Trading graph
TradingAgentsGraph
Bases: BaseModel
flowchart TD
src.tradingagents.graph.trading_graph.TradingAgentsGraph[TradingAgentsGraph]
click src.tradingagents.graph.trading_graph.TradingAgentsGraph href "" "src.tradingagents.graph.trading_graph.TradingAgentsGraph"
Main class that orchestrates the trading agents framework.
Methods:
| Name | Description |
|---|---|
propagate |
Run the trading agents graph for a company on a specific date. |
reflect_and_remember |
Reflect on decisions and update memory based on returns. |
process_signal |
Process a signal to extract the core decision. |
selected_analysts
selected_analysts: list[str] = Field(
default=["market", "social", "news", "fundamentals"],
title="Selected Analysts",
description="List of analyst types to include in the trading graph",
)
debug
debug: bool = Field(
default=False,
title="Debug Mode",
description="Enable debug mode with step-by-step tracing output",
)
config
config: TradingAgentsConfig = Field(
..., title="Configuration", description="Trading agents configuration settings"
)
callbacks
callbacks: list = Field(
default_factory=list,
title="Callbacks",
description="Optional callback handlers for tracking LLM/tool statistics",
)
curr_state
curr_state: AgentState | None = Field(
default=None,
title="Current State",
description="Current graph execution state, populated after propagate()",
)
ticker
ticker: str = Field(
default="", title="Ticker", description="Current stock ticker symbol being analyzed"
)
log_states_dict
log_states_dict: dict[str, Any] = Field(
default_factory=dict,
title="Log States",
description="Accumulated state logs keyed by trade date",
)
deep_thinking_llm
Deep thinking LLM instance, derived from config.
Returns:
| Name | Type | Description |
|---|---|---|
ChatModel |
ChatModel
|
Deep thinking LLM instance. |
quick_thinking_llm
Quick thinking LLM instance, derived from config.
Returns:
| Name | Type | Description |
|---|---|---|
ChatModel |
ChatModel
|
Quick thinking LLM instance. |
bull_memory
Bull researcher memory instance.
Returns:
| Name | Type | Description |
|---|---|---|
FinancialSituationMemory |
FinancialSituationMemory
|
Memory instance for the bull researcher. |
bear_memory
Bear researcher memory instance.
Returns:
| Name | Type | Description |
|---|---|---|
FinancialSituationMemory |
FinancialSituationMemory
|
Memory instance for the bear researcher. |
trader_memory
Trader memory instance.
Returns:
| Name | Type | Description |
|---|---|---|
FinancialSituationMemory |
FinancialSituationMemory
|
Memory instance for the trader. |
invest_judge_memory
Investment judge memory instance.
Returns:
| Name | Type | Description |
|---|---|---|
FinancialSituationMemory |
FinancialSituationMemory
|
Memory instance for the investment judge. |
risk_manager_memory
Risk manager memory instance.
Returns:
| Name | Type | Description |
|---|---|---|
FinancialSituationMemory |
FinancialSituationMemory
|
Memory instance for the risk manager. |
tool_nodes
Tool nodes for different data sources.
Returns:
| Type | Description |
|---|---|
dict[str, ToolNode]
|
dict[str, ToolNode]: A dictionary mapping data source names to ToolNodes. |
graph
Compiled LangGraph workflow, derived from config and selected analysts.
Returns:
| Name | Type | Description |
|---|---|---|
CompiledStateGraph |
CompiledStateGraph
|
The compiled state graph workflow. |
propagator
Graph propagator for state initialization.
Returns:
| Name | Type | Description |
|---|---|---|
Propagator |
Propagator
|
A Propagator instance. |
reflector
Post-trade reflector for memory updates.
Returns:
| Name | Type | Description |
|---|---|---|
Reflector |
Reflector
|
A Reflector instance. |
signal_processor
Signal processor for extracting BUY/SELL/HOLD decisions.
Returns:
| Name | Type | Description |
|---|---|---|
SignalProcessor |
SignalProcessor
|
A SignalProcessor instance. |
propagate
propagate(
company_name: str,
trade_date: str,
on_message: Callable[[AnyMessage], None] | None = None,
on_state: Callable[[AgentState], None] | None = None,
) -> tuple[AgentState, str]
Run the trading agents graph for a company on a specific date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Company name or ticker symbol. |
required |
|
str
|
Trading date in YYYY-MM-DD format. |
required |
|
Callable[[AnyMessage], None] | None
|
Callback invoked once per newly-produced message during the stream. When provided, takes precedence over the default debug print path so callers (CLI, TUI) can route output through Rich panels instead of message.pretty_print(). Defaults to None. |
None
|
|
Callable[[AgentState], None] | None
|
Callback invoked once per stream chunk with the full AgentState snapshot. Used by the Textual TUI to update the phase progress sidebar from analyst-report / debate fields; the CLI does not need this. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[AgentState, str]
|
tuple[AgentState, str]: The final agent state and the extracted signal decision. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the graph execution produces no output. |
Source code in src/tradingagents/graph/trading_graph.py
reflect_and_remember
Reflect on decisions and update memory based on returns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
float
|
Actual returns or losses from the trade. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If there is no current state to reflect on. |
Source code in src/tradingagents/graph/trading_graph.py
process_signal
Process a signal to extract the core decision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The raw text signal. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The extracted decision (BUY/SELL/HOLD). |