This repository demonstrates how to build an agent that uses Postgres and MongoDb via Tool Calling. The agent queries the Postgres and MongoDB using Tools (Tool Calling) to get information about a given Stock. The tool calling code makes sure that the required information is always there in the Database (If it is not there, the information is fetched from the internet and put into the database).
- The advantage is that you get full control over the agent and the agent is not free to access the internet for anything (a malicious actor can't take advantage of this)
- The code is not supposed to be used in production, it merely demonstrates a working idea.
Please follow the steps below to run this project.
cd goBackend
mkdir certs
cd certs
ssh-keygen -t rsa -b 4096 -m PEM -f agentauthRS256R.key -P ""
ssh-keygen -t rsa -b 4096 -m PEM -f agentauth256.key -P ""
openssl rsa -in agentauthRS256R.key -pubout -outform PEM -out agentauthRS256R.key.pub
openssl rsa -in agentauth256.key -pubout -outform PEM -out agentauth256.key.pubUse SQL File to create the tables in the postgres database.
Get into the postgres container and use the SQL file to create the tables.
docker exec -it postgres-aiagent psql -U ${DB_USER} -d ${DB_DATABASE} -f /app/asset_profiles.sqlPut the environment variables in the goenv file (this file will be used to build the docker image for the backend)
# make sure this is ignored in the .gitignore file
nano goenv# these keys will be used in round robin fashion
export YF_API_KEY1="your_api_key_here"
export YF_API_KEY2="your_api_key_here"
export YF_API_KEY3="your_api_key_here"
export YF_API_KEY4="your_api_key_here"
# openai api key for agent
export OPENAI_API_KEY="your_api_key_here"
# postgres db for yahoo finance data
export DB_HOST="127.0.0.1"
export DB_PORT=5432
export DB_USER="your_username_here"
export DB_PASSWORD="your_password_here"
export DB_DATABASE="your_database_name_here"
# redis db for auth server
export REDIS_HOST="127.0.0.1"
export REDIS_PORT="6379"
export REDIS_PASSWORD="your_password_here"docker build -t agentbackend -f dockerfile .Either run the docker compose file
# Run the docker compose file
docker compose up -f docker-compose.ymlOR
use the easiest option to run the backend
# Run the backend
make runBackendconda create --solver=libmamba -y -n agent python=3.12 && conda activate agent
python -m pip install flask "pymongo[srv]" "crewai[tools]" gradio browser-use