Hierarchical Multi-Agent System for Top 5 US Stock Selection
10K+
Hierarchical Multi-Agent System for Top 5 US Stock Selection
StockSage is an AI-powered investment analysis system that leverages multiple specialized agents to perform comprehensive stock analysis and selection. Using a combination of financial data analysis, sentiment analysis, and market trend detection, StockSage identifies the top 5 investment opportunities in the US stock market with detailed supporting rationales.
The system processes financial metrics, news sentiment, social media mentions, and analyst ratings to create a holistic view of each stock's potential, using a sophisticated ranking and selection methodology.
# Clone the repository
git clone https://github.com/yourusername/StockSage.git
cd StockSage
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
uv sync
# Build Docker image
docker build -t stocksage .
# Run Docker container
docker run -p 8501:8501 \
-e SERPER_API_KEY=your_serper_api_key \
-e ALPHAVANTAGE_API_KEY=your_alphavantage_api_key \
-e LANGCHAIN_API_KEY=your_langchain_api_key \
-e LANGCHAIN_TRACING_V2=true \
-e OPENAI_API_KEY=your_openai_api_key \
-e LANGCHAIN_ENDPOINT=https://api.smith.langchain.com \
-e LANGSMITH_PROJECT=stock-sage \
stocksage
Create a .env file in the root directory with the following variables:
SERPER_API_KEY=your_serper_api_key
ALPHAVANTAGE_API_KEY=your_alphavantage_api_key
LANGCHAIN_API_KEY=your_langchain_api_key
LANGCHAIN_TRACING_V2=true
LANGCHAIN_ENDPOINT=https://api.smith.langchain.com
LANGSMITH_PROJECT=stock-sage
# Run the full analysis pipeline
python -m stocksage.main run
# Run in training mode
python -m stocksage.main train
# Test the system
python -m stocksage.main test
# Replay a previous analysis
python -m stocksage.main replay --run_id your_run_id
from stocksage import StockSage
# Initialize and run the StockSage crew
inputs = {
"market": "US",
"stock_universe": "S&P 500",
"current_year": "2025",
"analysis_date": "2025-03-13"
}
sage = StockSage()
results = sage.crew().kickoff(inputs=inputs)
print(f"Analysis complete. Results saved to outputs directory.")
# Launch the Streamlit interface
streamlit run src/stocksage/user_interface.py
# Run all tests
pytest
# Run specific test file
pytest tests/test_sentiment_analysis_tool.py
# Run with coverage report
pytest --cov=stocksage
StockSage employs a hierarchical multi-agent architecture:
StockSage generates the following outputs in the outputs directory:
Example output structure:
{
"analysis_date": "2025-03-13",
"investments": [
{
"ticker": "AAPL",
"company_name": "Apple Inc.",
"recommendation": "Buy",
"target_price": "$210.45",
"thesis": "Apple's strong ecosystem...",
"sentiment_score": 0.78,
"sentiment_label": "Bullish"
},
...
]
}
Simplified Analysis Report
LangSmith Run Records
Contributions are welcome! Please feel free to submit a Pull Request.
Content type
Image
Digest
sha256:f7f941f88…
Size
443 MB
Last updated
over 1 year ago
docker pull programmerrdai/stock-sage