This project showcases a sophisticated Financial AI Assistant built with Python, LangChain, and LangGraph. It moves beyond basic RAG to implement a robust, agentic workflow capable of answering complex, multi-step financial questions with a high degree of accuracy and reliability.
The system leverages a suite of live financial data APIs and is architected around three advanced RAG patterns: Adaptive RAG, Self-RAG, and Corrective RAG.
- Multi-Source Data Integration: Connects to live APIs for stock prices (Yahoo Finance), economic data (FRED), financial news (NewsAPI), cryptocurrency prices (CoinDesk), SEC filings (EDGAR), Technical Indicators (Polygon.io), and general web search (Tavily).
- Intelligent Tool Use: The agent reasons about which data sources best fit a query and can query several of them in parallel for one question.
- Quality Filtering & Reconciliation: Retrieved data is graded for relevance before use, and when multiple sources are consulted their facts are cross-checked and reconciled into a single answer.
- Dynamic & Flexible: Can answer questions about financial instruments and economic indicators it wasn't explicitly pre-programmed to know about.
- API-Ready: Exposed via a FastAPI endpoint for easy integration into other applications.
- Modern Frontend: A clean, responsive Next.js chat interface with real-time "Agent Reasoning" status updates.
Screen.Recording.2025-12-21.041735.mp4
This project is built on three pillars of advanced Retrieval-Augmented Generation. Here's how they are implemented in the LangGraph workflow:
- Concept: The system "adapts" its strategy by choosing the best data source for a given query, rather than relying on a single, one-size-fits-all approach.
- Implementation: The core agent analyzes the user's prompt and its list of available tools. Based on the query's intent ("stock price" vs. "inflation rate"), it intelligently selects the appropriate function to call (e.g.,
get_stock_dataorget_economic_data). This happens dynamically in the mainrouternode.
- Concept: The system critically evaluates the information it has just retrieved before using it, reflecting on its relevance and quality.
- Implementation: After a tool returns information, the result is fed into the
quality_filternode. The agent assesses this new information against the original goal. If a tool returns irrelevant data or an error message, the agent filters it out, preventing low-quality data from reaching the user.
- Concept: When several sources are consulted for the same question, the system corrects conflicting or unreliable information before answering rather than passing the raw context straight to the LLM.
- Implementation: The graph runs
router->retriever->quality_filter->reconciler(only when more than one document survives the quality filter) ->generator.- Correction: The
quality_filternode drops documents that are irrelevant, stale, or contain error responses. - Synthesis: The
reconcilernode identifies discrepancies between the remaining sources, picks the most reliable value, and collapses them into a single reconciled document (or, if they genuinely conflict, forwards all of them so the generator can describe the disagreement).
- Correction: The
Note: the graph is a linear pipeline — it does not currently loop back to re-retrieve after discovering a knowledge gap.
- Python 3.10+
- Node.js 18+ (for the frontend)
- Git
git clone https://github.com/ChinmayNakwa/Financial-AI-System.git
cd Financial-AI-SystemIt's highly recommended to use a virtual environment.
# Create and activate a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtcd client
npm install
cd ..Create a .env file in the root directory and fill in your keys:
# LLM & Search APIs
GOOGLE_API_KEY="YOUR_KEY_HERE"
TAVILY_API_KEY="YOUR_KEY_HERE"
# Financial Data APIs
FRED_API_KEY="YOUR_KEY_HERE"
NEWS_API_KEY="YOUR_KEY_HERE"
SEC_API_KEY="YOUR_KEY_HERE"
COINDESK_API_KEY="YOUR_KEY_HERE"
POLYGON_API_KEY="YOUR_KEY_HERE"From the root directory:
python main.pyThe API will be available at http://localhost:8000. You can access the Swagger UI at http://localhost:8000/docs.
From the client/ directory:
npm run devThe interface will be available at http://localhost:3000.
This project is optimized for Vercel using a Proxy Pattern to bridge the Next.js frontend and the Python FastAPI backend.
- Framework Preset:
Other - Build Command:
cd client && npm run build - Output Directory:
client/out - Install Command:
cd client && npm install - Backend Entry:
api/index.py(Proxies requests to thebackend/package)
The vercel.json handles the routing, ensuring that requests to /backend/* are routed to the Python serverless function, while all other requests serve the static Next.js frontend.
api/index.py: Vercel-specific entry point that bridges the serverless environment to the backend package.backend/:api.py: FastAPI routes and application logic.core/rag/: Contains the LangGraph workflow definitions (financial_workflow.py) and RAG logic (adaptive_rag.py,self_rag.py,corrective_rag.py).core/data_sources/: Individual tool implementations for each financial API.
client/:app/: Next.js 14+ App Router pages (Chat interface and Landing page).components/: Reusable UI components (Chat messages, Navbar, etc.).next.config.ts: Configured foroutput: 'export'to support static hosting.
vercel.json: Global routing and rewrite configuration.requirements.txt: Python dependencies (located at root for Vercel detection).