Skip to content

Advanced stock market research Agent with no direct access to internet

Notifications You must be signed in to change notification settings

amritsingh183/goyahoo

Repository files navigation

Advanced stock market research Agent with no direct access to internet

Demo

https://youtu.be/iIuAioYgUZw

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.

Step 1: For Auth Server, Generate keys for JWT and store them in the certs folder

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.pub

Step 2: Prepare the database

Use 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.sql

Step 3: Build the backend

Put 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"

Build and test the api backend

docker build -t agentbackend -f dockerfile .

Step 4 Run the services required for the api backend

Either run the docker compose file

# Run the docker compose file
docker compose up -f docker-compose.yml

OR

use the easiest option to run the backend

# Run the backend
make runBackend

Step 5 Prepare the agent's python environment

Create a new conda environment

conda create --solver=libmamba -y -n agent python=3.12 && conda activate agent

python -m pip install flask "pymongo[srv]" "crewai[tools]" gradio browser-use

About

Advanced stock market research Agent with no direct access to internet

Resources

Stars

Watchers

Forks

Packages

No packages published