How kushagramahalaha/financial-ai-agent works
Purpose and entry points
FinChain is a Python, stateful multi-agent financial-advice system. It accepts user financial questions, routes them through specialized agents and tools, persists profile context, and can ground responses with retrieved finance documents. Interactive execution starts at main.py; FastAPI serving starts at app.py.
Workflow orchestration
LangGraph is the central control plane: it defines shared workflow state and assembles the agent-routing graph.
• graph/builder.py
• graph/state.py
The graph is the primary boundary between request handling and domain agents: each stage reads/writes a common state, then routes to an advisor, goal, or risk path before returning a synthesized response.
Specialized financial agents
The agent layer separates financial reasoning by responsibility:
• General advisory and response coordination: Agents/advisor_agent.py
• Goal-based planning from income, expenses, and stated objectives: Agents/goal_agent.py
• Investment and portfolio risk evaluation: Agents/risk_agent.py
• Finance-advisor specialization: Agents/finance_adviser.py
These agents are expected to use LangChain/LangGraph and Gemini 2.5 Flash, with external tools supplying live or computed financial context.
Financial analysis and market tools
The tools package is the capability boundary for deterministic calculations and external-market access. It includes portfolio analysis/reporting, investment calculations, stock data, and news lookup.
• Tools/portfolio_analyser.py
• Tools/smart_portfolio_analyzer.py
• Tools/stock_tools.py
Agent calls should delegate data fetching and calculations here rather than embed provider-specific logic in graph routing or conversational memory.
Expense tracking and persistent user memory
Expense input is parsed and tracked independently, while memory extraction/rules maintain a durable user profile such as financial facts, goals, and expenses.
• ExpenseTracker/parser.py
• ExpenseTracker/tracker.py
• Memory/user_memory.py
Persistent state is represented in repository storage by memory.json. Memory is a cross-request boundary: request-time agent state can be enriched from it, then relevant facts can be written back after interaction.
Retrieval-augmented financial context
The RAG pipeline ingests finance reference material, retrieves relevant chunks for a question, and exposes an asking/retrieval interface to the advisory workflow.
• RAG/ingest.py
• RAG/retriever.py
• RAG/ask.py
Source documents reside in data/, including data/finance.txt and data/portfolio.txt; the checked-in vector artifacts are vector_db/index.faiss and vector_db/index.pkl. This is the knowledge-grounding boundary, distinct from user memory and live market tools.
Runtime and integrations
The runtime is Python 3.9+, with FastAPI for HTTP delivery and a CLI path through main.py. Core AI infrastructure is LangChain, LangGraph, and langchain-google-genai/Gemini; financial capabilities may require provider API keys, notably the Google API key and financial-data credentials. Dependencies are declared in requirements.txt.
Main entry points: builder.py LangGraph builder · advisor_agent.py Advisor coordinator · risk_agent.py Risk evaluator · user_memory.py User memory manager
Components 20
Entry points
- CLI runner
main.py - FastAPI server
app.py
Workflow control
- LangGraph builder · Routes shared state through financial paths and synthesis.
graph/builder.py - Shared workflow state
graph/state.py
Financial agents
- Advisor coordinator
Agents/advisor_agent.py - Goal planner
Agents/goal_agent.py - Risk evaluator
Agents/risk_agent.py - Finance adviser
Agents/finance_adviser.py
Financial capabilities
- Portfolio analysis
Tools/portfolio_analyser.py - Investment calculations
Tools/smart_portfolio_analyzer.py - Market & news lookup
Tools/stock_tools.py - Expense parser
ExpenseTracker/parser.py - Expense tracker
ExpenseTracker/tracker.py
Persistent & retrieved context
- User memory manager · Extracts and maintains durable financial facts, goals, and expenses.
Memory/user_memory.py - User memory store
memory.json - RAG query interface
RAG/ask.py - Finance retriever
RAG/retriever.py - RAG ingestion
RAG/ingest.py - Finance reference docs
data/finance.txt - FAISS vector index
vector_db/index.faiss
Connections 21
- CLI runner → LangGraph builder: submits question
- FastAPI server → LangGraph builder: handles request
- LangGraph builder → Shared workflow state: reads and writes
- LangGraph builder → Advisor coordinator: routes advisory path
- LangGraph builder → Goal planner: routes goal path
- LangGraph builder → Risk evaluator: routes risk path
- Advisor coordinator → Finance adviser: delegates specialization
- Advisor coordinator → RAG query interface: grounds response
- Advisor coordinator → User memory manager: enriches and updates profile
- Goal planner → Expense tracker: uses expense history
- Goal planner → User memory manager: uses goals and facts
- Risk evaluator → Portfolio analysis: analyzes portfolio
- Risk evaluator → Investment calculations: calculates investments
- Risk evaluator → Market & news lookup: fetches market context
- Expense parser → Expense tracker: parses expense input
- Expense tracker → User memory manager: records expense facts
- User memory manager → User memory store: persists profile
- RAG query interface → Finance retriever: retrieves context
- Finance retriever → FAISS vector index: searches chunks
- Finance reference docs → RAG ingestion: source material
- RAG ingestion → FAISS vector index: builds index