How vignesh-codes/tradingagents works
Purpose and entry points
TradingAgents is a Python, LangGraph-based multi-agent framework that produces simulated trading decisions from market data and LLM reasoning. Primary interactive entry point is cli/main.py; package/programmatic use centers on tradingagents/graph/trading_graph.py and is demonstrated by main.py. Runtime defaults are defined in tradingagents/default_config.py.
Orchestration graph
TradingAgentsGraph constructs and propagates the workflow, carrying ticker, date, reports, debate artifacts, and final decision through LangGraph nodes. Graph setup, routing/conditional progression, and inter-agent propagation are separated in:
• tradingagents/graph/trading_graph.py
• tradingagents/graph/setup.py
• tradingagents/graph/conditional_logic.py
• tradingagents/graph/propagation.py
Market-data boundary
Agent-facing tools abstract financial-data retrieval and indicator computation. The dataflow layer supports Alpha Vantage and Yahoo Finance, isolating provider-specific API calls from agent reasoning:
• tradingagents/dataflows/interface.py
• tradingagents/dataflows/alpha_vantage.py
• tradingagents/dataflows/y_finance.py
• tradingagents/agents/utils/core_stock_tools.py
• tradingagents/agents/utils/technical_indicators_tools.py
Alpha Vantage requires its API key; Yahoo Finance is another market/news source. Inputs are ticker and analysis date, with tools supplying fundamentals, prices, technicals, and news/social context.
Analyst stage
Specialist LLM agents generate independent reports on fundamentals, market/technical signals, news, and social sentiment. They are grounded by data tools and return artifacts into shared graph state:
• tradingagents/agents/analysts/fundamentals_analyst.py
• tradingagents/agents/analysts/market_analyst.py
• tradingagents/agents/analysts/news_analyst.py
• tradingagents/agents/analysts/social_media_analyst.py
Research, trade, and risk decision stages
Bull and bear researchers debate the analyst evidence; the research manager synthesizes that work. The trader proposes a transaction, then risk debaters provide aggressive, conservative, and neutral views before the portfolio manager approves or rejects the outcome:
• tradingagents/agents/researchers/bull_researcher.py
• tradingagents/agents/researchers/bear_researcher.py
• tradingagents/agents/managers/research_manager.py
• tradingagents/agents/trader/trader.py
• tradingagents/agents/risk_mgmt/
• tradingagents/agents/managers/portfolio_manager.py
Structured schemas and serialization form the important boundary between free-form model output and reliable downstream graph decisions: tradingagents/agents/schemas.py, tradingagents/agents/utils/structured.py.
LLM provider boundary
A client factory and model catalog normalize calls across OpenAI, Google, Anthropic, xAI-compatible providers, DeepSeek, Qwen, GLM, OpenRouter, Ollama, and Azure. Provider credentials are environment-driven, including enterprise settings:
• tradingagents/llm_clients/factory.py
• tradingagents/llm_clients/base_client.py
• tradingagents/llm_clients/model_catalog.py
• tradingagents/llm_clients/openai_client.py
• tradingagents/llm_clients/azure_client.py
Persistence, recovery, and deployment
Completed decisions feed a persistent memory/reflection loop, allowing later same-ticker and cross-ticker context to influence the portfolio-manager prompt. Optional per-ticker SQLite checkpoints persist LangGraph state after nodes and support interrupted-run resume:
• tradingagents/agents/utils/memory.py
• tradingagents/graph/reflection.py
• tradingagents/graph/checkpointer.py
The system runs locally as Python or in Docker via Dockerfile and docker-compose.yml; Docker Compose also supports an Ollama profile for local models.
Main entry points: trading_graph.py TradingAgentsGraph · factory.py LLM client factory · fundamentals_analyst.py Specialist analysts · portfolio_manager.py Portfolio manager
Components 21
Entry points
- CLI
cli/main.py - Programmatic API
main.py - Runtime defaults
tradingagents/default_config.py
LangGraph workflow
- TradingAgentsGraph · Carries ticker, reports, debates, and final decision in shared state.
tradingagents/graph/trading_graph.py - Graph setup
tradingagents/graph/setup.py - Conditional routing
tradingagents/graph/conditional_logic.py - State propagation
tradingagents/graph/propagation.py
Market data
- Data tools interface
tradingagents/dataflows/interface.py - Alpha Vantage · API-key-backed market-data provider.
tradingagents/dataflows/alpha_vantage.py - Yahoo Finance
tradingagents/dataflows/y_finance.py - Stock and technical tools · Supplies fundamentals, prices, technicals, and context.
tradingagents/agents/utils/core_stock_tools.py
Decision agents
- Specialist analysts · Fundamentals, market, news, and social reports.
tradingagents/agents/analysts/fundamentals_analyst.py - Research debate · Bull and bear researchers assess analyst evidence.
tradingagents/agents/researchers/bull_researcher.py - Research manager
tradingagents/agents/managers/research_manager.py - Trader
tradingagents/agents/trader/trader.py - Risk debate · Aggressive, conservative, and neutral risk views.
- Portfolio manager · Approves or rejects the trade outcome.
tradingagents/agents/managers/portfolio_manager.py
Model and state services
- Structured output · Serializes model output into reliable graph decisions.
tradingagents/agents/schemas.py - LLM client factory · Normalizes provider and model selection.
tradingagents/llm_clients/factory.py - Memory and reflection · Feeds prior ticker context into portfolio decisions.
tradingagents/agents/utils/memory.py - SQLite checkpointer · Persists per-ticker state and enables resume.
tradingagents/graph/checkpointer.py
Connections 25
- CLI → TradingAgentsGraph: runs
- Programmatic API → TradingAgentsGraph: invokes
- Runtime defaults → TradingAgentsGraph: configures
- TradingAgentsGraph → Graph setup: builds
- Graph setup → Conditional routing: defines routes
- Conditional routing → State propagation: advances state
- TradingAgentsGraph → Specialist analysts: dispatches
- State propagation → Research debate: analyst evidence
- Research debate → Research manager: debate
- Research manager → Trader: research synthesis
- Trader → Risk debate: trade proposal
- Risk debate → Portfolio manager: risk views
- Data tools interface → Alpha Vantage: provider adapter
- Data tools interface → Yahoo Finance: provider adapter
- Stock and technical tools → Data tools interface: retrieves data
- Specialist analysts → Stock and technical tools: uses
- Specialist analysts → Structured output: reports
- Structured output → State propagation: validated artifacts
- LLM client factory → Specialist analysts: model calls
- LLM client factory → Research debate: model calls
- LLM client factory → Trader: model calls
- LLM client factory → Portfolio manager: model calls
- Portfolio manager → Memory and reflection: completed decisions
- Memory and reflection → Portfolio manager: prior context
- TradingAgentsGraph → SQLite checkpointer: checkpoint state