TradingAgents: Multi-Agents LLM Financial Trading Framework
Project description
๐ TradingAgents is a multi-agent LLM financial trading framework that leverages large language models to simulate analyst teams, research debates, and portfolio management decisions for stock trading analysis.
Other Languages: English | ็น้ซไธญๆ | ็ฎไฝไธญๆ
โจ Highlights
- Built on LangGraph for robust multi-agent orchestration
- Multi-agent architecture: Analyst Team โ Research Team โ Trader โ Risk Management โ Portfolio Management
- Powered by
langchain.chat_models.init_chat_model; supports any provider keyed via an explicitllm_providerfield plus a model name (OpenAI, Anthropic, Google Gemini, xAI (Grok), OpenRouter, Ollama, HuggingFace, LiteLLM) - Unified
reasoning_effortknob (low / medium / high / xhigh / max) mapped per provider to native parameters (Anthropiceffort, OpenAIreasoning_effort, Googlethinking_level) - Market data powered by
yfinancefor OHLCV, fundamentals, technical indicators, news, and insider transactions - Pydantic-based configuration with strict typing and validation
- Analysis results automatically saved to
results/with organized subfolders - Modern
src/layout with full type-annotated code - Fast dependency management via
uv - Pre-commit suite: ruff, mdformat, codespell, mypy, uv hooks
- Pytest with coverage; MkDocs Material documentation
๐ Quick Start
git clone https://github.com/Mai0313/TradingAgents.git
cd TradingAgents
make uv-install # Install uv (only needed once)
uv sync # Install dependencies
cp .env.example .env # Configure your API keys
Configure API Keys
Edit .env and set your LLM provider keys:
# LLM Providers (set the one you use)
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=AIza...
XAI_API_KEY=...
OPENROUTER_API_KEY=...
Usage
from tradingagents.config import TradingAgentsConfig
from tradingagents.graph.trading_graph import TradingAgentsGraph
config = TradingAgentsConfig(
llm_provider="openai",
deep_think_llm="gpt-5",
quick_think_llm="gpt-5-mini",
max_debate_rounds=1,
max_risk_discuss_rounds=1,
max_recur_limit=100,
reasoning_effort="medium",
)
ta = TradingAgentsGraph(debug=True, config=config)
_, decision = ta.propagate("NVDA", "2024-05-10")
print(decision)
llm_provider is one of the langchain.chat_models.init_chat_model registry keys (openai, anthropic, google_genai, xai, openrouter, ollama, huggingface, litellm); deep_think_llm / quick_think_llm take the model name as accepted by that provider (gpt-5, claude-sonnet-4-6, gemini-3-pro-preview, grok-4, ...).
๐ Project Structure
src/
โโโ tradingagents/
โโโ agents/ # Agent implementations
โ โโโ analysts/ # Market, News, Social, Fundamentals analysts
โ โโโ managers/ # Research & Portfolio managers
โ โโโ researchers/ # Bull & Bear researchers
โ โโโ risk_mgmt/ # Risk management agents
โ โโโ trader/ # Trader agent
โ โโโ utils/ # Shared agent utilities
โโโ dataflows/ # Data ingestion via yfinance
โโโ graph/ # LangGraph trading graph setup
โโโ llm.py # Chat model construction (init_chat_model wrapper + reasoning_effort mapping)
โโโ config.py # TradingAgentsConfig schema + global singleton
โโโ cli.py # Entry point
๐ค Agent Workflow
TradingAgents orchestrates 12 LLM agents plus 2 supporting components through a LangGraph StateGraph. Every run goes through 4 sequential phases, and the state (reports, debate transcripts, trade decisions) is persisted through a Pydantic AgentState shared across all nodes.
Phase 1 โ Analyst Team (Data Collection)
Four analysts run in sequence. Each analyst has its LLM bound to a specific set of yfinance-backed @tool functions, and loops with its own ToolNode until no more tool calls are emitted. Between analysts a Msg Clear node resets the conversation history (emitting RemoveMessage + a HumanMessage("Continue") placeholder for Anthropic compatibility).
| Analyst | LLM-bound tools | Writes to state |
|---|---|---|
| Market Analyst | get_stock_data, get_indicators |
market_report |
| Social Media Analyst | get_news |
sentiment_report |
| News Analyst | get_news, get_global_news |
news_report |
| Fundamentals Analyst | get_fundamentals, get_balance_sheet, get_cashflow, get_income_statement |
fundamentals_report |
Supported technical indicators (selected by the Market Analyst, up to 8 per run): close_50_sma, close_200_sma, close_10_ema, macd, macds, macdh, rsi, boll, boll_ub, boll_lb, atr, vwma.
Phase 2 โ Research Debate
- Bull Researcher and Bear Researcher debate for
max_debate_roundsrounds (default: 1 round each), taking turns based on who spoke last. Each researcher retrieves top-k BM25 matches from its ownFinancialSituationMemorybefore arguing. - Termination:
count >= 2 * max_debate_roundsroutes the graph to Research Manager (deep-thinking LLM), which evaluates the full debate, produces theinvestment_plan, and populatesinvestment_debate_state.judge_decision.
Phase 3 โ Trader
Trader (quick-thinking LLM) consumes investment_plan plus the top-k trader_memory matches and produces trader_investment_plan. Its output must end with FINAL TRANSACTION PROPOSAL: **BUY/HOLD/SELL**.
Phase 4 โ Risk Control Debate
Three debators rotate in a fixed order โ Aggressive โ Conservative โ Neutral โ Aggressive โ โฆ โ for max_risk_discuss_rounds rounds (default: 1 round per stance). Termination: count >= 3 * max_risk_discuss_rounds routes to the Risk Judge (deep-thinking LLM via create_risk_manager), which revises the trader's plan and writes the final_trade_decision. A lightweight SignalProcessor LLM then extracts the canonical BUY / SELL / HOLD token from that natural-language decision.
Supporting components
- FinancialSituationMemory โ BM25Okapi-backed per-agent memory (5 instances: bull, bear, trader, invest_judge, risk_manager). Purely lexical, no external embeddings API required.
- Reflector โ After the trade outcome is known,
TradingAgentsGraph.reflect_and_remember(returns_losses)runs post-trade reflection against each of the 5 memories so future runs can learn from past decisions.
Flow Diagram
START
โ
โผ
[Market Analyst โ tools_market] โ Msg Clear
โ
โผ
[Social Analyst โ tools_social] โ Msg Clear
โ
โผ
[News Analyst โ tools_news] โ Msg Clear
โ
โผ
[Fundamentals Analyst โ tools_fundamentals] โ Msg Clear
โ
โผ
[Bull Researcher โ Bear Researcher] ร max_debate_rounds
โ
โผ
Research Manager โ Trader
โ
โผ
[Aggressive โ Conservative โ Neutral] ร max_risk_discuss_rounds
โ
โผ
Risk Judge โ SignalProcessor โ END
Per-run logs are written to results/<TICKER>/TradingAgentsStrategy_logs/full_states_log_<DATE>.json (the path resolves from TradingAgentsConfig.results_dir, which defaults to ./results).
๐ค Contributing
For development instructions including documentation, testing, and Docker services, please see CONTRIBUTING.md.
- Open issues/PRs
- Follow the coding style (ruff, type hints)
- Use Conventional Commit messages and descriptive PR titles
๐ License
MIT โ see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tradingagents-0.1.1.tar.gz.
File metadata
- Download URL: tradingagents-0.1.1.tar.gz
- Upload date:
- Size: 334.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
183e87f37a7c3f4f223c1f56a51e005e5b1c020db4ecbe06b43c02f4e0788b98
|
|
| MD5 |
c7c5bd1d291212f9d4bae828299c1580
|
|
| BLAKE2b-256 |
2ac0a35bd7c4464b9c9b837235f73e4119d3c431ac3c3727a9f62885cd7fde70
|
File details
Details for the file tradingagents-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tradingagents-0.1.1-py3-none-any.whl
- Upload date:
- Size: 62.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3601a3e0fbd754c50496c498248e07a006c8d8951ddcbad1970e80addb44251a
|
|
| MD5 |
ef086bd7989d77b1f95e93039d3a57d8
|
|
| BLAKE2b-256 |
3c4008e86243b755900ee337af4905c2c23087fd89154191bcf32d1557485821
|