# baipengyan/tradingagents architecture

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

- Interactive diagram: https://gitdiagram.com/baipengyan/tradingagents
- Repository: https://github.com/baipengyan/tradingagents

## Overview

TradingAgents is a multi-agent financial research and decision-support framework, entered through a CLI or Python API. Its principal workflow gathers market, company, news, and sentiment evidence; produces analyst reports; debates bullish and bearish cases; forms a research plan; debates risk; and renders a final portfolio decision. The graph, agent, data-provider, and LLM-client paths are supported by the tree and sampled source. Some subsystem connections are shown only where the README or excerpts establish them; unsampled details are omitted.

Main entry points: [`tradingagents/dataflows/interface.py`](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/dataflows/interface.py) (Dataflow interface), [`tradingagents/graph/setup.py`](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/graph/setup.py) (Graph setup), [`tradingagents/agents/analysts`](https://github.com/baipengyan/tradingagents/tree/main/tradingagents/agents/analysts) (Analyst team), [`tradingagents/graph/trading_graph.py`](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/graph/trading_graph.py) (Trading graph)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User entry"]
  node_cli["Interactive CLI<br/>[main.py]"]
  node_api["Python API example<br/>[main.py]"]
end

subgraph group_workflow["Trading workflow"]
  node_graph["Trading graph<br/>[trading_graph.py]"]
  node_setup["Graph setup<br/>[setup.py]"]
  node_report["Decision reporting<br/>[reporting.py]"]
  node_memory["Decision memory<br/>[memory.py]"]
end

subgraph group_research["Research agents"]
  node_analysts["Analyst team"]
  node_market["Market analysis<br/>[market_analyst.py]"]
  node_fundamentals["Fundamentals analysis"]
  node_news["News analysis<br/>[news_analyst.py]"]
  node_sentiment["Sentiment analysis"]
  node_researchers["Bull-bear debate"]
  node_research_manager["Research plan"]
  node_trader["Trade proposal<br/>[trader.py]"]
  node_risk["Risk debate"]
  node_portfolio["Portfolio decision"]
end

subgraph group_data["Data sources"]
  node_dataflows["Dataflow interface<br/>[interface.py]"]
  node_market_data["Market data vendors"]
  node_news_data["News and sentiment"]
  node_macro_data["Macro and prediction"]
end

subgraph group_services["Models and state"]
  node_llm_factory["LLM provider factory<br/>[factory.py]"]
  node_llm_clients["Provider clients"]
  node_checkpoint[("Graph checkpointing<br/>[checkpointer.py]")]
end

node_user(("Trader or researcher"))
node_external_llm(("LLM providers"))

node_user -->|"configures run"| node_cli
node_user -->|"starts analysis"| node_api
node_cli -->|"runs analysis"| node_graph
node_api -->|"propagates ticker"| node_graph
node_graph -->|"builds workflow"| node_setup
node_setup -->|"dispatches analysis"| node_analysts
node_analysts -->|"includes"| node_market
node_analysts -->|"includes"| node_fundamentals
node_analysts -->|"includes"| node_news
node_analysts -->|"includes"| node_sentiment
node_setup -->|"dispatches debate"| node_researchers
node_researchers -->|"informs plan"| node_research_manager
node_setup -->|"dispatches proposal"| node_trader
node_setup -->|"dispatches risk debate"| node_risk
node_setup -->|"dispatches decision"| node_portfolio
node_portfolio -->|"provides decision"| node_report
node_graph -.->|"uses reflections"| node_memory
node_market -->|"requests evidence"| node_dataflows
node_fundamentals -->|"requests evidence"| node_dataflows
node_news -->|"requests evidence"| node_dataflows
node_sentiment -->|"requests evidence"| node_dataflows
node_dataflows -->|"routes market queries"| node_market_data
node_dataflows -->|"routes news queries"| node_news_data
node_dataflows -->|"routes macro queries"| node_macro_data
node_llm_factory -->|"creates client"| node_llm_clients
node_llm_clients -->|"sends prompts"| node_external_llm
node_graph -.->|"saves workflow state"| node_checkpoint

click node_cli "https://github.com/baipengyan/tradingagents/blob/main/cli/main.py"
click node_api "https://github.com/baipengyan/tradingagents/blob/main/main.py"
click node_graph "https://github.com/baipengyan/tradingagents/blob/main/tradingagents/graph/trading_graph.py"
click node_setup "https://github.com/baipengyan/tradingagents/blob/main/tradingagents/graph/setup.py"
click node_analysts "https://github.com/baipengyan/tradingagents/tree/main/tradingagents/agents/analysts"
click node_market "https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/analysts/market_analyst.py"
click node_fundamentals "https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/analysts/fundamentals_analyst.py"
click node_news "https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/analysts/news_analyst.py"
click node_sentiment "https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/analysts/sentiment_analyst.py"
click node_researchers "https://github.com/baipengyan/tradingagents/tree/main/tradingagents/agents/researchers"
click node_research_manager "https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/managers/research_manager.py"
click node_trader "https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/trader/trader.py"
click node_risk "https://github.com/baipengyan/tradingagents/tree/main/tradingagents/agents/risk_mgmt"
click node_portfolio "https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/managers/portfolio_manager.py"
click node_report "https://github.com/baipengyan/tradingagents/blob/main/tradingagents/reporting.py"
click node_memory "https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/utils/memory.py"
click node_dataflows "https://github.com/baipengyan/tradingagents/blob/main/tradingagents/dataflows/interface.py"
click node_market_data "https://github.com/baipengyan/tradingagents/tree/main/tradingagents/dataflows"
click node_news_data "https://github.com/baipengyan/tradingagents/tree/main/tradingagents/dataflows"
click node_macro_data "https://github.com/baipengyan/tradingagents/tree/main/tradingagents/dataflows"
click node_llm_factory "https://github.com/baipengyan/tradingagents/blob/main/tradingagents/llm_clients/factory.py"
click node_llm_clients "https://github.com/baipengyan/tradingagents/tree/main/tradingagents/llm_clients"
click node_checkpoint "https://github.com/baipengyan/tradingagents/blob/main/tradingagents/graph/checkpointer.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_cli,node_api toneBlue
class node_graph,node_setup,node_report,node_memory toneAmber
class node_analysts,node_market,node_fundamentals,node_news,node_sentiment,node_researchers,node_research_manager,node_trader,node_risk,node_portfolio toneMint
class node_dataflows,node_market_data,node_news_data,node_macro_data toneRose
class node_llm_factory,node_llm_clients,node_checkpoint,node_user,node_external_llm toneIndigo
```

## Components

### User entry

- [Interactive CLI](https://github.com/baipengyan/tradingagents/blob/main/cli/main.py): `cli/main.py`
- [Python API example](https://github.com/baipengyan/tradingagents/blob/main/main.py): `main.py`

### Trading workflow

- [Trading graph](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/graph/trading_graph.py): `tradingagents/graph/trading_graph.py`
- [Graph setup](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/graph/setup.py): `tradingagents/graph/setup.py`
- [Decision reporting](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/reporting.py): `tradingagents/reporting.py`
- [Decision memory](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/utils/memory.py): `tradingagents/agents/utils/memory.py`

### Research agents

- [Analyst team](https://github.com/baipengyan/tradingagents/tree/main/tradingagents/agents/analysts): `tradingagents/agents/analysts`
- [Market analysis](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/analysts/market_analyst.py): `tradingagents/agents/analysts/market_analyst.py`
- [Fundamentals analysis](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/analysts/fundamentals_analyst.py): `tradingagents/agents/analysts/fundamentals_analyst.py`
- [News analysis](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/analysts/news_analyst.py): `tradingagents/agents/analysts/news_analyst.py`
- [Sentiment analysis](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/analysts/sentiment_analyst.py): `tradingagents/agents/analysts/sentiment_analyst.py`
- [Bull-bear debate](https://github.com/baipengyan/tradingagents/tree/main/tradingagents/agents/researchers): `tradingagents/agents/researchers`
- [Research plan](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/managers/research_manager.py): `tradingagents/agents/managers/research_manager.py`
- [Trade proposal](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/trader/trader.py): `tradingagents/agents/trader/trader.py`
- [Risk debate](https://github.com/baipengyan/tradingagents/tree/main/tradingagents/agents/risk_mgmt): `tradingagents/agents/risk_mgmt`
- [Portfolio decision](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/agents/managers/portfolio_manager.py): `tradingagents/agents/managers/portfolio_manager.py`

### Data sources

- [Dataflow interface](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/dataflows/interface.py): `tradingagents/dataflows/interface.py`
- [Market data vendors](https://github.com/baipengyan/tradingagents/tree/main/tradingagents/dataflows): `tradingagents/dataflows`
- [News and sentiment](https://github.com/baipengyan/tradingagents/tree/main/tradingagents/dataflows): `tradingagents/dataflows`
- [Macro and prediction](https://github.com/baipengyan/tradingagents/tree/main/tradingagents/dataflows): `tradingagents/dataflows`

### Models and state

- [LLM provider factory](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/llm_clients/factory.py): `tradingagents/llm_clients/factory.py`
- [Provider clients](https://github.com/baipengyan/tradingagents/tree/main/tradingagents/llm_clients): `tradingagents/llm_clients`
- [Graph checkpointing](https://github.com/baipengyan/tradingagents/blob/main/tradingagents/graph/checkpointer.py): `tradingagents/graph/checkpointer.py`

### Other components

- **Trader or researcher**
- **LLM providers**

## Connections

- Trader or researcher → Interactive CLI: configures run
- Trader or researcher → Python API example: starts analysis
- Interactive CLI → Trading graph: runs analysis
- Python API example → Trading graph: propagates ticker
- Trading graph → Graph setup: builds workflow
- Graph setup → Analyst team: dispatches analysis
- Analyst team → Market analysis: includes
- Analyst team → Fundamentals analysis: includes
- Analyst team → News analysis: includes
- Analyst team → Sentiment analysis: includes
- Graph setup → Bull-bear debate: dispatches debate
- Bull-bear debate → Research plan: informs plan
- Graph setup → Trade proposal: dispatches proposal
- Graph setup → Risk debate: dispatches risk debate
- Graph setup → Portfolio decision: dispatches decision
- Portfolio decision → Decision reporting: provides decision
- Trading graph → Decision memory: uses reflections
- Market analysis → Dataflow interface: requests evidence
- Fundamentals analysis → Dataflow interface: requests evidence
- News analysis → Dataflow interface: requests evidence
- Sentiment analysis → Dataflow interface: requests evidence
- Dataflow interface → Market data vendors: routes market queries
- Dataflow interface → News and sentiment: routes news queries
- Dataflow interface → Macro and prediction: routes macro queries
- LLM provider factory → Provider clients: creates client
- Provider clients → LLM providers: sends prompts
- Trading graph → Graph checkpointing: saves workflow state
