Architecture Note: ReAct (Reasoning + Acting) agent pattern with RAG over SEC filings for financial research and company analysis.
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#C17852', 'primaryTextColor': '#F0F6FC', 'primaryBorderColor': '#4A5E32', 'lineColor': '#E6C98F', 'secondaryColor': '#161B22', 'tertiaryColor': '#0D1117', 'background': '#0D1117', 'mainBkg': '#161B22', 'nodeBorder': '#4A5E32', 'clusterBkg': '#161B22', 'clusterBorder': '#4A5E32', 'titleColor': '#E6C98F', 'edgeLabelBackground': '#161B22'}}}%%
flowchart LR
subgraph Input["📥 Data Sources"]
T[("📊 Stock Ticker")]
F[("📄 Filing Type
10-K, 10-Q, 8-K")]
end
subgraph Edgar["🏛️ EDGAR API"]
A["🔍 Search Filings"]
D["📥 Download HTML"]
P["🔧 Parse Content"]
end
subgraph Process["⚙️ Processing"]
C["✂️ Recursive Splitter
chunk_size=1000"]
E["🔢 OpenAI Embeddings
text-embedding-ada"]
end
subgraph Storage["💾 Vector Store"]
V[("🗄️ ChromaDB
Persistent")]
M[("📋 Metadata
ticker, date, type")]
end
T --> A
F --> A
A --> D
D --> P
P --> C
C --> E
E --> V
E --> M
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#C17852', 'primaryTextColor': '#F0F6FC', 'primaryBorderColor': '#4A5E32', 'lineColor': '#E6C98F', 'secondaryColor': '#161B22', 'tertiaryColor': '#0D1117', 'background': '#0D1117', 'mainBkg': '#161B22', 'nodeBorder': '#4A5E32', 'clusterBkg': '#161B22', 'clusterBorder': '#4A5E32', 'titleColor': '#E6C98F', 'edgeLabelBackground': '#161B22'}}}%%
flowchart TB
subgraph Query["💬 User Query"]
Q["🔍 Financial Question"]
end
subgraph Embed["🔢 Query Processing"]
QE["🔢 Query Embedding"]
end
subgraph Retrieval["📚 Retrieval"]
VS[("🗄️ ChromaDB")]
SR["🎯 Similarity Search
top_k=5"]
RD["📄 Retrieved Docs"]
end
subgraph Context["📋 Context Building"]
CB["📝 Context Builder"]
MP["📊 Metadata Filter"]
end
subgraph LLM["🧠 Generation"]
PT["📝 Prompt Template"]
G["🤖 GPT-4
Generate Answer"]
end
subgraph Output["📤 Response"]
A["✅ Answer + Citations"]
end
Q --> QE
QE --> VS
VS --> SR
SR --> RD
RD --> CB
MP --> CB
CB --> PT
PT --> G
G --> A
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#C17852', 'primaryTextColor': '#F0F6FC', 'primaryBorderColor': '#4A5E32', 'lineColor': '#E6C98F', 'secondaryColor': '#161B22', 'tertiaryColor': '#0D1117', 'background': '#0D1117', 'mainBkg': '#161B22', 'nodeBorder': '#4A5E32', 'clusterBkg': '#161B22', 'clusterBorder': '#4A5E32', 'titleColor': '#E6C98F', 'edgeLabelBackground': '#161B22'}}}%%
flowchart TB
subgraph Input["📥 Input"]
Q["🔍 Complex Query"]
end
subgraph Agent["🤖 ReAct Agent"]
T["💭 Thought
Reasoning Step"]
A["⚡ Action
Choose Tool"]
O["👁️ Observation
Tool Result"]
D{"🎯 Done?"}
end
subgraph Tools["🔧 Available Tools"]
R["📚 RAG Search
Vector Retrieval"]
E["🏛️ EDGAR Query
Filing Search"]
C["🔢 Calculator
Financial Math"]
end
subgraph Output["📤 Output"]
F["✅ Final Answer"]
end
Q --> T
T --> A
A --> R
A --> E
A --> C
R --> O
E --> O
C --> O
O --> D
D -->|"No"| T
D -->|"Yes"| F
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#C17852', 'primaryTextColor': '#F0F6FC', 'primaryBorderColor': '#4A5E32', 'lineColor': '#E6C98F', 'secondaryColor': '#161B22', 'tertiaryColor': '#0D1117', 'background': '#0D1117', 'mainBkg': '#161B22', 'nodeBorder': '#4A5E32', 'clusterBkg': '#161B22', 'clusterBorder': '#4A5E32', 'titleColor': '#E6C98F', 'edgeLabelBackground': '#161B22'}}}%%
flowchart LR
subgraph Filing["📄 SEC Filing"]
F10["📊 10-K Annual"]
F10Q["📊 10-Q Quarterly"]
end
subgraph Extract["⚙️ Extraction"]
IS["💰 Income Statement"]
BS["📋 Balance Sheet"]
CF["💸 Cash Flow"]
end
subgraph Metrics["📈 Calculated Metrics"]
REV["💵 Revenue Growth"]
NI["📊 Net Income"]
EPS["📈 EPS"]
ROE["📉 ROE / ROA"]
DR["📊 Debt Ratio"]
end
subgraph Store["💾 Storage"]
VDB[("🗄️ ChromaDB")]
JSON[("📝 Structured JSON")]
end
F10 --> IS
F10 --> BS
F10 --> CF
F10Q --> IS
F10Q --> BS
IS --> REV
IS --> NI
IS --> EPS
BS --> ROE
BS --> DR
CF --> DR
REV --> VDB
NI --> VDB
EPS --> JSON
ROE --> JSON
DR --> JSON
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#C17852', 'primaryTextColor': '#F0F6FC', 'primaryBorderColor': '#4A5E32', 'lineColor': '#E6C98F', 'secondaryColor': '#161B22', 'tertiaryColor': '#0D1117', 'background': '#0D1117', 'mainBkg': '#161B22', 'nodeBorder': '#4A5E32', 'clusterBkg': '#161B22', 'clusterBorder': '#4A5E32', 'titleColor': '#E6C98F', 'edgeLabelBackground': '#161B22'}}}%%
flowchart TB
subgraph Input["📥 Input"]
T1["📊 Ticker A"]
T2["📊 Ticker B"]
Q["🔍 Comparison Query"]
end
subgraph Parallel["⚡ Parallel Retrieval"]
direction TB
R1["📚 RAG: Company A"]
R2["📚 RAG: Company B"]
end
subgraph Context["📋 Context Merge"]
M["🔗 Merge Documents"]
D["📊 Extract Metrics"]
end
subgraph Analysis["🧠 GPT-4 Analysis"]
P["📝 Comparison Prompt"]
A["🤖 Generate Analysis"]
end
subgraph Output["📤 Output"]
C["📊 Comparison Report"]
R["📈 Relative Metrics"]
end
T1 --> R1
T2 --> R2
Q --> P
R1 --> M
R2 --> M
M --> D
D --> P
P --> A
A --> C
A --> R
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#C17852', 'primaryTextColor': '#F0F6FC', 'primaryBorderColor': '#4A5E32', 'lineColor': '#E6C98F', 'secondaryColor': '#161B22', 'tertiaryColor': '#0D1117', 'background': '#0D1117', 'mainBkg': '#161B22', 'nodeBorder': '#4A5E32', 'clusterBkg': '#161B22', 'clusterBorder': '#4A5E32', 'titleColor': '#E6C98F', 'edgeLabelBackground': '#161B22'}}}%%
flowchart TB
subgraph Client["🖥️ Frontend"]
UI["💻 Web Interface"]
end
subgraph API["🔌 FastAPI Backend"]
EP["🛤️ Endpoints"]
AUTH["🔐 Auth"]
end
subgraph Agent["🤖 LangChain Agent"]
RA["🧠 ReAct Agent"]
TK["🔧 Tool Registry"]
end
subgraph RAG["📚 RAG Layer"]
RT["🔍 Retriever"]
EM["🔢 Embeddings"]
end
subgraph External["🌐 External APIs"]
ED["🏛️ SEC EDGAR"]
OAI["🤖 OpenAI API"]
end
subgraph Storage["💾 Persistence"]
CH[("🗄️ ChromaDB")]
FS[("📁 File System")]
end
UI <--> EP
EP --> AUTH
AUTH --> RA
RA <--> TK
TK <--> RT
RT <--> EM
EM <--> OAI
RT <--> CH
TK <--> ED
ED --> FS