# ro5f6/finai_agent architecture

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

- Interactive diagram: https://gitdiagram.com/ro5f6/finai_agent
- Repository: https://github.com/ro5f6/finai_agent

## Overview

FinAI-Agent is an investment-research assistant: a user query is planned by a LangGraph agent, answered with filing, market, or portfolio tools, and numerically verified before return. Separately, an ingestion command fetches and prepares SEC 10-K content for retrieval. The graph preserves README-documented capabilities, including structured financial history and portfolio-risk measures, though their implementations were not sampled. API routers appear empty in the tree; edges for unsampled runtime behavior are included only where the README or source index supports them.

Main entry points: [`src/finai/ingestion/ingest.py`](https://github.com/ro5f6/finai_agent/blob/main/src/finai/ingestion/ingest.py) (Ingestion runner), [`src/finai/agent/nodes.py`](https://github.com/ro5f6/finai_agent/blob/main/src/finai/agent/nodes.py) (LangGraph planner), [`src/finai/tools/agent_tools.py`](https://github.com/ro5f6/finai_agent/blob/main/src/finai/tools/agent_tools.py) (Agent tool wrappers), [`src/finai/tools/portfolio.py`](https://github.com/ro5f6/finai_agent/blob/main/src/finai/tools/portfolio.py) (Portfolio analytics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_research["Research agent"]
  node_planner["LangGraph planner<br/>[nodes.py]"]
  node_prompt["Research prompt<br/>[prompts.py]"]
  node_state["Agent state<br/>[state.py]"]
  node_verifier["Number verifier"]
end

subgraph group_tools["Research tools"]
  node_tool_wrappers["Agent tool wrappers<br/>[agent_tools.py]"]
  node_filing_search["10-K search<br/>[filings.py]"]
  node_financials["Financial history<br/>[filings.py]"]
  node_market["Live market data<br/>[market_data.py]"]
  node_portfolio["Portfolio analytics<br/>[portfolio.py]"]
end

subgraph group_filing_data["Filing ingestion"]
  node_ingest["Ingestion runner<br/>[ingest.py]"]
  node_fetch["SEC fetch/archive<br/>[fetch.py]"]
  node_parse["10-K extraction<br/>[parse.py]"]
  node_clean["Filing cleanup<br/>[clean.py]"]
  node_chunk["Table-aware chunks<br/>[chunk.py]"]
end

subgraph group_platform["Data services"]
  node_embedding["Embedding and reranking<br/>[embed.py]"]
  node_store["Vector search<br/>[store.py]"]
  node_qdrant[("Qdrant")]
  node_voyage{{"Voyage AI"}}
  node_finnhub{{"Finnhub"}}
  node_alpaca{{"Alpaca bars"}}
end

node_user(("Research user"))

node_user -->|"asks"| node_planner
node_planner -->|"uses prompt"| node_prompt
node_planner -->|"uses state"| node_state
node_planner -->|"dispatches tools"| node_tool_wrappers
node_tool_wrappers -->|"calls"| node_filing_search
node_tool_wrappers -->|"calls"| node_market
node_tool_wrappers -->|"calls"| node_portfolio
node_tool_wrappers -->|"provides"| node_financials
node_filing_search -->|"embeds query"| node_embedding
node_filing_search -->|"searches"| node_store
node_financials -->|"returns statements"| node_user
node_market -->|"fetches quotes"| node_finnhub
node_portfolio -->|"gets daily bars"| node_alpaca
node_planner -->|"checks numbers"| node_verifier
node_verifier -->|"returns answer"| node_user
node_ingest -->|"fetches filings"| node_fetch
node_ingest -->|"extracts items"| node_parse
node_ingest -->|"cleans items"| node_clean
node_ingest -->|"builds chunks"| node_chunk
node_ingest -->|"embeds chunks"| node_embedding
node_ingest -->|"upserts chunks"| node_store
node_embedding -->|"embeds and reranks"| node_voyage
node_store -->|"reads and writes"| node_qdrant
node_portfolio -->|"reports holdings"| node_user
node_portfolio -->|"computes risk metrics"| node_user

click node_planner "https://github.com/ro5f6/finai_agent/blob/main/src/finai/agent/nodes.py"
click node_prompt "https://github.com/ro5f6/finai_agent/blob/main/src/finai/agent/prompts.py"
click node_state "https://github.com/ro5f6/finai_agent/blob/main/src/finai/agent/state.py"
click node_verifier "https://github.com/ro5f6/finai_agent/tree/main/src/finai/guardrails"
click node_tool_wrappers "https://github.com/ro5f6/finai_agent/blob/main/src/finai/tools/agent_tools.py"
click node_filing_search "https://github.com/ro5f6/finai_agent/blob/main/src/finai/tools/filings.py"
click node_financials "https://github.com/ro5f6/finai_agent/blob/main/src/finai/tools/filings.py"
click node_market "https://github.com/ro5f6/finai_agent/blob/main/src/finai/tools/market_data.py"
click node_portfolio "https://github.com/ro5f6/finai_agent/blob/main/src/finai/tools/portfolio.py"
click node_ingest "https://github.com/ro5f6/finai_agent/blob/main/src/finai/ingestion/ingest.py"
click node_fetch "https://github.com/ro5f6/finai_agent/blob/main/src/finai/ingestion/fetch.py"
click node_parse "https://github.com/ro5f6/finai_agent/blob/main/src/finai/ingestion/parse.py"
click node_clean "https://github.com/ro5f6/finai_agent/blob/main/src/finai/ingestion/clean.py"
click node_chunk "https://github.com/ro5f6/finai_agent/blob/main/src/finai/ingestion/chunk.py"
click node_embedding "https://github.com/ro5f6/finai_agent/blob/main/src/finai/ingestion/embed.py"
click node_store "https://github.com/ro5f6/finai_agent/blob/main/src/finai/ingestion/store.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_planner,node_prompt,node_state,node_verifier,node_user toneBlue
class node_tool_wrappers,node_filing_search,node_financials,node_market,node_portfolio toneAmber
class node_ingest,node_fetch,node_parse,node_clean,node_chunk toneMint
class node_embedding,node_store,node_qdrant,node_voyage,node_finnhub,node_alpaca toneRose
```

## Components

### Research agent

- [LangGraph planner](https://github.com/ro5f6/finai_agent/blob/main/src/finai/agent/nodes.py): `src/finai/agent/nodes.py`
- [Research prompt](https://github.com/ro5f6/finai_agent/blob/main/src/finai/agent/prompts.py): `src/finai/agent/prompts.py`
- [Agent state](https://github.com/ro5f6/finai_agent/blob/main/src/finai/agent/state.py): `src/finai/agent/state.py`
- [Number verifier](https://github.com/ro5f6/finai_agent/tree/main/src/finai/guardrails): `src/finai/guardrails`

### Research tools

- [Agent tool wrappers](https://github.com/ro5f6/finai_agent/blob/main/src/finai/tools/agent_tools.py): `src/finai/tools/agent_tools.py`
- [10-K search](https://github.com/ro5f6/finai_agent/blob/main/src/finai/tools/filings.py): `src/finai/tools/filings.py`
- [Financial history](https://github.com/ro5f6/finai_agent/blob/main/src/finai/tools/filings.py): `src/finai/tools/filings.py`
- [Live market data](https://github.com/ro5f6/finai_agent/blob/main/src/finai/tools/market_data.py): `src/finai/tools/market_data.py`
- [Portfolio analytics](https://github.com/ro5f6/finai_agent/blob/main/src/finai/tools/portfolio.py): `src/finai/tools/portfolio.py`

### Filing ingestion

- [Ingestion runner](https://github.com/ro5f6/finai_agent/blob/main/src/finai/ingestion/ingest.py): `src/finai/ingestion/ingest.py`
- [SEC fetch/archive](https://github.com/ro5f6/finai_agent/blob/main/src/finai/ingestion/fetch.py): `src/finai/ingestion/fetch.py`
- [10-K extraction](https://github.com/ro5f6/finai_agent/blob/main/src/finai/ingestion/parse.py): `src/finai/ingestion/parse.py`
- [Filing cleanup](https://github.com/ro5f6/finai_agent/blob/main/src/finai/ingestion/clean.py): `src/finai/ingestion/clean.py`
- [Table-aware chunks](https://github.com/ro5f6/finai_agent/blob/main/src/finai/ingestion/chunk.py): `src/finai/ingestion/chunk.py`

### Data services

- [Embedding and reranking](https://github.com/ro5f6/finai_agent/blob/main/src/finai/ingestion/embed.py): `src/finai/ingestion/embed.py`
- [Vector search](https://github.com/ro5f6/finai_agent/blob/main/src/finai/ingestion/store.py): `src/finai/ingestion/store.py`
- **Qdrant**
- **Voyage AI**
- **Finnhub**
- **Alpaca bars**

### Other components

- **Research user**

## Connections

- Research user → LangGraph planner: asks (evidence: `README.md`)
- LangGraph planner → Research prompt: uses prompt (evidence: `src/finai/agent/nodes.py`)
- LangGraph planner → Agent state: uses state (evidence: `src/finai/agent/nodes.py`)
- LangGraph planner → Agent tool wrappers: dispatches tools (evidence: `src/finai/agent/nodes.py`)
- Agent tool wrappers → 10-K search: calls (evidence: `src/finai/tools/agent_tools.py`)
- Agent tool wrappers → Live market data: calls (evidence: `src/finai/tools/agent_tools.py`)
- Agent tool wrappers → Portfolio analytics: calls (evidence: `src/finai/tools/agent_tools.py`)
- Agent tool wrappers → Financial history: provides (evidence: `README.md`)
- 10-K search → Embedding and reranking: embeds query (evidence: `src/finai/tools/filings.py`)
- 10-K search → Vector search: searches (evidence: `src/finai/tools/filings.py`)
- Financial history → Research user: returns statements (evidence: `README.md`)
- Live market data → Finnhub: fetches quotes (evidence: `src/finai/tools/market_data.py`)
- Portfolio analytics → Alpaca bars: gets daily bars (evidence: `README.md`)
- LangGraph planner → Number verifier: checks numbers (evidence: `README.md`)
- Number verifier → Research user: returns answer (evidence: `README.md`)
- Ingestion runner → SEC fetch/archive: fetches filings (evidence: `src/finai/ingestion/ingest.py`)
- Ingestion runner → 10-K extraction: extracts items (evidence: `src/finai/ingestion/ingest.py`)
- Ingestion runner → Filing cleanup: cleans items (evidence: `src/finai/ingestion/ingest.py`)
- Ingestion runner → Table-aware chunks: builds chunks (evidence: `src/finai/ingestion/ingest.py`)
- Ingestion runner → Embedding and reranking: embeds chunks (evidence: `src/finai/ingestion/ingest.py`)
- Ingestion runner → Vector search: upserts chunks (evidence: `src/finai/ingestion/ingest.py`)
- Embedding and reranking → Voyage AI: embeds and reranks (evidence: `src/finai/ingestion/embed.py`)
- Vector search → Qdrant: reads and writes (evidence: `src/finai/ingestion/store.py`)
- Portfolio analytics → Research user: reports holdings (evidence: `README.md`)
- Portfolio analytics → Research user: computes risk metrics (evidence: `README.md`)
