A comprehensive AI-powered stock analysis system built with CrewAI and CopilotKit, featuring multiple specialized agents for financial research, analysis, and investment recommendations.
- Multi-Agent Architecture: Specialized AI agents for different aspects of stock analysis
- Real-time Data Integration: SEC filings (10-K, 10-Q), financial websites, and market data
- Comprehensive Analysis: Financial metrics, market sentiment, and investment recommendations
- Web API: FastAPI-based RESTful API with CopilotKit integration
- Interactive Interface: Built-in CopilotKit UI for seamless user interaction
- Role: Expert financial analyst specializing in stock market analysis
- Capabilities:
- P/E ratio, EPS growth, revenue trends analysis
- Debt-to-equity ratio calculations
- Industry peer comparisons
- Market trend analysis
- Tools: Calculator, SEC filings, website scraping, financial data extraction
- Role: Market research specialist focusing on news and sentiment analysis
- Capabilities:
- Recent news article collection and summarization
- Market sentiment analysis
- Earnings announcements tracking
- Press release monitoring
- Tools: Website search, SEC filings, content scraping
- Role: Senior investment advisor providing strategic recommendations
- Capabilities:
- Comprehensive investment recommendations
- Risk assessment
- Portfolio strategy formulation
- Insider trading activity analysis
- Tools: Calculator, web research, financial modeling
- Calculator Tool: Safe mathematical operations for financial calculations
- SEC 10-K Tool: Semantic search through annual SEC filings
- SEC 10-Q Tool: Quarterly SEC filing analysis
- Website Search Tool: Real-time web data collection
- Website Scraping Tool: Content extraction from financial websites
- SEC API: Official SEC filings data
- OpenRouter: AI model access (DeepSeek R1)
- Financial Data Sources: Real-time market data integration
crew-ai/
βββ stock_analysis/
β βββ __init__.py
β βββ main.py # FastAPI application entry point
β βββ crew.py # CrewAI crew configuration
β βββ config/
β β βββ agents.yaml # Agent configurations
β β βββ tasks.yaml # Task definitions
β βββ tools/
β βββ __init__.py
β βββ calculator_tool.py # Mathematical operations
β βββ sec_tool.py # SEC filings integration
βββ pyproject.toml # Project dependencies
βββ uv.lock # Dependency lock file
βββ README.md # This file
- Python 3.13+
- UV package manager (recommended)
- API keys for:
- OpenRouter API
- SEC API
-
Clone the repository
git clone https://github.com/Avyakta000/crew-ai.git cd crew-ai -
Install dependencies
uv sync
-
Environment Setup Create a
.envfile in the root directory:OPENROUTER_API_KEY=your_openrouter_api_key SEC_API_API_KEY=your_sec_api_key PORT=8000
-
Run the application
uv run python stock_analysis/main.py
The API will be available at http://localhost:8000
Defines the roles, goals, and backstories for each AI agent:
- Financial Analyst: Market analysis expert
- Research Analyst: News and sentiment specialist
- Investment Advisor: Strategic recommendation provider
Specifies the tasks each agent performs:
- Financial Analysis: Comprehensive stock health assessment
- Research: News collection and market sentiment analysis
- Filings Analysis: SEC document review and insights
- Recommendation: Investment advice synthesis
GET /health- Health check endpointPOST /copilotkit- CopilotKit integration endpoint
# Health check
curl http://localhost:8000/health
# Run stock analysis (via CopilotKit)
curl -X POST http://localhost:8000/copilotkit \
-H "Content-Type: application/json" \
-d '{"company_stock": "AAPL"}'from stock_analysis.crew import StockAnalysisCrew
# Initialize the crew
crew = StockAnalysisCrew()
# Run analysis for a specific stock
result = crew.crew().kickoff(inputs={"company_stock": "AAPL"})
print(result)# The crew can be configured with different stocks
# Modify the SEC tools initialization in crew.py:
SEC10QTool("TSLA"), # For Tesla
SEC10KTool("TSLA"),| Variable | Description | Required |
|---|---|---|
OPENROUTER_API_KEY |
OpenRouter API key for AI model access | Yes |
SEC_API_API_KEY |
SEC API key for filings data | Yes |
PORT |
Server port (default: 8000) | No |
- Research Phase: Collect recent news and market sentiment
- Financial Analysis: Analyze key metrics and ratios
- SEC Filings Review: Extract insights from official documents
- Synthesis: Combine all analyses into investment recommendations
- Output: Generate comprehensive investment report
- Safe Calculator: Restricted mathematical operations only
- Input Validation: Robust error handling for all inputs
- API Rate Limiting: Built-in protection against abuse
- Secure Headers: Proper HTTP headers for SEC API requests
- Define agent configuration in
config/agents.yaml - Create agent method in
crew.py - Add corresponding task in
config/tasks.yaml - Update crew composition in
crew()method
- Create tool class in
tools/directory - Import and configure in agent definitions
- Test integration with existing workflow
-
API Key Errors
- Verify environment variables are set correctly
- Check API key validity and quotas
-
SEC API Rate Limits
- Implement request throttling
- Consider caching for repeated requests
-
Model Access Issues
- Verify OpenRouter API key
- Check model availability and pricing
Enable verbose logging by setting verbose=True in agent configurations.
- Concurrent Processing: Sequential task execution for consistency
- Memory Management: Efficient handling of large SEC documents
- API Optimization: Smart caching and request batching
- Error Recovery: Graceful handling of API failures