# kushagramahalaha/financial-ai-agent architecture

> Architecture diagram of the GitHub repository kushagramahalaha/financial-ai-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kushagramahalaha/financial-ai-agent
- Repository: https://github.com/kushagramahalaha/financial-ai-agent

## Overview

#### 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: [`graph/builder.py`](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/graph/builder.py) (LangGraph builder), [`Agents/advisor_agent.py`](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Agents/advisor_agent.py) (Advisor coordinator), [`Agents/risk_agent.py`](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Agents/risk_agent.py) (Risk evaluator), [`Memory/user_memory.py`](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Memory/user_memory.py) (User memory manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_cli["CLI runner<br/>Python entry point<br/>[main.py]"]
  node_api["FastAPI server<br/>HTTP entry point<br/>[app.py]"]
end

subgraph group_workflow["Workflow control"]
  node_graph_builder{{"LangGraph builder<br/>workflow assembly<br/>[builder.py]"}}
  node_workflow_state["Shared workflow state<br/>LangGraph state<br/>[state.py]"]
end

subgraph group_agents["Financial agents"]
  node_advisor["Advisor coordinator<br/>financial agent<br/>[advisor_agent.py]"]
  node_goal["Goal planner<br/>financial agent<br/>[goal_agent.py]"]
  node_risk["Risk evaluator<br/>financial agent<br/>[risk_agent.py]"]
  node_finance_adviser["Finance adviser<br/>agent specialization<br/>[finance_adviser.py]"]
end

subgraph group_capabilities["Financial capabilities"]
  node_portfolio_tools["Portfolio analysis<br/>analysis tools"]
  node_smart_portfolio["Investment calculations<br/>analysis tools"]
  node_market_tools["Market &amp; news lookup<br/>external-data tools<br/>[stock_tools.py]"]
  node_expense_parser["Expense parser<br/>expense input<br/>[parser.py]"]
  node_expense_tracker["Expense tracker<br/>expense tracking<br/>[tracker.py]"]
end

subgraph group_context["Persistent &amp; retrieved context"]
  node_user_memory["User memory manager<br/>profile memory<br/>[user_memory.py]"]
  node_memory_store[("User memory store<br/>JSON persistence<br/>[memory.json]")]
  node_rag_ask["RAG query interface<br/>retrieval interface<br/>[ask.py]"]
  node_retriever["Finance retriever<br/>vector retrieval<br/>[retriever.py]"]
  node_rag_ingest["RAG ingestion<br/>indexing pipeline<br/>[ingest.py]"]
  node_finance_docs["Finance reference docs<br/>knowledge documents<br/>[finance.txt]"]
  node_vector_index[("FAISS vector index<br/>retrieval index<br/>[index.faiss]")]
end

node_cli -->|"submits question"| node_graph_builder
node_api -->|"handles request"| node_graph_builder
node_graph_builder -->|"reads and writes"| node_workflow_state
node_graph_builder -->|"routes advisory path"| node_advisor
node_graph_builder -->|"routes goal path"| node_goal
node_graph_builder -->|"routes risk path"| node_risk
node_advisor -->|"delegates specialization"| node_finance_adviser
node_advisor -->|"grounds response"| node_rag_ask
node_advisor -->|"enriches and updates profile"| node_user_memory
node_goal -->|"uses expense history"| node_expense_tracker
node_goal -->|"uses goals and facts"| node_user_memory
node_risk -->|"analyzes portfolio"| node_portfolio_tools
node_risk -->|"calculates investments"| node_smart_portfolio
node_risk -->|"fetches market context"| node_market_tools
node_expense_parser -->|"parses expense input"| node_expense_tracker
node_expense_tracker -->|"records expense facts"| node_user_memory
node_user_memory -->|"persists profile"| node_memory_store
node_rag_ask -->|"retrieves context"| node_retriever
node_retriever -->|"searches chunks"| node_vector_index
node_finance_docs -->|"source material"| node_rag_ingest
node_rag_ingest -->|"builds index"| node_vector_index

click node_cli "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/main.py"
click node_api "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/app.py"
click node_graph_builder "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/graph/builder.py"
click node_workflow_state "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/graph/state.py"
click node_advisor "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Agents/advisor_agent.py"
click node_goal "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Agents/goal_agent.py"
click node_risk "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Agents/risk_agent.py"
click node_finance_adviser "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Agents/finance_adviser.py"
click node_portfolio_tools "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Tools/portfolio_analyser.py"
click node_smart_portfolio "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Tools/smart_portfolio_analyzer.py"
click node_market_tools "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Tools/stock_tools.py"
click node_expense_parser "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/ExpenseTracker/parser.py"
click node_expense_tracker "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/ExpenseTracker/tracker.py"
click node_user_memory "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Memory/user_memory.py"
click node_memory_store "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/memory.json"
click node_rag_ask "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/RAG/ask.py"
click node_retriever "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/RAG/retriever.py"
click node_rag_ingest "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/RAG/ingest.py"
click node_finance_docs "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/data/finance.txt"
click node_vector_index "https://github.com/kushagramahalaha/financial-ai-agent/blob/main/vector_db/index.faiss"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_api toneBlue
class node_graph_builder,node_workflow_state toneAmber
class node_advisor,node_goal,node_risk,node_finance_adviser toneMint
class node_portfolio_tools,node_smart_portfolio,node_market_tools,node_expense_parser,node_expense_tracker toneRose
class node_user_memory,node_memory_store,node_rag_ask,node_retriever,node_rag_ingest,node_finance_docs,node_vector_index toneIndigo
```

## Components

### Entry points

- [CLI runner](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/main.py): Python entry point · `main.py`
- [FastAPI server](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/app.py): HTTP entry point · `app.py`

### Workflow control

- [LangGraph builder](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/graph/builder.py): workflow assembly · Routes shared state through financial paths and synthesis. · `graph/builder.py`
- [Shared workflow state](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/graph/state.py): LangGraph state · `graph/state.py`

### Financial agents

- [Advisor coordinator](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Agents/advisor_agent.py): financial agent · `Agents/advisor_agent.py`
- [Goal planner](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Agents/goal_agent.py): financial agent · `Agents/goal_agent.py`
- [Risk evaluator](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Agents/risk_agent.py): financial agent · `Agents/risk_agent.py`
- [Finance adviser](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Agents/finance_adviser.py): agent specialization · `Agents/finance_adviser.py`

### Financial capabilities

- [Portfolio analysis](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Tools/portfolio_analyser.py): analysis tools · `Tools/portfolio_analyser.py`
- [Investment calculations](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Tools/smart_portfolio_analyzer.py): analysis tools · `Tools/smart_portfolio_analyzer.py`
- [Market & news lookup](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Tools/stock_tools.py): external-data tools · `Tools/stock_tools.py`
- [Expense parser](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/ExpenseTracker/parser.py): expense input · `ExpenseTracker/parser.py`
- [Expense tracker](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/ExpenseTracker/tracker.py): expense tracking · `ExpenseTracker/tracker.py`

### Persistent & retrieved context

- [User memory manager](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/Memory/user_memory.py): profile memory · Extracts and maintains durable financial facts, goals, and expenses. · `Memory/user_memory.py`
- [User memory store](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/memory.json): JSON persistence · `memory.json`
- [RAG query interface](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/RAG/ask.py): retrieval interface · `RAG/ask.py`
- [Finance retriever](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/RAG/retriever.py): vector retrieval · `RAG/retriever.py`
- [RAG ingestion](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/RAG/ingest.py): indexing pipeline · `RAG/ingest.py`
- [Finance reference docs](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/data/finance.txt): knowledge documents · `data/finance.txt`
- [FAISS vector index](https://github.com/kushagramahalaha/financial-ai-agent/blob/main/vector_db/index.faiss): retrieval index · `vector_db/index.faiss`

## Connections

- 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
