Content
# TradingAgents-MCPmode
TradingAgents-MCPmode multi-agent trading analysis system based on MCP tools
## 🌟 Project Overview
**TradingAgents-MCPmode** is an innovative multi-agent trading analysis system that integrates the Model Context Protocol (MCP) tool to achieve intelligent stock analysis and trading decision-making processes. The system provides comprehensive market analysis, investment advice, and risk management through the collaboration of 15 specialized intelligent agents.
### 🎯 Core Features
- **🤖 Multi-Agent Collaboration**: 15 specialized intelligent agents collaborate
- **⚡ Parallel Processing**: The analyst team adopts a parallel architecture, significantly improving analysis efficiency
- **🔧 MCP Tool Integration**: Supports external data sources and real-time information acquisition
- **📊 Comprehensive Analysis**: Seven-dimensional analysis of company overview, market, sentiment, news, fundamentals, shareholder structure, and product business
- **💭 Intelligent Debate**: Bullish/bearish researcher debate mechanism, configurable debate rounds
- **⚠️ Risk Management**: Three-layer risk analysis and management decision-making, supporting dynamic risk debate
- **🎛️ Agent Control**: The front-end can dynamically enable/disable specific agents, flexibly customizing the workflow
- **🌀 Debate Round Configuration**: The front-end can set investment and risk debate rounds in real-time, precisely controlling the depth of analysis
- **🔧 Flexible Configuration**: Control agent MCP permissions through environment variables
- **🌍 Multi-Market Support**: US stocks (US), A-shares (CN), Hong Kong stocks (HK)
- **🗣️ Natural Language**: Supports natural language queries without specifying market and date
- **📈 Real-Time Decision-Making**: Trading recommendations based on the latest data
- **🌐 Web Front-End**: Complete Streamlit Web interface, supporting real-time analysis and historical management
## 🏗️ System Architecture
### Agent Organizational Structure
```
┌─────────────────────────────────────────────────────────────┐
│ TradingAgents-MCPmode │
├─────────────────────────────────────────────────────────────┤
│ 📊 Analysts - Parallel Execution │
│ ├── CompanyOverviewAnalyst │
│ ├── MarketAnalyst ┐ │
│ ├── SentimentAnalyst │ Parallel Processing │
│ ├── NewsAnalyst │ 6 Analysts │
│ ├── FundamentalsAnalyst│ Execute Simultaneously │
│ ├── ShareholderAnalyst │ │
│ └── ProductAnalyst ┘ │
├─────────────────────────────────────────────────────────────┤
│ 🔬 Researchers │
│ ├── BullResearcher │
│ └── BearResearcher │
├─────────────────────────────────────────────────────────────┤
│ 👔 Managers │
│ ├── ResearchManager │
│ └── Trader │
├─────────────────────────────────────────────────────────────┤
│ ⚠️ Risk Management │
│ ├── AggressiveRiskAnalyst │
│ ├── SafeRiskAnalyst │
│ ├── NeutralRiskAnalyst │
│ └── RiskManager │
└─────────────────────────────────────────────────────────────┘
```
### 🚀 Parallelized Workflow
```mermaid
graph TD
%% 用户输入
USER[👤 用户输入<br/>user_query]
%% 第0阶段:公司概述分析师
A0[🏢 公司概述分析师<br/>📥 输入:user_query<br/>📤 输出:company_details + company_overview_report]
%% 第1阶段:分析师并行节点
PARALLEL[⚡ 分析师并行节点<br/>📥 输入:user_query + company_details<br/>🔄 并发执行6个分析师<br/>📤 输出:全部6个分析报告]
%% 并行执行的6个分析师
A1[🔍 市场分析师]
A2[😊 情绪分析师]
A3[📰 新闻分析师]
A4[📊 基本面分析师]
A5[👥 股东分析师]
A6[🏭 产品分析师]
%% 第2阶段:研究员辩论
B1[📈 看涨研究员<br/>📥 输入:user_query + 全部7个分析师报告<br/>📤 输出:看涨论证 + 辩论历史]
B2[📉 看跌研究员<br/>📥 输入:user_query + 全部7个分析师报告 + 辩论历史<br/>📤 输出:看跌论证 + 辩论历史]
%% 第3阶段:管理层
C1[🎯 研究经理<br/>📥 输入:user_query + 全部7个分析师报告 + 完整辩论历史<br/>📤 输出:investment_plan]
C2[💰 交易员<br/>📥 输入:user_query + 全部7个分析师报告 + 辩论历史 + investment_plan<br/>📤 输出:trader_investment_plan]
%% 第4阶段:风险管理团队
D1[🔥 激进风险分析师<br/>📥 输入:全部信息<br/>📤 输出:激进风险观点 + 风险辩论历史]
D2[🛡️ 保守风险分析师<br/>📥 输入:全部信息 + 风险辩论历史<br/>📤 输出:保守风险观点 + 风险辩论历史]
D3[⚖️ 中性风险分析师<br/>📥 输入:全部信息 + 风险辩论历史<br/>📤 输出:中性风险观点 + 风险辩论历史]
D4[🎯 风险经理<br/>📥 输入:全部信息 + 完整风险辩论历史<br/>📤 输出:final_trade_decision]
%% 主要流程连接
USER --> A0
A0 --> PARALLEL
PARALLEL --> B1
B1 --> B2
B2 -.->|辩论循环| B1
B1 --> C1
C1 --> C2
C2 --> D1
D1 -.->|风险辩论循环| D2
D2 -.->|风险辩论循环| D3
D3 -.->|风险辩论循环| D1
D1 --> D4
D2 --> D4
D3 --> D4
%% 并行节点内部连接(虚线表示并发)
PARALLEL -.-> A1
PARALLEL -.-> A2
PARALLEL -.-> A3
PARALLEL -.-> A4
PARALLEL -.-> A5
PARALLEL -.-> A6
%% 样式定义
style USER fill:#f9f9f9,stroke:#333,stroke-width:2px
style A0 fill:#e1f5fe,stroke:#0277bd
style PARALLEL fill:#fff3e0,stroke:#ff8f00,stroke-width:3px
style A1 fill:#e8f5e8,stroke:#4caf50
style A2 fill:#e8f5e8,stroke:#4caf50
style A3 fill:#e8f5e8,stroke:#4caf50
style A4 fill:#e8f5e8,stroke:#4caf50
style A5 fill:#e8f5e8,stroke:#4caf50
style A6 fill:#e8f5e8,stroke:#4caf50
style B1 fill:#e3f2fd,stroke:#1976d2
style B2 fill:#e3f2fd,stroke:#1976d2
style C1 fill:#fff3e0,stroke:#ef6c00
style C2 fill:#fff3e0,stroke:#ef6c00
style D1 fill:#fce4ec,stroke:#c2185b
style D2 fill:#fce4ec,stroke:#c2185b
style D3 fill:#fce4ec,stroke:#c2185b
style D4 fill:#fce4ec,stroke:#c2185b
```
### ⚡ Parallelization Advantages
1. **Significantly Improved Efficiency**: 6 analysts execute concurrently, and the total time is close to the execution time of the slowest analyst
2. **Resource Optimization**: Fully utilize system resources and avoid serial waiting
3. **Data Consistency**: Each analyst uses a deep copy state to avoid concurrent conflicts
4. **Result Merging**: Intelligently merge the reports and execution history of each analyst
#### Online Experience (Public Network Address)
- Experience Address: `http://47.79.147.241:8501`
- Description: Open to the public for free for function experience and demonstration.
- Note: Please use it civilly and do not conduct any form of attack, stress test, or malicious access behavior to avoid affecting service stability.
<img width="1920" height="1080" alt="image" src="https://github.com/user-attachments/assets/c557e15a-de1e-4dbe-b619-b8f32a2a91c2" />
## 🚀 Quick Start
### Environment Requirements
- Python 3.8+
- Supported operating systems: Windows, macOS, Linux
### Installation Steps
1. **Clone the Project**
```bash
git clone https://github.com/guangxiangdebizi/TradingAgents-MCPmode.git
cd TradingAgents-MCPmode
```
2. **Install Dependencies**
```bash
pip install -r requirements.txt
```
3. **Configure Environment Variables**
```bash
cp env.example .env
# Edit the .env file to configure your API keys and workflow parameters
```
4. **Configure MCP Tool**
```bash
# Edit the mcp_config.json file to configure the MCP server
```
### 🌐 Web Front-End Usage
**Recommended Usage** - Interact through the Web interface:
```bash
streamlit run web_app.py
```
Then visit in your browser: `http://localhost:8501`
<img width="1920" height="1080" alt="image" src="https://github.com/user-attachments/assets/280599ee-c00a-4c8c-b61f-c786e43cc6d4" />
#### Web Front-End Features
- **🏠 Home**: System overview and quick navigation
- **⚙️ System Configuration**: Online editing of .env and MCP configuration
- **🔍 Real-Time Analysis**: Enter queries and monitor analysis progress in real-time
- **🤖 Agent Control**: Dynamically enable/disable specific agents, checkbox interface organized by team
- **🌀 Debate Configuration**: Real-time adjustment of investment and risk debate rounds, precisely controlling the depth of analysis
- **📊 Agent Page**: View detailed analysis results of each agent by team
- **📚 Historical Reports**: Manage historical sessions, support Markdown, PDF, DOCX export
#### 🎛️ Front-End Agent Control Features
**Agent Enablement Control**:
- ✅ **Group Management**: Organized by four teams: analysts, researchers, management, and risk management
- ✅ **Real-Time Selection**: Checkbox interface, supporting quick operations for selecting all/none
- ✅ **Dynamic Counting**: Real-time display of the number of enabled agents (e.g., Enabled 12/15)
- ✅ **Intelligent Skipping**: Disabled agents are automatically skipped, without affecting workflow continuity
**Debate Round Configuration**:
- 🔄 **Investment Debate**: Slider settings for bullish/bearish researcher debate rounds (each round = each side speaks once)
- ⚖️ **Risk Debate**: Slider settings for aggressive/conservative/neutral risk analyst debate rounds (each round = each side speaks once)
- 📊 **Real-Time Preview**: Display current settings and expected number of speeches
- 🚀 **Automatic Application**: Automatically apply front-end settings when starting analysis, without manual confirmation
### 💻 Command Line Usage
If you prefer the command line:
```bash
python main.py -c "Analyze Apple's stock"
```
#### Interactive Mode
```bash
python main.py
```
Then enter your query as prompted, for example:
- "Analyze Tesla stock"
- "Analyze 600036 China Merchants Bank for me"
- "Analyze the investment value of NVDA"
## 📊 Data Flow Mechanism
### 🎯 Key Design Features
1. **company_details Placeholder System**
- 🏢 **Company Overview Analyst** first obtains basic company information
- 📥 **Only passed to the analyst team**: 6 professional analysts can obtain accurate company background
- 🚫 **Not passed to subsequent agents**: Researchers and subsequent agents focus on comprehensive evaluation of analysis reports
2. **Information Accumulation Effect**
- **Stage 0**: User query only
- **Stage 1**: User query + company details (parallel processing)
- **Stage 2**: User query + all 7 analyst reports
- **Stage 3**: User query + analyst reports + debate history + investment decisions
- **Stage 4**: User query + all information + risk opinions
3. **Dual Debate Mechanism**
- **Investment Debate**: Bullish ↔ Bearish researchers debate in a loop
- **Risk Debate**: Aggressive ↔ Conservative ↔ Neutral risk analysts debate in a loop
### 💡 Practical Application Example
**User Input**: "Analyze Tesla stock"
1. **🏢 Company Overview Analyst**: Obtain basic information such as Tesla Inc., TSLA, NASDAQ, and the electric vehicle industry
2. **⚡ Analyst Parallel Node**: 6 analysts simultaneously conduct professional analysis based on accurate "Tesla Inc." information
3. **📈 Bullish Researcher**: Synthesize all 7 professional analysis reports to construct a bullish investment argument for Tesla
4. **🎯 Risk Manager**: Make the final risk decision on Tesla investment based on all information and debate results
This design ensures **precise information transmission** and **gradual refinement**, allowing each agent to exert professional capabilities in the most suitable information environment!
## 🎯 Usage Examples
### 📱 Front-End Operation Example
**Scenario**: Quickly analyze Apple's stock, enable only core analysts, and set up simplified debates
1. **Start the System**:
```bash
streamlit run web_app.py
```
2. **Configure Agents** (expand in "🤖 Agents Enabled This Round"):
- ✅ Analyst Team: Select All (7 agents)
- ✅ Researcher Team: Select Bullish Researcher only
- ❌ Management: Select None (quick analysis)
- ❌ Risk Management: Select None (quick analysis)
- 📊 Display: Enabled 8/15
3. **Set Debate Rounds** (expand in "🌀 Debate Round Settings"):
- 🔄 Investment Debate Rounds: 1 round (only the bullish researcher speaks once)
- ⚖️ Risk Debate Rounds: 0 rounds (skip risk debate)
4. **Execute Analysis**:
- Input: "Analyze the investment value of Apple's stock"
- Click "🚀 Start Analysis"
- The system automatically applies the front-end settings and starts execution
5. **Expected Results**:
- ⚡ Quick Execution: Only 8 agents participate, significantly reducing analysis time
- 📊 Core Reports: Obtain 7 professional analyst reports
- 🎯 Investment Advice: The bullish researcher provides investment advice based on analyst reports
### 🎛️ Dynamic Configuration Advantages
- **🚀 Quick Experience**: Disable non-core agents to get analysis results in 1-2 minutes
- **🔬 In-Depth Analysis**: Enable all agents + multiple rounds of debate to get complete decision support
- **🎯 Customization**: Flexibly select agent combinations based on analysis needs
- **💡 Real-Time Adjustment**: No need to restart the service, adjust parameters in real-time on the front-end
## 🛠️ Configuration Instructions
### Environment Variable Configuration
Configure the following parameters in the `.env` file:
```env
# Large Model Configuration
OPENAI_API_KEY=your_openai_api_key
OPENAI_BASE_URL=https://api.openai.com/v1
MODEL_NAME=gpt-4
# Workflow Configuration
MAX_DEBATE_ROUNDS=1 # Default number of investment debate rounds (can be dynamically adjusted on the front-end)
MAX_RISK_DEBATE_ROUNDS=1 # Default number of risk debate rounds (can be dynamically adjusted on the front-end)
DEBUG_MODE=true # Debug mode, display detailed logs
VERBOSE_LOGGING=true # Detailed log output
# Agent MCP Permission Configuration
# Analyst Team - It is recommended to enable MCP to obtain real-time data
COMPANY_OVERVIEW_ANALYST_MCP=true
MARKET_ANALYST_MCP=true
SENTIMENT_ANALYST_MCP=true
NEWS_ANALYST_MCP=true
FUNDAMENTALS_ANALYST_MCP=true
SHAREHOLDER_ANALYST_MCP=true
PRODUCT_ANALYST_MCP=true
# Researcher/Management/Risk Team - It is recommended to turn off MCP to focus on comprehensive analysis
BULL_RESEARCHER_MCP=false
BEAR_RESEARCHER_MCP=false
RESEARCH_MANAGER_MCP=false
TRADER_MCP=false
AGGRESSIVE_RISK_ANALYST_MCP=false
SAFE_RISK_ANALYST_MCP=false
NEUTRAL_RISK_ANALYST_MCP=false
RISK_MANAGER_MCP=false
# Task Quantity Concurrency Limit
MAX_CONCURRENT_ANALYSIS=2 # Number of analysis tasks running simultaneously
```
> **💡 Tip**: The `MAX_DEBATE_ROUNDS` and `MAX_RISK_DEBATE_ROUNDS` in the environment variables are only default values. The actual runtime can be adjusted in real-time on the front-end. It is recommended to set it to 1 for a quick experience. If you need in-depth analysis, you can increase the number of rounds on the front-end.
### MCP Tool Configuration
Configure the MCP server in the `mcp_config.json` file:
```json
{
"mcpServers": {
"finance-mcp": {
"disabled": false,
"timeout": 600,
"transport": "streamable_http",
"url": "https://finvestai.top/mcp",
"headers": {
"X-Tushare-Token": "Your tushare token"
}
}
}
}
```
**Configuration Instructions**:
- `disabled`: Whether to disable the MCP server (false means enabled)
- `timeout`: Request timeout time (seconds), default is 600 seconds
- `transport`: Transport protocol, use `streamable_http`
- `url`: MCP server address `https://finvestai.top/mcp`
- `X-Tushare-Token`: Please replace with your real Tushare API Key
> **💡 Tip**: After modifying the configuration, please restart the application or hot reload the MCP client to make the configuration take effect.
## 📈 Performance Optimization
### Parallel Processing Advantages
- **Original Serial Architecture**: 6 analysts execute sequentially, and the total time = Σ(time of each analyst)
- **New Parallel Architecture**: 6 analysts execute concurrently, and the total time ≈ max(time of each analyst)
- **Performance Improvement**: Theoretically, the efficiency can be improved by 5-6 times, and the actual improvement depends on the time distribution of each analyst
### Resource Management
- Use deep copies to avoid state competition
- Intelligently merge execution history and tool call records
- Optimize memory usage and avoid state redundancy
## 🤝 Contribution Guide
Welcome to submit Issues and Pull Requests to improve the project!
## 📄 License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
---
**TradingAgents-MCPmode** - Let the AI agent team escort your investment decisions! 🚀📈
## 📬 Contact Information
- Email: `guangxiangdebizi@gmail.com`
- LinkedIn: [Xingyu Chen](https://www.linkedin.com/in/xingyu-chen-b5b3b0313/)
- Facebook: [Personal Homepage](https://www.facebook.com/profile.php?id=100072282093932)
- Bilibili: [Personal Space](https://space.bilibili.com/51239486?spm_id_from=333.1007.0.0)
Connection Info
You Might Also Like
valuecell
Valuecell is a Python project for efficient data management.
hexstrike-ai
HexStrike AI is an AI-powered MCP cybersecurity automation platform with 150+ tools.
AP2
AP2 provides code samples and demos for the Agent Payments Protocol.
boltmcp
BoltMCP: An enterprise-grade platform for creating, deploying, and managing...
vscode-mcp-server
A VS Code extension enabling MCP clients to code directly in VS Code with...
open-mcp
OpenMCP is a standard for converting web APIs into MCP servers and an open...