| title | AI Finance Assistant |
|---|---|
| emoji | π° |
| colorFrom | green |
| colorTo | blue |
| sdk | streamlit |
| sdk_version | 1.38.0 |
| app_file | app.py |
| pinned | false |
Production-grade multi-agent AI finance assistant built with LangGraph, RAG, and real-time market APIs.
Democratizing financial literacy through intelligent conversational AI β helping beginners take their first steps toward financial security with personalized, accessible education and guidance.
- Architecture Overview
- Features
- Project Structure
- Setup Instructions
- Usage Examples
- API Documentation
- Testing
- Deployment
- Troubleshooting
- Contributing
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Streamlit Web App β
β ββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββββββ β
β β Chat β β Portfolio β β Market β β
β β Page β β Dashboard β β Overview β β
β ββββββ¬ββββββ ββββββββββ¬ββββββββββ ββββββββββββ¬ββββββββββββ β
βββββββββΌββββββββββββββββββΌβββββββββββββββββββββββββΌβββββββββββββββ
β β β
βββββββββββββββββββΌβββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββ
β LangGraph Workflow Engine β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Query Router (LLM) β β
β βββββ¬βββββββ¬βββββββ¬βββββββ¬βββββββ¬βββββββ¬βββββββ¬βββββββββββββ β
β β β β β β β β β
β β ββββΌβββββββΌβββββββΌβββββββΌβββββββΌβββ β Single-domain β
β β βPort.ββMkt. ββGoal ββNews ββTax β β Agents β
β β βAgentββAgentββAgentββAgentββAgentβ β β
β β ββββ¬βββββββ¬βββββββ¬βββββββ¬βββββββ¬βββ β β
β β β β β β β β β
β βββββΌβββ β β β β β βββββΌβββββββββββββββ β
β βFin QAβ β β β β β β Planner Agent β β
β βAgent β β β β β β β (LLM decompose) β β
β βββββ¬βββ β β β β β βββββββββ¬βββββββββββ β
β β β β β β β β β
β β β β β β β βββββββββΌβββββββββββ β
β β β β β β β βMulti-Agent β β
β β β β β β β βCoordinator β β
β β β β β β β β(parallel asyncio)β β
β β β β β β β ββββ¬βββββ¬βββββ¬ββββββ β
β β β β β β β β β β β
β β β β β β β Mktβ Taxβ Goalβ β
β β β β β β β β β β β
β β β β β β β ββββΌβββββΌβββββΌββββββ β
β β β β β β β β LLM Synthesizer β β
β β β β β β β ββββββββββββββββββββ β
ββββββββΌβββββββΌβββββββΌβββββββΌβββββββΌβββββββΌβββββββββββββββββββββββ
β β β β β β
ββββββββΌβββββββΌβββββββΌβββββββΌβββββββΌβββββββΌββββββββββββββββββββββββ
β RAG Pipeline β Market Data APIs β
β βββββββββββββββββββββββββββββββ β ββββββββββββββββββββββββ β
β β Knowledge Base (50+ docs) β β β yFinance / Alpha β β
β β FAISS Vector Store β β β Vantage API β β
β β Semantic Search β β β + TTL Cache β β
β βββββββββββββββββββββββββββββββ β ββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββ
Single-domain query (e.g. "What is a bond?"):
User Query β Router β Specialized Agent β RAG Retrieval β LLM β Response β UI
Multi-domain query (e.g. retirement + market volatility + tax implications):
User Query β Router β Planner Agent (decompose)
β
βββββββββββββΌββββββββββββ
βΌ βΌ βΌ
Market Agent Tax Agent Goal Agent (parallel)
β β β
βββββββββββββΌββββββββββββ
βΌ
LLM Synthesizer β Unified Response β UI
| Component | Technology | Purpose |
|---|---|---|
| Multi-Agent System | LangGraph | Orchestrates specialized agents with state management |
| Language Model | OpenAI GPT / Google Gemini / Claude | Natural language understanding and generation |
| Vector Database | FAISS / ChromaDB | Semantic search over financial knowledge base |
| Market Data | yFinance / Alpha Vantage | Real-time stock quotes and financial data |
| Web Interface | Streamlit | Interactive multi-tab user experience |
| Embeddings | sentence-transformers | Local embedding generation for RAG |
- Finance Q&A Agent β General financial education (stocks, bonds, ETFs, diversification)
- Portfolio Analysis Agent β Portfolio review, diversification assessment, risk analysis
- Market Analysis Agent β Real-time stock data, market trends, company information
- Goal Planning Agent β SMART goal setting, savings plans, retirement projections
- News Synthesizer Agent β Financial news summarization with educational context
- Tax Education Agent β Tax-advantaged accounts, capital gains, tax strategies
- Planner Agent β Orchestrates complex multi-domain queries by decomposing them into targeted sub-tasks for the relevant specialist agents, then synthesizes a unified answer
- RAG-Powered Responses β Grounded in a curated financial knowledge base with source citations
- Real-Time Market Data β Live stock quotes, historical charts, company information
- Intelligent Routing β LLM-based query classification routes to the optimal agent
- Multi-Agent Planning β Complex cross-domain questions (e.g. retirement + market + tax) are automatically decomposed, run in parallel across specialist agents, and synthesized into one coherent answer
- Conversation Context β Multi-turn conversations with history preservation
- Portfolio Visualization β Interactive charts showing allocation and performance
- Proper Disclaimers β Clear separation between education and financial advice
ai_finance_assistant/
βββ src/
β βββ agents/ # Specialized financial agents
β β βββ base_agent.py # Abstract base class for all agents
β β βββ finance_qa_agent.py # General financial education
β β βββ portfolio_agent.py # Portfolio analysis
β β βββ market_agent.py # Real-time market insights
β β βββ goal_planning_agent.py# Financial goal planning
β β βββ news_agent.py # News synthesis
β β βββ tax_agent.py # Tax education
β β βββ planner_agent.py # Multi-domain query planner
β βββ core/ # Core infrastructure
β β βββ config.py # Configuration management (Pydantic + YAML)
β β βββ llm.py # LLM factory (OpenAI/Google/Anthropic)
β β βββ state.py # LangGraph state schema
β β βββ prompts.py # System prompts and templates
β βββ data/ # Data layer
β β βββ market_data.py # Market data provider (yFinance/Alpha Vantage)
β β βββ cache.py # TTL cache for API responses
β β βββ knowledge_base/ # Financial education articles (RAG source)
β βββ rag/ # RAG pipeline
β β βββ embeddings.py # Embedding model factory
β β βββ vector_store.py # FAISS/Chroma vector store management
β β βββ retriever.py # Document retrieval with filtering
β β βββ indexer.py # Knowledge base indexing pipeline
β βββ web_app/ # Streamlit application
β β βββ app.py # Main app entry point
β β βββ pages/ # Multi-tab pages
β β β βββ chat.py # Conversational interface
β β β βββ portfolio.py # Portfolio dashboard
β β β βββ market.py # Market overview
β β βββ components/ # Reusable UI components
β β βββ sidebar.py # Navigation sidebar
β β βββ charts.py # Plotly chart builders
β βββ utils/ # Shared utilities
β β βββ logger.py # Structured logging (structlog)
β β βββ exceptions.py # Custom exception hierarchy
β β βββ validators.py # Input validation
β βββ workflow/ # LangGraph orchestration
β βββ graph.py # Workflow graph definition
β βββ router.py # LLM-based query router
β βββ nodes.py # Graph node implementations
βββ tests/ # Test suite
β βββ conftest.py # Shared fixtures
β βββ unit/ # Unit tests
β β βββ test_agents.py
β β βββ test_rag.py
β β βββ test_workflow.py
β βββ integration/ # Integration tests
β βββ test_end_to_end.py
β βββ test_market_data.py
βββ config.yaml # Application configuration
βββ main.py # Application initialization
βββ requirements.txt # Python dependencies
βββ pyproject.toml # Project metadata and tool config
βββ Dockerfile # Container configuration
βββ docker-compose.yml # Container orchestration
βββ .env.example # Environment variable template
βββ .gitignore # Git ignore rules
βββ README.md # This file
- Python 3.11+
- pip or conda
- Git
- API key for at least one LLM provider (OpenAI, Google, or Anthropic)
- (Optional) Alpha Vantage API key for market data
git clone <repository-url>
cd ai_finance_assistantpython -m venv .venv
source .venv/bin/activate
# Windows/Python
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activatepip install -r requirements.txt# Copy the example environment file
cp .env.example .env
# Edit .env with your API keys
# At minimum, set one LLM provider key:
# OPENAI_API_KEY=sk-...
# or GOOGLE_API_KEY=...
# or ANTHROPIC_API_KEY=...python -c "from src.rag.indexer import KnowledgeBaseIndexer; KnowledgeBaseIndexer().index()"streamlit run src/web_app/app.pyThe app will be available at http://localhost:8501
# Build and run with Docker Compose
docker-compose up --build
# Or build manually
docker build -t ai-finance-assistant .
docker run -p 8501:8501 --env-file .env ai-finance-assistantUser: "What is dollar-cost averaging and why should I use it?"
Agent: [Finance Q&A Agent responds with educational content + RAG sources]
User: "Analyze my portfolio: 50 shares AAPL, 30 shares MSFT, 100 shares VOO"
Agent: [Portfolio Agent analyzes diversification, concentration, and risk]
User: "What's the current price of Tesla?"
Agent: [Market Agent fetches live data from yFinance API]
User: "How should I save $50,000 for a house down payment in 3 years?"
Agent: [Goal Planning Agent creates a structured savings plan]
User: "What happened in the market today?"
Agent: [News Agent synthesizes recent financial news]
User: "How do Roth IRA conversions work?"
Agent: [Tax Agent explains with appropriate disclaimers]
User: "I am 45, want to retire in 15 years, the market looks volatile β should I increase my SIP investments and what are the tax implications?"
Agent: [Router detects multi-domain query β Planner decomposes into 3 sub-tasks
β Market, Tax, and Goal Planning agents run in parallel
β LLM Synthesizer merges outputs into a single cohesive answer]
User: "Why did Tesla stock fall today and should long-term investors worry?"
Agent: [Router detects multi-domain query β Planner decomposes into 3 sub-tasks ('market', 'news', 'portfolio')]
User: "I am 40 years old and want to retire at 60. What tax-efficient investments should I consider?"
Agent: [Router detects multi-domain query β Planner decomposes into 2 sub-tasks ('goal_planning', 'tax')]
User: "My portfolio is 70% tech stocks. Given the current market and taxes, should I diversify?"
Agent: [Router detects multi-domain query β Planner decomposes into 2 sub-tasks ('portfolio', 'market', 'tax')]
from main import initialize_app
from src.workflow.graph import create_workflow_graph
# Initialize the application
initialize_app()
# Create and invoke the workflow
graph = create_workflow_graph()
result = await graph.ainvoke({
"query": "What is compound interest?",
"chat_history": [],
})
print(result["response"])All agents implement the BaseAgent abstract class:
class BaseAgent(ABC):
async def process(self, state: AgentState) -> AgentState:
"""Process state and return updated state with response."""
...class AgentState(TypedDict):
query: str # User's input query
chat_history: list[dict] # Conversation history
route: str # Determined agent route
response: str # Generated response
sources: list[dict] # RAG source citations
portfolio_data: dict # Portfolio holdings
market_data: dict # Market quotes
symbols: list[str] # Extracted ticker symbols
# Multi-agent planner fields
is_multi_agent: bool # True when planner dispatched multiple agents
plan: list[dict] # Planner's sub-tasks: [{"agent", "sub_query"}, ...]
agent_outputs: dict[str, str] # Raw outputs keyed by agent name
error: str | None # Error informationConfiguration is loaded from config.yaml with environment variable overrides:
llm:
provider: "openai" # openai | google | anthropic
model: "gpt-4o-mini"
temperature: 0.1
vector_store:
type: "faiss" # faiss | chroma
chunk_size: 1000
market_data:
provider: "yfinance" # yfinance | alpha_vantage
cache_ttl_seconds: 300pytestpytest --cov=src --cov-report=html# Unit tests only
pytest tests/unit/
# Integration tests only
pytest tests/integration/ -m integration
# Specific agent tests
pytest tests/unit/test_agents.py -v- Unit Tests: Test individual agents, router, cache, and RAG components in isolation
- Integration Tests: Test end-to-end workflow execution and API interactions
docker-compose up --build -d| Variable | Required | Description |
|---|---|---|
OPENAI_API_KEY |
Yes* | OpenAI API key |
GOOGLE_API_KEY |
Yes* | Google Gemini API key |
ANTHROPIC_API_KEY |
Yes* | Anthropic API key |
ALPHA_VANTAGE_API_KEY |
No | Alpha Vantage key (defaults to yFinance) |
LLM_PROVIDER |
No | LLM provider to use (default: openai) |
LLM_MODEL |
No | Model name (default: gpt-4o-mini) |
LOG_LEVEL |
No | Logging level (default: INFO) |
*At least one LLM provider key is required.
| Issue | Solution |
|---|---|
ModuleNotFoundError |
Ensure virtual env is activated and dependencies installed |
OPENAI_API_KEY not set |
Copy .env.example to .env and add your API key |
Vector store not initialized |
Run the knowledge base indexer (see Setup step 5) |
Rate limit exceeded |
Reduce request frequency or increase CACHE_TTL_SECONDS |
yfinance data unavailable |
Check network connection; some symbols may not be available |
Streamlit port in use |
Use streamlit run src/web_app/app.py --server.port=8502 |
Enable debug mode for verbose logging:
# In .env
APP_DEBUG=true
LOG_LEVEL=DEBUG# Delete persisted store and re-index
rm -rf data/vector_store/
python -c "from src.rag.indexer import KnowledgeBaseIndexer; KnowledgeBaseIndexer().index()"- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Linting
ruff check src/ tests/
# Type checking
mypy src/
# Format
ruff format src/ tests/This application is designed for educational purposes only and does not constitute financial advice. Always consult a qualified financial advisor before making investment decisions. The creators of this tool are not responsible for any financial decisions made based on its output.
MIT License β see LICENSE for details.