crazyafro/financial_intelligence_agent
Financial Intelligence Agent
A multi-agent AI platform for financial research, live market data, quantitative analysis, and automated report generation — built on LangGraph's supervisor pattern with a Gradio web UI.
Architecture
The system uses a Supervisor → Specialized Agent pattern. A central supervisor LLM reads every user message and decides which specialist agent to invoke. Agents call their tools, return results to the supervisor, and the loop continues until the task is complete.
User (Gradio UI)
│
▼
Supervisor (GPT-4o-mini · routes tasks)
┌───┼───────┬──────────┬────────┐
▼ ▼ ▼ ▼ ▼
Research Finance Analysis Report RAG
Agent Agent Agent Agent Agent
│ │ │ │ │
Tools Tools Tools Format index_doc
──↓── search_kb
[HITL]
──↓──
SaveAgents
Tools
Features
RAG — Persistent Vector Knowledge Base
The RAG Agent stores and retrieves information from a local ChromaDB vector database (chroma_db/). Every saved report or key finding can be indexed, enabling the system to:
- Recall past analyses across sessions
- Avoid duplicate research
- Find related context from previous work
Human-in-the-Loop Report Approval
Before any report is written to disk, the graph pauses (via LangGraph's interrupt_before) and surfaces an approval panel in the UI. You can:
- Approve & Save — resumes the graph, writes the file to
reports/ - Cancel Saving — injects a rejection message, the graph completes without saving
Setup
Prerequisites
- Python 3.9+
- OpenAI API key
- Tavily API key
- ExchangeRate-API key
- (Optional) LangSmith API key for tracing
Installation
git clone <repo-url>
cd financial_intelligence_agent
pip install -r requirements.txtConfiguration
Create a .env file in the project root:
OPENAI_API_KEY=sk-...
TAVILY_API_KEY=tvly-...
EXCHANGE_RATE_API_KEY=...
# Optional: enables LangSmith tracing
LANGCHAIN_API_KEY=lsv2_...
LANGCHAIN_TRACING_V2=true
LANGCHAIN_PROJECT=financial-intelligence-agentFor Hugging Face Spaces, set these as repository secrets (Settings → Variables and secrets) instead of using a .env file.
Usage
python app.pyOpen the Gradio UI at http://localhost:7860.
Example Queries
UI Controls
Memory and Persistence
Note for Hugging Face Spaces: the Spaces filesystem is ephemeral and resets on container restart. For persistent storage on Spaces, mount a Persistent Storage volume or use an external database.
Project Structure
financial_intelligence_agent/
├── app.py # Gradio web interface — entry point
├── requirements.txt
├── .env # API keys (not committed — see .gitignore)
├── .gitignore
├── diagram.png # Architecture diagram
├── generate_diagram.py # Script to regenerate diagram.png
│
├── agents/
│ ├── __init__.py # Exports all agent nodes
│ ├── state.py # Shared AgentState TypedDict
│ ├── supervisor.py # Supervisor routing logic
│ ├── research_agent.py # Web search + Wikipedia
│ ├── finance_agent.py # Stock, crypto, FX data
│ ├── analysis_agent.py # Calculator, date, summarize
│ ├── report_agent.py # Format + save reports (HITL gated)
│ └── rag_agent.py # Vector store search + index
│
├── graph/
│ ├── __init__.py # Exports build_graph, get_memory
│ ├── workflow.py # LangGraph StateGraph assembly + interrupt
│ └── memory.py # SQLite checkpointer
│
├── tools/
│ ├── __init__.py # Aggregates all tools by category
│ ├── search_tools.py # web_search, wikipedia_search
│ ├── finance_tools.py # get_stock_price, get_crypto_price, get_exchange_rate
│ ├── analysis_tools.py # calculator, get_date_context, summarize_text
│ ├── report_tools.py # format_markdown_report, save_report_to_file
│ └── rag_tools.py # index_document, search_knowledge_base
│
├── reports/ # Auto-created; timestamped .md reports
├── chroma_db/ # Auto-created; ChromaDB vector store
└── agent_memory.db # Auto-created; SQLite conversation memoryDeploying to Hugging Face Spaces
This repo is pre-configured for Spaces deployment (see YAML frontmatter above and server_name="0.0.0.0" in app.py).
Steps (requires you to do once):
- Push this repo to a GitHub repository
- Go to huggingface.co/new-space → choose Gradio SDK → link your GitHub repo
- In Space Settings → Variables and secrets, add your API keys:
OPENAI_API_KEYTAVILY_API_KEYEXCHANGE_RATE_API_KEY- (Optional) Add a Persistent Storage volume so
chroma_db/,reports/, andagent_memory.dbsurvive container restarts
