An intelligent multi-agent financial analysis system powered by LangChain and Google's Gemini AI, providing real-time market insights, SEC filing analysis, and comprehensive financial reports.
Financial Assistant is a production-ready AI platform that combines advanced LLM capabilities with real-time financial data to deliver professional-grade financial analysis. The system features a sophisticated multi-agent architecture that can process complex queries, analyze SEC filings, perform quantitative analysis, and generate comprehensive investment reports.
- π€ Dual-Mode AI System: Chat mode for quick queries, Think mode for deep analysis
- π Real-Time Market Data: Integration with Yahoo Finance, Alpha Vantage, and News APIs
- π SEC Filing Analysis: RAG-enhanced semantic search across 10-K, 10-Q, 8-K filings
- π Multi-Agent Architecture: Planner β Financial Analyst β Publisher workflow
- π¬ Conversational Memory: MongoDB-backed chat history with session management
- π Production-Ready: Dockerized, fully documented, AWS deployment guides included
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (React) β
β - Modern UI with Tailwind CSS β
β - Real-time WebSocket streaming β
β - Session management & chat history β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β API Layer (FastAPI) β
β - RESTful endpoints (/api/chat, /api/think) β
β - WebSocket support for streaming β
β - MongoDB integration for persistence β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Multi-Agent System (LangGraph) β
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Planner βββββΆβ Financial βββββΆβ Publisher β β
β β Agent β β Agent β β Agent β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β β β β
β ββββββββββββββββββββββ΄βββββββββββββββββββββ β
β β β
ββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Financial Tools β β News & Web β β SEC Filings β
β β β Search β β (RAG + LLM) β
β - yfinance β β - NewsAPI β β - ChromaDB β
β - Metrics β β - DuckDuckGo β β - Embeddings β
β - Comparisons β β - Summarization β β - Chunking β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
-
Chat Mode: Fast, conversational responses (2-4 LLM calls)
- Quick metrics lookups (P/E ratio, market cap, etc.)
- Stock price summaries
- Analyst recommendations
- Conversational follow-ups with memory
-
Think Mode: Comprehensive analysis (10+ LLM calls, structured workflow)
- Multi-agent planning and execution
- Deep financial analysis with multiple data sources
- Structured investment reports
- Comparative analysis across companies
Quantitative Analysis:
- Valuation metrics (P/E, P/B, EV/EBITDA, etc.)
- Profitability metrics (ROE, ROA, margins)
- Historical growth analysis
- Stock price summaries
- Analyst recommendations
- Multi-company comparisons
News & Market Intelligence:
- Stock-specific news aggregation
- Market-wide news monitoring
- Full article content extraction
- News summarization
SEC Filing Analysis (RAG-Enhanced):
- 10-K, 10-Q, 8-K filing downloads
- Semantic search across documents
- Multi-document comparative analysis
- Financial data extraction
- Smart chunking and embeddings
Web Search:
- Real-time market searches
- Financial web search
- Search + summarization pipeline
- MongoDB-backed chat history
- Session persistence across queries
- Multi-user support
- Automatic session continuation
- Message metadata tracking
- API: RESTful + WebSocket endpoints
- Authentication: Ready for JWT/OAuth integration
- Monitoring: Health checks, logging
- Error Handling: Comprehensive error responses
- CORS: Configurable for frontend integration
- Docker: Single-command deployment
- Python 3.11+
- Node.js 18+
- Docker & Docker Compose
- API Keys (see
.env.example)
git clone https://github.com/yourusername/Finassistant.git
cd Finassistant# Copy environment template
cp .env.example .env
# Edit .env and add your API keys
nano .envRequired API keys:
GOOGLE_API_KEY- Google Gemini AINEWS_API_KEY- NewsAPI.orgMONGODB_URL- MongoDB Atlas connection string- (Optional)
OPENAI_API_KEY,GROQ_API_KEY,ALPHA_VANTAGE_API_KEY
# Build and start backend
docker-compose up -d
# View logs
docker-compose logs -f backend
# Test API
curl http://localhost:8000/api/healthcd frontend
npm install
npm run dev
# Visit http://localhost:5173Chat Mode (Quick queries):
curl -X POST "http://localhost:8000/api/chat?query=What%20is%20Apple%27s%20P/E%20ratio?"Think Mode (Comprehensive analysis):
curl -X POST "http://localhost:8000/api/think?query=Analyze%20Tesla%27s%20financial%20health&verbose=true"Finassistant/
βββ agent/ # AI Agent System
β βββ agent.py # Main agent runner
β βββ graph/ # LangGraph workflows
β β βββ single_agent_graph.py # Chat mode
β β βββ multi_agent_graph.py # Think mode
β βββ nodes/ # Agent nodes
β βββ subagents/ # Specialized agents
β β βββ planner_agent.py
β β βββ financial_agent.py
β β βββ publisher_agent.py
β βββ tools/ # Tool implementations
β β βββ quant/ # Financial metrics
β β βββ news/ # News aggregation
β β βββ sec_filing/ # SEC filings
β β βββ rag/ # RAG system
β β βββ search/ # Web search
β βββ states/ # State management
β
βββ api/ # FastAPI Backend
β βββ app.py # Main API application
β βββ database.py # MongoDB connection
β βββ chat_history.py # Session management
β βββ models.py # Pydantic models
β βββ websocket_handler.py # WebSocket streaming
β
βββ frontend/ # React Frontend
β βββ src/
β β βββ components/ # React components
β β βββ services/ # API client
β β βββ hooks/ # Custom React hooks
β β βββ App.jsx # Main app
β βββ package.json
β
βββ Dockerfile # Backend container
βββ docker-compose.yml # Orchestration
βββ requirements.txt # Python dependencies
βββ DEPLOYMENT_BACKEND.md # EC2 deployment guide
βββ DEPLOYMENT_FRONTEND.md # S3 + CloudFront guide
βββ README.md # This file
| Technology | Purpose |
|---|---|
| Python 3.11 | Core language |
| FastAPI | REST API framework |
| LangChain | LLM orchestration |
| LangGraph | Multi-agent workflows |
| Google Gemini | Primary LLM (Gemini 1.5 Flash) |
| ChromaDB | Vector database for RAG |
| MongoDB | Chat history & sessions |
| yfinance | Stock market data |
| NewsAPI | News aggregation |
| BeautifulSoup | Web scraping |
| Technology | Purpose |
|---|---|
| React 18 | UI framework |
| Vite | Build tool |
| Tailwind CSS | Styling |
| Axios | HTTP client |
| React Markdown | Markdown rendering |
| Lucide React | Icons |
- Docker - Containerization
- AWS EC2 - Backend hosting
- AWS S3 + CloudFront - Frontend CDN
- Nginx - Reverse proxy
- Let's Encrypt - SSL certificates
GET /api/healthResponse:
{
"status": "healthy",
"timestamp": "2024-01-15T10:30:00Z",
"version": "1.0.0"
}POST /api/chat?query=<your_query>&session_id=<optional>&user_id=<optional>Example:
curl -X POST "http://localhost:8000/api/chat?query=What%27s%20Apple%27s%20market%20cap%3F"Response:
{
"success": true,
"query": "What's Apple's market cap?",
"query_type": "chat",
"result": "Apple (AAPL) has a market capitalization of approximately $2.8 trillion...",
"timestamp": "2024-01-15T10:30:00Z",
"metadata": {
"execution_time_seconds": 3.2,
"session_id": "abc123..."
}
}POST /api/think?query=<your_query>&verbose=<true|false>Example:
curl -X POST "http://localhost:8000/api/think?query=Analyze%20Tesla%27s%20financial%20health&verbose=true"GET /api/sessions?user_id=<user_id> # List sessions
POST /api/sessions # Create session
GET /api/sessions/<session_id> # Get session with messages
DELETE /api/sessions/<session_id> # Delete session
PATCH /api/sessions/<session_id> # Update sessionconst ws = new WebSocket('ws://localhost:8000/ws/chat?user_id=user123');
ws.send(JSON.stringify({
query: "Analyze Apple",
mode: "think",
session_id: "abc123",
save_history: true
}));
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log(data.type, data.data);
};Full API Docs: Visit http://localhost:8000/docs after starting the server.
from agent.agent import run_agent
result = run_agent(
query="What's Microsoft's P/E ratio?",
mode="chat"
)
print(result)
# Output: "Microsoft (MSFT) has a P/E ratio of 32.5..."result = run_agent(
query="Compare the financial health of Tesla and Ford",
mode="think",
verbose=True
)
print(result)
# Output: Detailed multi-page report with metrics, analysis, and recommendationshistory = [
{"role": "user", "content": "Tell me about Apple"},
{"role": "assistant", "content": "Apple Inc. is..."}
]
result = run_agent(
query="What about their latest earnings?",
mode="chat",
conversation_history=history
)# Interactive mode
python -m agent.agent
# Direct query
python -m agent.agent chat "What's NVDA's current price?"
python -m agent.agent think "Analyze Amazon's Q4 performance"docker-compose.yml- Full stack (local development with FE + BE)docker-compose.backend.yml- Backend only (for EC2 deployment)docker-compose.frontend.yml- Frontend only (for testing before S3)
See DOCKER_DEPLOYMENT.md for detailed usage.
Complete step-by-step guide: DEPLOYMENT_BACKEND.md
Quick Deploy:
# On EC2 instance
git clone https://github.com/yourusername/Finassistant.git
cd Finassistant
cp .env.example .env
# Edit .env with your API keys
docker-compose -f docker-compose.backend.yml up -dFeatures:
- Docker containerization (backend only)
- Direct port exposure (8000)
- Optional: Nginx reverse proxy
- Optional: SSL with Let's Encrypt
- Systemd service management
- CloudWatch monitoring
Complete step-by-step guide: DEPLOYMENT_FRONTEND.md
Quick Deploy:
cd frontend
npm run build
aws s3 sync dist/ s3://your-bucket --delete
aws cloudfront create-invalidation --distribution-id XXX --paths "/*"Features:
- Static hosting on S3
- CloudFront CDN distribution
- Custom domain with SSL
- Automated deployment script
- CI/CD with GitHub Actions
| Variable | Description | Required |
|---|---|---|
GOOGLE_API_KEY |
Google Gemini API key | β Yes |
NEWS_API_KEY |
NewsAPI.org API key | β Yes |
MONGODB_URL |
MongoDB connection string | β Yes |
OPENAI_API_KEY |
OpenAI API key (optional) | βͺ No |
GROQ_API_KEY |
Groq API key (optional) | βͺ No |
ALPHA_VANTAGE_API_KEY |
Alpha Vantage key (optional) | βͺ No |
PINECONE_API_KEY |
Pinecone vector DB (optional) | βͺ No |
- Create free cluster at MongoDB Atlas
- Create database user
- Whitelist your IP (or 0.0.0.0/0 for development)
- Get connection string and add to
.env
- Google Gemini: https://makersuite.google.com/app/apikey
- NewsAPI: https://newsapi.org/register
- MongoDB: https://www.mongodb.com/cloud/atlas/register
The following enhancements are planned or recommended for future development:
- Current State: News articles are fetched and summarized, but sentiment is not quantitatively analyzed
- Improvement:
- Implement a fine-tuned sentiment analysis model (e.g., FinBERT)
- Score news sentiment on a scale (-1 to +1)
- Aggregate sentiment scores over time windows
- Visualize sentiment trends in frontend
Business Impact: More accurate assessment of market sentiment, better decision-making signals
- Current State: News and price data are shown separately
- Improvement:
- Build ML model correlating news sentiment with stock price movements
- Features: sentiment scores, article volume, source credibility, historical patterns
- Predict short-term price movements (1-day, 7-day, 30-day)
- Backtesting framework to validate predictions
Technical Approach:
- Feature engineering: sentiment scores, trading volume, price history
- Models to explore: LSTM, Transformer-based architectures, XGBoost
- Training data: Historical news + stock prices (2018-2024)
Business Impact: Predictive insights for traders, enhanced investment recommendations
Frontend UX/UI:
- Dark/light mode toggle
- Advanced charting (Plotly.js, TradingView widgets)
- Comparison dashboards (side-by-side company views)
- Sentiment visualization (gauge charts, trend lines)
- Export reports to PDF
- Saved queries and favorites
- Real-time streaming indicators (typing animation, progress bars)
- Mobile-responsive design improvements
Backend Performance:
- Caching layer (Redis) for frequently requested data
- Rate limiting per user/API key
- Async batch processing for multi-company queries
- Database indexing optimization
- API response compression (gzip)
- Websocket connection pooling
System Architecture:
- Microservices architecture (separate services for tools, agents, API)
- Message queue (RabbitMQ/SQS) for long-running tasks
- Horizontal scaling with load balancer
- Kubernetes deployment manifests
- Prometheus + Grafana monitoring
- Distributed tracing (OpenTelemetry)
Integration & Testing:
- Comprehensive unit tests (pytest, >80% coverage)
- Integration tests for API endpoints
- End-to-end tests (Playwright/Selenium)
- CI/CD pipeline (GitHub Actions)
- Automated security scanning (Snyk, Dependabot)
- Performance benchmarking suite
Security:
- JWT authentication
- Role-based access control (RBAC)
- API key management
- Secrets management (AWS Secrets Manager)
- Input validation and sanitization
- Rate limiting and DDoS protection
Contributions are welcome! This project is actively maintained.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
# Install dependencies
pip install -r requirements.txt
cd frontend && npm install
# Run tests
pytest
npm test
# Format code
black agent/ api/
prettier --write frontend/src| Metric | Value |
|---|---|
| Chat Mode Latency | 2-4 seconds (avg) |
| Think Mode Latency | 15-30 seconds (avg) |
| API Throughput | 50+ req/sec (single instance) |
| Tool Accuracy | 95%+ (financial data) |
| LLM Calls (Chat) | 2-4 calls |
| LLM Calls (Think) | 10-15 calls |
| Database Queries | <100ms (MongoDB) |
| Vector Search | <200ms (ChromaDB) |
1. MongoDB Connection Failed
# Check connection string in .env
# Verify IP whitelist in MongoDB Atlas
# Test connection:
mongosh "your-mongodb-url"2. API Keys Not Working
# Ensure .env file exists and is loaded
# Verify API key validity
# Check API quota limits3. Docker Build Fails
# Clear Docker cache
docker-compose down -v
docker system prune -a
docker-compose build --no-cache4. Frontend Can't Connect to Backend
# Check CORS settings in api/app.py
# Verify API URL in frontend/.env.production
# Check backend is running: curl http://localhost:8000/api/healthThis project is licensed under the MIT License - see the LICENSE file for details.
Nishant
- GitHub: @nishant-ai
- LinkedIn: Nishant Sharma
- LangChain - For the amazing LLM framework
- Google Gemini - For powerful AI capabilities
- FastAPI - For the excellent Python web framework
- MongoDB - For reliable data persistence
- Open Source Community - For countless libraries and tools
For questions, issues, or feature requests:
- Issues: GitHub Issues
- Discussions: GitHub Discussions
If you find this project useful, please consider giving it a star! β
Built with β€οΈ using AI and modern web technologies
π Star this repo β’ π Report Bug β’ β¨ Request Feature