AI-powered stock analysis agent with multi-agent system for comprehensive market research and financial analysis.
- Features
- Architecture
- Tech Stack
- Installation
- Configuration
- Usage
- Project Structure
- Customization
- Troubleshooting
- Development
- Multi-Agent Architecture: Three specialized agents work together to provide comprehensive stock analysis
- Real-time Market Data: Fetches live stock prices, performance metrics, and financial data
- Market Intelligence: Uses Perplexity API to gather the latest news, trends, and analyst opinions
- Automated Reports: Generates professional markdown reports from the analysis
- Web API: FastAPI interface for easy integration and access
- Interactive Web Interface: User-friendly dashboard for stock analysis
- Workflow Visualization: Mermaid graph visualization of the agent workflow
- Customizable Prompts: Configurable system prompts for different analysis needs
The Superior-Agent system consists of three specialized agents coordinated by a supervisor using LangGraph's multi-agent orchestration:
- Web Search Expert: Gathers current market news, trends, and analyst opinions using Perplexity API
- Finance Analyst: Fetches stock prices, performance metrics, and financial data using yfinance
- Report Generator: Compiles all gathered data into professional markdown reports
- Supervisor: Orchestrates the workflow between agents to generate comprehensive analyses
- Financial Manager Agent (supervisor) receives the analysis query and coordinates the workflow
- Web Search Agent uses Perplexity API to gather market news and trends
- Yahoo Finance Agent fetches live stock prices, performance metrics, and financial data
- Report Generator Agent compiles all gathered information into a professional report
- Reports are saved as markdown files in the
output/directory
- LangGraph - State management and multi-agent orchestration
- LangGraph Supervisor - Multi-agent supervisor functionality
- LangChain - LLM integration and tool management
- FastAPI - Web API framework
- yfinance - Financial data fetching
- Perplexity API - Market research and news gathering
- Pydantic - Data validation
- uvicorn - ASGI server
- Jinja2 - Template rendering
- IPython - Interactive Python functionality
- Streamlit - Optional web application framework
-
Clone the repository:
git clone https://github.com/devgomesai/Superior-Agent.git cd superior-agent -
Create a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies:
# Using pip pip install -e . # Or using uv (recommended) uv pip install -e .
-
Create a
.envfile in the project root directory:# Perplexity API key for market research PERPLEXITY_API_KEY=your_perplexity_api_key_here # LLM provider and model selection # Examples: groq:mixtral-8x7b-32768, anthropic:claude-3-5-sonnet-20241022 LLM_CHOICE=groq:mixtral-8x7b-32768 # API keys for your selected LLM provider GROQ_API_KEY=gsk_your_groq_api_key_here ANTHROPIC_API_KEY=sk-ant-your_anthropic_api_key_here
For more LLM options, refer to the LangChain documentation.
-
The application automatically uses these environment variables for:
- Perplexity API authentication for market research
- LLM model selection and credentials
-
Start the API server:
uvicorn src.agent.api.api:app --reload
Or without auto-reload:
uvicorn src.agent.api.api:app
-
Access the application:
- Web interface:
http://127.0.0.1:8000 - API documentation:
http://127.0.0.1:8000/docs
- Web interface:
-
POST
/analyze- Analyze stock using the agent workflowcurl -X POST "http://127.0.0.1:8000/analyze" \ -H "Content-Type: application/json" \ -d '{"query": "Analyze Tesla stock (TSLA) performance and financial metrics"}'
-
GET
/- Home page with stock analysis interface -
GET
/health- Health check endpointcurl -X GET "http://127.0.0.1:8000/health" -
GET
/output-files- List all generated stock reportscurl -X GET "http://127.0.0.1:8000/output-files" -
GET
/output-files/{filename}- Get specific report contentcurl -X GET "http://127.0.0.1:8000/output-files/stock_report_AAPL_20251027_094248.md"
Run the application directly for interactive analysis:
python -m src.tests.mainOr from the src directory:
cd src
python -m tests.mainFollow the prompts to enter your stock analysis query.
The interactive web interface (http://127.0.0.1:8000) includes:
- Stock query input form for analysis requests
- Real-time display of agent workflow and responses
- Download section for previously generated reports
- Refresh functionality to update report listings
- Syntax-highlighted JSON response viewer
superior-agent/
├── src/
│ ├── agent/
│ │ ├── api/
│ │ │ ├── __init__.py
│ │ │ └── api.py # FastAPI endpoints
│ │ ├── __init__.py
│ │ └── agent.py # Core agent workflow
│ ├── prompts/
│ │ └── agent_prompts.py # Agent system prompts
│ ├── templates/
│ │ └── index.html # Web interface
│ ├── tests/
│ │ ├── main.py # Interactive CLI mode
│ │ ├── test.py # Test template
│ │ └── tests.py # Test utilities
│ ├── tools/
│ │ └── stock_analysis_tools.py # Market data tools
│ ├── __init__.py
│ └── requirements.txt
├── output/ # Generated stock reports
├── .gitignore
├── .python-version
├── agent_flow.json # Workflow configuration
├── architecture.png # Architecture diagram
├── Dockerfile
├── graph.png # Workflow visualization
├── pyproject.toml # Project configuration
├── README.md
├── trace.png # Debug trace
└── uv.lock
Customize agent behavior in src/prompts/agent_prompts.py:
WEB_SEARCH_AGENT_PROMPT- Web research agent configurationYAHOO_FINANCE_AGENT_PROMPT- Finance analyst configurationREPORT_GENERATOR_AGENT_PROMPT- Report generator configurationSUPERVISOR_PROMPT- Workflow coordinator configuration
Available tools in src/tools/stock_analysis_tools.py:
web_search_news()- Search market news using Perplexity APIget_stock_price()- Fetch current stock price and informationget_stock_performance()- Retrieve historical performance dataget_financial_metrics()- Get key financial metricssave_report_to_file()- Save analysis reports to markdown
pyproject.toml- Project metadata and dependenciesagent_flow.json- Agent workflow configurationgraph.png- Auto-generated workflow visualization
| Issue | Solution |
|---|---|
| API Keys Invalid | Verify your Perplexity and LLM API keys have sufficient credits |
| No Internet Connection | The system requires internet for fetching financial data and research |
| LLM Access Error | Ensure your LLM API key is properly configured in .env |
| Rate Limits Exceeded | Be aware of API rate limits for Perplexity and Yahoo Finance |
| Port 8000 Already in Use | Specify a different port: uvicorn src.agent.api.api:app --port 8001 |
Install the package in editable mode for development:
pip install -e .Test scripts are located in src/tests/:
main.py- Interactive command-line interface for testingtest.py- Test template (commented)tests.py- Additional test utilities
Run interactive analysis to test functionality:
python -m src.tests.mainThe application automatically generates workflow visualizations (graph.png) when run, useful for debugging the agent flow.
