CoolFace
Apppublic

crazyafro/financial_intelligence_agent

sourceHugging Facemitupdated 4mo agoView on Hugging Face
0likes
App README

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.

[image]


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]
                           ──↓──
                          Save

Agents

AgentRoleTools
SupervisorRoutes requests to the best-fit agent; signals FINISH when done—
Research AgentFinds news, background info, and recent eventsweb_search, wikipedia_search
Finance AgentRetrieves live market dataget_stock_price, get_crypto_price, get_exchange_rate
Analysis AgentPerforms calculations, date context, text summarizationcalculator, get_date_context, summarize_text
Report AgentFormats reports then waits for human approval before savingformat_markdown_report, save_report_to_file
RAG AgentSearches and indexes the persistent vector knowledge basesearch_knowledge_base, index_document

Tools

ToolDescriptionData Source
web_searchReal-time internet search (4 results)Tavily API
wikipedia_searchWikipedia summaries with disambiguation handlingWikipedia
get_stock_pricePrice, market cap, P/E ratio, 52-week rangeyfinance
get_crypto_pricePrice, market cap, 24h changeCoinGecko API
get_exchange_rateCurrency pair conversion ratesExchangeRate-API
calculatorSafe math evaluation (sqrt, log, pow, etc.)Python math
get_date_contextCurrent date, time, day, and fiscal quarterSystem clock
summarize_textCondenses text into a 3-5 sentence summaryGPT-4o-mini
format_markdown_reportStructures raw data into a professional Markdown reportGPT-4o-mini
save_report_to_fileSaves report to reports/ — requires human approval firstLocal filesystem
search_knowledge_baseSemantic search over past analyses and reportsChromaDB + OpenAI Embeddings
index_documentIndexes text into the vector store for future retrievalChromaDB + OpenAI Embeddings

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

Installation

bash
git clone <repo-url>
cd financial_intelligence_agent
pip install -r requirements.txt

Configuration

Create a .env file in the project root:

env
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-agent

For Hugging Face Spaces, set these as repository secrets (Settings → Variables and secrets) instead of using a .env file.


Usage

bash
python app.py

Open the Gradio UI at http://localhost:7860.

Example Queries

QueryAgents Typically Used
Research Tesla, get stock price, convert market cap to EUR, save a reportResearch + Finance + Analysis + Report
What is Bitcoin's price? Summarize recent news and save a reportFinance + Research + Analysis + Report
Compare Apple vs Microsoft stocks — which has a higher P/E?Finance + Analysis
Search for the latest AI regulation news and format a briefingResearch + Report
What is 15% of Tesla's current stock price?Finance + Analysis
Search the knowledge base for past analyses on AppleRAG

UI Controls

ControlDescription
Show Agent Reasoning TraceExpands all tool calls and raw results below the answer
New SessionStarts a fresh conversation with a new thread ID
Session Thread IDKeep this to resume a conversation with full memory
Approve & Save(appears when a report is ready) Confirms writing to disk
Cancel Saving(appears when a report is ready) Discards the save without losing the formatted content

Memory and Persistence

StoreTechnologyLocationPersists across restarts
Conversation memorySQLite via LangGraph SqliteSaveragent_memory.dbYes
Knowledge base (RAG)ChromaDB + OpenAI Embeddingschroma_db/Yes
Generated reportsMarkdown filesreports/Yes
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 memory

Deploying 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):

  1. 1.Push this repo to a GitHub repository
  2. 2.Go to huggingface.co/new-space → choose Gradio SDK → link your GitHub repo
  3. 3.In Space Settings → Variables and secrets, add your API keys:
  4. 4.OPENAI_API_KEY
  5. 5.TAVILY_API_KEY
  6. 6.EXCHANGE_RATE_API_KEY
  7. 7.(Optional) Add a Persistent Storage volume so chroma_db/, reports/, and agent_memory.db survive container restarts

Tech Stack

ComponentTechnology
LLMOpenAI GPT-4o-mini
Agent frameworkLangChain + LangGraph
Vector store (RAG)ChromaDB + OpenAI Embeddings (text-embedding-3-small)
Web UIGradio
Conversation memoryLangGraph SQLite checkpointer
Web searchTavily
Stock datayfinance
Crypto dataCoinGecko API
Currency dataExchangeRate-API
TracingLangSmith (optional)