TradingAgents: Multi-Agents LLM Financial Trading Framework

repository·main·Indexed 13 days ago

https://github.com/tauricresearch/tradingagents

A multi-agent LLM-powered financial trading framework version 0.3.1 that simulates a professional trading firm. It utilizes specialized agent roles—including Analysts (Fundamentals, Sentiment, News, Technical), Researchers, Traders, and Risk Managers—to collaboratively perform market analysis and execute simulated trades. The framework supports a wide range of LLM providers including OpenAI, Google, Anthropic, DeepSeek, and local models via Ollama.

Tokens
10K
Snippets
27
Records
39
Agent score
100%

What's inside TradingAgents

  1. How the TradingAgents framework works

    main

    TradingAgents is a multi-agent LLM framework that simulates a real-world trading firm by decomposing complex trading tasks into specialized roles. The framework uses a collaborative process where different teams evaluate market conditions and engage in structured debates to reach optimal strategies.

    Core Agent Roles:

    • Analyst Team: Provides specialized market views.
      • Fundamentals Analyst: Evaluates financials and intrinsic value.
      • Sentiment Analyst: Gauges market mood via news, StockTwits, and Reddit.
      • News Analyst: Interprets macroeconomic indicators and global news.
      • Technical Analyst: Uses indicators like MACD and RSI to forecast price movements.
    • Researcher Team: Consists of bullish and bearish researchers who debate the Analyst Team's insights to balance potential gains against risks.
    • Trader Agent: Synthesizes reports from analysts and researchers to decide the timing and magnitude of trades.
    • Risk Management and Portfolio Manager: The Risk Management team assesses volatility and liquidity to adjust strategies, while the Portfolio Manager provides the final approval or rejection of transaction proposals before they are sent to the simulated exchange.
  2. Enable Checkpoint Resume and Persistence

    main

    TradingAgents provides two types of persistence:

    1. Decision Log: Automatically appends decisions to ~/.tradingagents/memory/trading_memory.md. This allows the Portfolio Manager to reflect on past performance. You can override this path using the TRADINGAGENTS_MEMORY_LOG_PATH environment variable.

    2. Checkpoint Resume: An opt-in feature that uses LangGraph to save state after each node. If a run is interrupted, it can resume from the last successful step. Checkpoints are stored in per-ticker SQLite databases at ~/.tradingagents/cache/checkpoints/<TICKER>.db. You can override the base directory with TRADINGAGENTS_CACHE_DIR.

    CLI Usage

    • Enable checkpoints for a run: tradingagents analyze --checkpoint
    • Clear all checkpoints before a run: tradingagents analyze --clear-checkpoints

    Python Usage

    Set checkpoint_enabled: True in your config dictionary.

    tradingagents analyze --checkpoint           # enable for this run
    tradingagents analyze --clear-checkpoints    # reset before running
    config = DEFAULT_CONFIG.copy()
    config["checkpoint_enabled"] = True
    ta = TradingAgentsGraph(config=config)
    _, decision = ta.propagate("NVDA", "2026-01-15")
  3. Improve Reproducibility in TradingAgents

    main

    Because TradingAgents is LLM-driven, outputs may vary due to non-deterministic sampling and live data changes. To increase reproducibility:

    1. Lower Temperature: Set temperature in your config or via the TRADINGAGENTS_TEMPERATURE environment variable. Note that many reasoning-first models may ignore this setting.
    2. Use Non-Reasoning Models: For tighter control, explicitly set a non-reasoning model for deep_think_llm or quick_think_llm using the Custom model ID option, as reasoning models vary more due to internal sampling.
    3. Pin Analysis Dates: Always provide a specific date to propagate() to keep the price and indicator window fixed.
    config = DEFAULT_CONFIG.copy()
    config["llm_provider"] = "openai"
    config["temperature"] = 0.0
    # For tighter reproducibility, set a non-reasoning deep/quick model explicitly
  4. Install TradingAgents via pip

    main

    To install TradingAgents locally, clone the repository, set up a Python 3.12 virtual environment, and install the package.

    # Clone the repository
    git clone https://github.com/TauricResearch/TradingAgents.git
    cd TradingAgents
    
    # Create and activate a virtual environment (using conda as an example)
    conda create -n tradingagents python=3.12
    conda activate tradingagents
    
    # Install the package and dependencies
    pip install .
    git clone https://github.com/TauricResearch/TradingAgents.git
    cd TradingAgents
    conda create -n tradingagents python=3.12
    conda activate tradingagents
    pip install .
  5. Use TradingAgents in Python

    main

    To integrate TradingAgents into your own Python applications, import TradingAgentsGraph from tradingagents.graph.trading_graph and initialize it with a configuration dictionary. The core method is .propagate(ticker, date), which performs the multi-agent analysis and returns a tuple containing the full state and the final decision.

    By default, you can use DEFAULT_CONFIG from tradingagents.default_config as a base for your configuration.

    from tradingagents.graph.trading_graph import TradingAgentsGraph
    from tradingagents.default_config import DEFAULT_CONFIG
    
    ta = TradingAgentsGraph(debug=True, config=DEFAULT_CONFIG.copy())
    
    # forward propagate: returns (state, decision)
    _, decision = ta.propagate("NVDA", "2026-01-15")
    print(decision)
  6. Run TradingAgents with Docker

    main

    You can run the framework using Docker. Ensure you have a .env file configured with your API keys before running.

    Standard run:

    cp .env.example .env  # add your API keys
    docker compose run --rm tradingagents

    Run with local models via Ollama:

    docker compose --profile ollama run --rm tradingagents-ollama
    cp .env.example .env
    docker compose run --rm tradingagents
    
    # For Ollama profile
    docker compose --profile ollama run --rm tradingagents-ollama
  7. Configure Data Vendors and Tool Overrides

    main

    TradingAgents uses a hierarchical configuration for data providers.

    1. Category-level (data_vendors): Sets the default vendor for a group of tools (e.g., all technical indicator tools use yfinance). You can provide an ordered list for fallback, such as "yfinance,alpha_vantage".
    2. Tool-level (tool_vendors): Provides specific overrides for individual tools that take precedence over the category default.

    Supported Vendors mentioned in config:

    • yfinance
    • alpha_vantage
    • fred (requires FRED_API_KEY)
    • polymarket (keyless)
    • default (uses all available vendors)
    # Example configuration for data vendors
    config = {
        "data_vendors": {
            "core_stock_apis": "yfinance",
            "macro_data": "fred",
        },
        "tool_vendors": {
            "get_stock_data": "alpha_vantage",  # Overrides core_stock_apis for this specific tool
        }
    }
  8. Configure LLM providers and models

    main

    You can customize the LLM behavior by modifying the configuration dictionary passed to TradingAgentsGraph.

    Supported providers include:

    • openai (and openai_compatible for vLLM, LM Studio, llama.cpp, etc.)
    • google
    • anthropic
    • deepseek
    • groq
    • ollama (for local models)
    • and others (xAI, Qwen, GLM, MiniMax, OpenRouter, Azure OpenAI)

    Key configuration keys:

    • llm_provider: The provider string.
    • deep_think_llm: The model used for complex reasoning tasks.
    • quick_think_llm: The model used for faster, simpler tasks.
    • max_debate_rounds: Number of rounds for agent debate.
    from tradingagents.graph.trading_graph import TradingAgentsGraph
    from tradingagents.default_config import DEFAULT_CONFIG
    
    config = DEFAULT_CONFIG.copy()
    config["llm_provider"] = "openai"
    config["deep_think_llm"] = "gpt-5.5"
    config["quick_think_llm"] = "gpt-5.4-mini"
    config["max_debate_rounds"] = 2
    
    ta = TradingAgentsGraph(debug=True, config=config)
  9. Configure LLM Providers and API Keys

    main

    TradingAgents supports various LLM providers. You can configure them by setting the corresponding environment variables.

    Common Provider Environment Variables:

    • OPENAI_API_KEY: OpenAI (GPT)
    • GOOGLE_API_KEY: Google (Gemini)
    • ANTHROPIC_API_KEY: Anthropic (Claude)
    • XAI_API_KEY: xAI (Grok)
    • DEEPSEEK_API_KEY: DeepSeek
    • DASHSCOPE_API_KEY: Qwen (International)
    • DASHSCOPE_CN_API_KEY: Qwen (China)
    • ZHIPU_API_KEY: GLM (International)
    • ZHIPU_CN_API_KEY: GLM (China)
    • MINIMAX_API_KEY: MiniMax (Global)
    • MINIMAX_CN_API_KEY: MiniMax (China)
    • OPENROUTER_API_KEY: OpenRouter
    • ALPHA_VANTAGE_API_KEY: Alpha Vantage

    Special Configurations:

    • AWS Bedrock: Install the extra via pip install ".[bedrock]". Set llm_provider: "bedrock", configure AWS credentials (env vars, ~/.aws/credentials, or IAM role), set AWS_DEFAULT_REGION, and provide a Bedrock model ID (e.g., us.anthropic.claude-opus-4-8-v1:0).
    • Ollama (Local): Set llm_provider: "ollama". The default endpoint is http://localhost:11434/v1. Use OLLAMA_BASE_URL for remote servers. You must ollama pull <name> the model first.
    • OpenAI-Compatible Servers (vLLM, LM Studio, etc.): Set llm_provider: "openai_compatible". Configure the endpoint using backend_url or TRADINGAGENTS_LLM_BACKEND_URL (e.g., http://localhost:8000/v1). Use OPENAI_COMPATIBLE_API_KEY if the endpoint requires authentication.
    • Azure OpenAI: Copy .env.enterprise.example to .env.enterprise and fill in your credentials.
  10. How configuration precedence works in the CLI

    main

    The CLI uses a hierarchical configuration system to resolve settings like research depth and checkpointing. This ensures that automated environments (via env vars) and manual overrides (via CLI flags) are respected correctly.

    Precedence Rules:

    1. CLI Flags: Explicitly provided flags (like --checkpoint) always win.
    2. Environment Variables: If a CLI flag is omitted, environment variables (e.g., TRADINGAGENTS_MAX_DEBATE_ROUNDS) take precedence over the interactive user selections.
    3. Interactive Selections: If no flag or environment variable is provided, the value chosen during the interactive CLI session is used.
    4. Defaults: If none of the above are present, the DEFAULT_CONFIG values are used.
  11. Configure TradingAgents via Environment Variables

    main

    The TradingAgents CLI follows an environment-precedence rule. If specific environment variables are set, the interactive questionnaire steps are skipped, and the values are pulled directly from the environment. This is useful for non-interactive automation.

    Supported Environment Variables:

    • TRADINGAGENTS_OUTPUT_LANGUAGE: Sets the language for reports and decisions.
    • TRADINGAGENTS_MAX_DEBATE_ROUNDS: Sets the number of debate rounds (affects research depth).
    • TRADINGAGENTS_MAX_RISK_ROUNDS: Sets the number of risk discussion rounds (affects research depth).
    • TRADINGAGENTS_LLM_PROVIDER: Sets the LLM provider (e.g., openai, anthropic, google, ollama).
    • TRADINGAGENTS_LLM_BACKEND_URL: Sets the custom endpoint for the provider.
    • TRADINGAGENTS_QUICK_THINK_LLM: Sets the model for shallow thinking.
    • TRADINGAGENTS_DEEP_THINK_LLM: Sets the model for deep thinking.
    • TRADINGAGENTS_GOOGLE_THINKING_LEVEL: Sets Gemini thinking mode.
    • TRADINGAGENTS_OPENAI_REASONING_EFFORT: Sets OpenAI reasoning effort.
    • TRADINGAGENTS_ANTHROPIC_EFFORT: Sets Claude effort level.
  12. Configure the Analyst Team and Research Depth

    main

    When running a trading analysis, you can interactively select the composition of your analyst team and the depth of the research process.

    Analyst Team

    Available analysts depend on the AssetType:

    • Stocks: Market, Sentiment, News, and Fundamentals analysts.
    • Crypto: Market, Sentiment, and News analysts (Fundamentals is excluded for crypto).

    Research Depth

    You can choose from three levels of depth:

    1. Shallow: Quick research, minimal debate/strategy rounds.
    2. Medium: Moderate debate and strategy discussion.
    3. Deep: Comprehensive research with in-depth debate and strategy discussion.