# gilgamish-hub/finreport-agent architecture

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

- Interactive diagram: https://gitdiagram.com/gilgamish-hub/finreport-agent
- Repository: https://github.com/gilgamish-hub/finreport-agent

## Overview

FinReport Agent takes an analyst’s question about a selected company filing and returns a grounded answer with cited pages, optionally routing direct lookups through plain RAG and calculations or comparisons through an agent loop. Filings are extracted into page-aware chunks for hybrid retrieval; the agent grades and may rewrite searches, reasons over full pages, uses a calculator, and verifies numerical support. Streamlit, FastAPI, and MCP expose the product. The README documents evaluation and routing capabilities; unsampled modules are represented conservatively, with uncertain wiring omitted.

Main entry points: [`finagent/graph.py`](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/graph.py) (Agent workflow), [`finagent/ingest.py`](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/ingest.py) (PDF ingestion), [`finagent/retriever.py`](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/retriever.py) (Hybrid retrieval), [`app.py`](https://github.com/gilgamish-hub/finreport-agent/blob/main/app.py) (Streamlit demo)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Filing ingestion"]
  node_ingest_pdf["PDF ingestion<br/>[ingest.py]"]
  node_vector_store[("Chroma index<br/>[ingest.py]")]
  node_config["Runtime configuration<br/>[config.py]"]
end

subgraph group_answer["Answering engine"]
  node_retrieval["Hybrid retrieval<br/>[retriever.py]"]
  node_agent_graph["Agent workflow<br/>[graph.py]"]
  node_prompts["Agent prompts<br/>[prompts.py]"]
  node_grounding["Answer grounding<br/>[grounding.py]"]
  node_calculator["Safe calculator<br/>[tools.py]"]
  node_llm["Model adapters<br/>[llm.py]"]
end

subgraph group_interfaces["User interfaces"]
  node_streamlit["Streamlit demo<br/>[app.py]"]
  node_http_api["HTTP API<br/>[api.py]"]
  node_mcp["MCP server<br/>[mcp_server.py]"]
  node_demo_data["Demo data<br/>[demo.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_baseline["Plain RAG baseline<br/>[baseline.py]"]
  node_evaluation_runtime["Benchmark evaluation<br/>[evaluate.py]"]
end

node_analyst(("Analyst"))
node_filing_pdfs["Filing PDFs"]
node_model_providers["LLM providers"]
node_mcp_client(("MCP client"))

node_analyst -->|"asks questions"| node_streamlit
node_analyst -->|"asks questions"| node_http_api
node_mcp_client -->|"searches and asks"| node_mcp
node_filing_pdfs -->|"extracts pages"| node_ingest_pdf
node_ingest_pdf -->|"indexes chunks"| node_vector_store
node_vector_store -->|"supplies chunks"| node_retrieval
node_retrieval -->|"searches index"| node_vector_store
node_agent_graph -->|"retrieves evidence"| node_retrieval
node_agent_graph -->|"formats model tasks"| node_prompts
node_agent_graph -->|"dispatches calculations"| node_calculator
node_agent_graph -.->|"checks support"| node_grounding
node_agent_graph -.->|"invokes models"| node_llm
node_streamlit -->|"runs workflow"| node_agent_graph
node_streamlit -->|"validates uploads"| node_ingest_pdf
node_streamlit -.->|"loads examples"| node_demo_data
node_http_api -->|"runs workflow"| node_agent_graph
node_http_api -->|"lists indexed reports"| node_ingest_pdf
node_mcp -.->|"exposes agent tools"| node_agent_graph
node_llm -.->|"calls models"| node_model_providers
node_baseline -.->|"uses retrieval"| node_retrieval
node_evaluation_runtime -.->|"compares baseline"| node_baseline
node_evaluation_runtime -.->|"evaluates answers"| node_agent_graph
node_ingest_pdf -->|"reads settings"| node_config
node_retrieval -->|"reads limits"| node_config

click node_streamlit "https://github.com/gilgamish-hub/finreport-agent/blob/main/app.py"
click node_http_api "https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/api.py"
click node_mcp "https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/mcp_server.py"
click node_ingest_pdf "https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/ingest.py"
click node_vector_store "https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/ingest.py"
click node_retrieval "https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/retriever.py"
click node_agent_graph "https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/graph.py"
click node_prompts "https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/prompts.py"
click node_grounding "https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/grounding.py"
click node_calculator "https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/tools.py"
click node_llm "https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/llm.py"
click node_config "https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/config.py"
click node_demo_data "https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/demo.py"
click node_baseline "https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/baseline.py"
click node_evaluation_runtime "https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/evaluate.py"

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_ingest_pdf,node_vector_store,node_config,node_mcp_client toneBlue
class node_retrieval,node_agent_graph,node_prompts,node_grounding,node_calculator,node_llm toneAmber
class node_streamlit,node_http_api,node_mcp,node_demo_data toneMint
class node_baseline,node_evaluation_runtime toneRose
class node_analyst,node_filing_pdfs,node_model_providers toneIndigo
```

## Components

### Filing ingestion

- [PDF ingestion](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/ingest.py): `finagent/ingest.py`
- [Chroma index](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/ingest.py): `finagent/ingest.py`
- [Runtime configuration](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/config.py): `finagent/config.py`

### Answering engine

- [Hybrid retrieval](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/retriever.py): `finagent/retriever.py`
- [Agent workflow](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/graph.py): `finagent/graph.py`
- [Agent prompts](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/prompts.py): `finagent/prompts.py`
- [Answer grounding](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/grounding.py): `finagent/grounding.py`
- [Safe calculator](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/tools.py): `finagent/tools.py`
- [Model adapters](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/llm.py): `finagent/llm.py`

### User interfaces

- [Streamlit demo](https://github.com/gilgamish-hub/finreport-agent/blob/main/app.py): `app.py`
- [HTTP API](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/api.py): `finagent/api.py`
- [MCP server](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/mcp_server.py): `finagent/mcp_server.py`
- [Demo data](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/demo.py): `finagent/demo.py`

### Evaluation

- [Plain RAG baseline](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/baseline.py): `finagent/baseline.py`
- [Benchmark evaluation](https://github.com/gilgamish-hub/finreport-agent/blob/main/finagent/evaluate.py): `finagent/evaluate.py`

### Other components

- **Analyst**
- **Filing PDFs**
- **LLM providers**
- **MCP client**

## Connections

- Analyst → Streamlit demo: asks questions (evidence: `README.md`)
- Analyst → HTTP API: asks questions (evidence: `README.md`)
- MCP client → MCP server: searches and asks (evidence: `README.md`)
- Filing PDFs → PDF ingestion: extracts pages (evidence: `finagent/ingest.py`)
- PDF ingestion → Chroma index: indexes chunks (evidence: `finagent/ingest.py`)
- Chroma index → Hybrid retrieval: supplies chunks (evidence: `finagent/retriever.py`)
- Hybrid retrieval → Chroma index: searches index (evidence: `finagent/retriever.py`)
- Agent workflow → Hybrid retrieval: retrieves evidence (evidence: `finagent/graph.py`)
- Agent workflow → Agent prompts: formats model tasks (evidence: `finagent/graph.py`)
- Agent workflow → Safe calculator: dispatches calculations (evidence: `finagent/graph.py`)
- Agent workflow → Answer grounding: checks support (evidence: `finagent/graph.py`)
- Agent workflow → Model adapters: invokes models (evidence: `finagent/graph.py`)
- Streamlit demo → Agent workflow: runs workflow (evidence: `app.py`)
- Streamlit demo → PDF ingestion: validates uploads (evidence: `app.py`)
- Streamlit demo → Demo data: loads examples (evidence: `app.py`)
- HTTP API → Agent workflow: runs workflow (evidence: `finagent/api.py`)
- HTTP API → PDF ingestion: lists indexed reports (evidence: `finagent/api.py`)
- MCP server → Agent workflow: exposes agent tools
- Model adapters → LLM providers: calls models
- Plain RAG baseline → Hybrid retrieval: uses retrieval
- Benchmark evaluation → Plain RAG baseline: compares baseline
- Benchmark evaluation → Agent workflow: evaluates answers
- PDF ingestion → Runtime configuration: reads settings (evidence: `finagent/ingest.py`)
- Hybrid retrieval → Runtime configuration: reads limits (evidence: `finagent/retriever.py`)
