Using the CLI Interface for Interactive Trading Analysis in TradingAgents

The TradingAgents CLI provides an interactive terminal interface that orchestrates a graph-based multi-agent workflow for financial analysis, gathering user inputs through cli/main.py and streaming real-time results through a Rich-based dashboard while delegating all calculations to modular agent nodes.

The TradingAgents open-source framework from TauricResearch simulates the decision-making pipeline of a real trading firm using large language models. Using the CLI interface for interactive trading analysis allows you to configure specialized analyst agents, select LLM providers, and execute complex research workflows through an intuitive terminal experience. The architecture cleanly separates the presentation layer from the core graph logic, enabling both interactive and programmatic access to the multi-agent system.

CLI Architecture and Data Flow

The TradingAgents system processes interactive trading analysis through a seven-stage pipeline that transforms user inputs into comprehensive trading decisions.

First, the CLI layer in cli/main.py gathers user input including ticker symbols, analysis dates, analyst selection, research depth, and LLM provider preferences. These selections merge into DEFAULT_CONFIG (defined in tradingagents/default_config.py) to establish the runtime configuration.

Second, the LLM client factory in tradingagents/llm_clients/factory.py creates provider-specific wrappers for OpenAI, Anthropic, Google, xAI, OpenRouter, and Ollama. Provider-specific parameters like reasoning_effort, thinking_level, and effort inject into client kwargs through the _get_provider_kwargs method.

Third, tool nodes provide stateless data-access utilities. Abstract functions like get_stock_data and get_indicators reside in tradingagents/agents/utils/agent_utils.py, while specific implementations such as the LangChain @tool for OHLCV data fetching live in tradingagents/agents/utils/core_stock_tools.py. The TradingAgentsGraph._create_tool_nodes() method (in tradingagents/graph/trading_graph.py) wires these into the execution graph.

Fourth, graph components instantiate within TradingAgentsGraph.__init__. The ConditionalLogic class decides when debates end, the Propagator creates initial state and supplies graph arguments, the Reflector updates memories after execution, and the SignalProcessor extracts the final trade decision.

Fifth, data routing occurs through tradingagents/dataflows/interface.py, which dispatches tool calls to configured vendors like yfinance or alpha_vantage based on DEFAULT_CONFIG["data_vendors"] settings.

Sixth, the message buffer and UI layer manages the live terminal experience. The MessageBuffer class (defined in cli/main.py) stores messages, tool calls, and incremental report sections. Rich-driven layout functions create_layout and update_display render progress bars, recent messages, and current analyst reports in real time.

Seventh, the execution orchestrator run_analysis() coordinates the complete workflow. It calls get_user_selections() from cli/utils.py to collect parameters, builds a TradingAgentsGraph with selected analysts, and streams the graph via graph.stream while updating the MessageBuffer and UI after each chunk.

Launching the Interactive Terminal

Install the package and launch the interface using the entry point defined in pyproject.toml:


# Install from source

pip install .

# Launch the interactive interface  

tradingagents

# Or run directly from source

python -m cli.main analyze

The CLI sequentially prompts for:

  • Ticker symbol (e.g., AAPL, NVDA, 7203.T)
  • Analysis date in YYYY-MM-DD format
  • Analyst agents (Market, Social, News, Fundamentals)
  • Research depth (shallow, medium, deep)
  • LLM provider and models (quick-thinking and deep-thinking configurations)

During execution, the Rich-based dashboard displays agent status, recent messages, and current report sections as the multi-agent debate progresses through research, trading plan creation, risk analysis, and portfolio management stages.

Configuring the Analysis Pipeline

The configuration system merges user selections with defaults through DEFAULT_CONFIG in tradingagents/default_config.py. This dictionary controls data vendor selection, LLM model choices, and output directories.

When building the graph programmatically, override specific values before instantiation:

from tradingagents.graph.trading_graph import TradingAgentsGraph
from tradingagents.default_config import DEFAULT_CONFIG

# Customize configuration

config = DEFAULT_CONFIG.copy()
config["data_vendors"]["fundamental_data"] = "alpha_vantage"
config["llm_provider"] = "openai"
config["quick_think_llm"] = "gpt-5-mini"
config["deep_think_llm"] = "gpt-5.4"

# Create graph with selected analysts only

graph = TradingAgentsGraph(
    selected_analysts=["market", "fundamentals"],
    debug=False,
    config=config,
)

The selected_analysts parameter accepts a list of strings corresponding to the Analyst enum defined in cli/models.py. The graph initializes tool nodes through _create_tool_nodes() and configures the debate workflow based on these selections.

The Multi-Agent Graph Structure

The TradingAgentsGraph class in tradingagents/graph/trading_graph.py encapsulates the multi-agent simulation. Each agent writes analysis sections into MessageBuffer.report_sections, which the CLI renders in real time.

The standard workflow follows this sequence:

  1. Analyst agents produce *_report sections using data from tool nodes
  2. Research agents debate the investment plan
  3. Trader agent creates a structured trading plan
  4. Risk analysts evaluate potential downsides
  5. Portfolio manager delivers the final decision

Tool nodes remain stateless functions that delegate to the data-vendor dispatcher. The vendor selection in DEFAULT_CONFIG["data_vendors"] determines whether yfinance or alpha_vantage provides the underlying market data.

Programmatic Usage Without the Terminal

Bypass the interactive CLI by invoking the graph directly through Python. The propagate() method returns the complete internal state and final decision:

from tradingagents.graph.trading_graph import TradingAgentsGraph
from tradingagents.default_config import DEFAULT_CONFIG

# Initialize with default or custom config

graph = TradingAgentsGraph(config=DEFAULT_CONFIG)

# Execute analysis for specific ticker and date

final_state, decision = graph.propagate("NVDA", "2026-01-15")
print("Final trade decision:", decision)

The propagate method accepts a ticker string and date string, executing the full agent workflow without terminal interaction. Access intermediate reports through the final_state dictionary containing all analysis sections generated during the run.

Saving and Accessing Reports

The CLI automatically persists reports via save_report_to_disk() in cli/main.py. To manually save results when using the programmatic interface:

from pathlib import Path
from tradingagents.graph.trading_graph import TradingAgentsGraph
from tradingagents.default_config import DEFAULT_CONFIG
from cli.main import save_report_to_disk

graph = TradingAgentsGraph(config=DEFAULT_CONFIG)
state, _ = graph.propagate("SPY", "2025-12-31")

# Create output directory

report_path = Path("./my_reports/SPY_2025-12-31")
report_path.mkdir(parents=True, exist_ok=True)

# Persist markdown report

report_file = save_report_to_disk(state, "SPY", report_path)
print(f"Report written to {report_file}")

This generates a multi-section markdown file containing the complete analysis from all agent stages.

Summary

  • The CLI interface in cli/main.py serves as the primary entry point, orchestrating user input collection and real-time dashboard rendering through run_analysis().
  • Configuration management merges user selections with DEFAULT_CONFIG and initializes provider-specific LLM clients through the factory pattern in tradingagents/llm_clients/factory.py.
  • Tool nodes abstract data access through tradingagents/agents/utils/agent_utils.py and tradingagents/agents/utils/core_stock_tools.py, routing requests to vendors like yfinance or alpha_vantage via tradingagents/dataflows/interface.py.
  • The TradingAgentsGraph class manages the multi-agent debate workflow, instantiating ConditionalLogic, Propagator, Reflector, and SignalProcessor components to handle state transitions and final decision extraction.
  • Both interactive and programmatic execution support report persistence through save_report_to_disk(), generating detailed markdown documentation of the analysis pipeline.

Frequently Asked Questions

How do I select specific analyst agents when running TradingAgents interactively?

The CLI prompts you to choose analysts during the get_user_selections() workflow defined in cli/utils.py. You can select from Market, Social, News, and Fundamentals analysts, which correspond to the Analyst enum in cli/models.py. Alternatively, programmatic users pass a list like ["market", "fundamentals"] to the selected_analysts parameter when constructing TradingAgentsGraph.

What LLM providers does TradingAgents support, and how do I configure them?

The framework supports OpenAI, Anthropic, Google, xAI, OpenRouter, and Ollama through the factory pattern in tradingagents/llm_clients/factory.py. Configure your preferred provider by setting the llm_provider key in your configuration dictionary, along with model selections for quick_think_llm and deep_think_llm. The factory automatically injects provider-specific parameters such as reasoning_effort or thinking_level based on the selected backend.

Where does TradingAgents store the generated analysis reports?

By default, the run_analysis() function in cli/main.py persists reports to the directory specified in DEFAULT_CONFIG. When using the library programmatically, import save_report_to_disk from cli/main.py to write the multi-section markdown report to your chosen Path. The function returns the absolute path to the generated file, which contains formatted sections from each agent in the analysis pipeline.

Can I use my own data sources instead of yfinance or Alpha Vantage?

Yes. The tradingagents/dataflows/interface.py file implements the data-vendor dispatcher that routes tool calls. Modify DEFAULT_CONFIG["data_vendors"] to map data types (such as fundamental_data or price_data) to custom vendor identifiers. You would then extend the dispatch logic in interface.py to handle your custom vendor, or modify the tool functions in tradingagents/agents/utils/agent_utils.py to call your proprietary data sources directly.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →