Research Debate Analyst
Groq-Powered Multi-Agent Debate Analysis
This project now includes a powerful stock analysis system using Groq LLMs with LangChain for multi-agent debates. The system provides fast, cost-effective analysis through intelligent agent debates.
π Features
- Multi-Agent Debate System: Bull vs Bear researchers debate investment thesis
- Risk Management Consensus: 3-way debate between conservative, neutral, and aggressive risk managers
- Fast Inference: Uses Groq's Llama 3.1 models (70B for deep thinking, 8B for quick thinking)
- Memory-Based Learning: Learns from past trading decisions using ChromaDB
- Flexible Data Sources: Integrates with yfinance, Alpha Vantage, and more
ποΈ Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Stock Analysis Request β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Market & News Analysts β
β (Gather data: technical, fundamental, news, social) β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Investment Debate β
β ββββββββββββββββ ββββββββββββββββ β
β β Bull β βββββ β Bear β β
β β Researcher β β Researcher β β
β ββββββββββββββββ ββββββββββββββββ β
β β β β
β ββββββββββ¬ββββββββββββββββ β
β βΌ β
β ββββββββββββββββββ β
β β Research β (Judge: BUY/SELL/HOLD) β
β β Manager β β
β ββββββββββ¬ββββββββ β
ββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Trader Decision β
β (Action: BUY/SELL/HOLD) β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Risk Management Debate β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β βConservativeβ β Neutral β βAggressiveβ β
β β Debator β β Debator β β Debator β β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β β β β
β ββββββββββββββΌββββββββββββββ β
β βΌ β
β ββββββββββββββββββββ β
β β Risk Manager β (Judge final risk level) β
β ββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββπ¦ Installation
Install Python Dependencies
cd agents/debate-analyst
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies (includes langchain-groq)
pip install -r requirements.txtConfigure Environment
The environment has been configured to use Groq by default:
Main Project .env (create this file):
GROQ_API_KEY=your_groq_api_key_here
NEXT_PUBLIC_DEBATE_ANALYST_URL=http://localhost:8001Debate-Analyst .env (create at agents/debate-analyst/.env):
GROQ_API_KEY=your_groq_api_key_here
LLM_PROVIDER=groq
DEEP_THINK_LLM=llama-3.1-70b-versatile
QUICK_THINK_LLM=llama-3.1-8b-instant
MAX_DEBATE_ROUNDS=2Default Configuration (agents/debate-analyst/tradingagents/default_config.py):
DEFAULT_CONFIG = {
"llm_provider": "groq",
"deep_think_llm": "llama-3.1-70b-versatile",
"quick_think_llm": "llama-3.1-8b-instant",
"max_debate_rounds": 2,
# ... other settings
}π¦ Running the Service
Start the Debate-Analyst API Server
cd agents/debate-analyst
source venv/bin/activate
python api_server.pyThe server will start on http://localhost:8001
Start the Next.js Application
# From project root
npm run devThe Next.js app will start on http://localhost:3000
π‘ API Usage
Using the Next.js API Endpoint
The new /api/groq-debate endpoint provides a simplified interface:
# Get API information
curl http://localhost:3000/api/groq-debate
# Analyze a stock
curl -X POST http://localhost:3000/api/groq-debate \
-H "Content-Type: application/json" \
-d '{
"symbol": "AAPL",
"date": "2024-12-11",
"max_debate_rounds": 2
}'Response Format
{
"success": true,
"symbol": "AAPL",
"date": "2024-12-11",
"analysis": {
"bull_arguments": [
"Strong fundamentals with consistent revenue growth...",
"Leading position in smartphone market with 50%+ profit share..."
],
"bear_arguments": [
"High valuation multiples compared to historical averages...",
"Increasing regulatory pressure in key markets..."
],
"risk_assessment": "Medium risk with controlled position sizing recommended",
"final_decision": "BUY with 60% confidence",
"confidence_level": "Medium-High",
"reasoning": "The bull case is stronger based on fundamental analysis..."
},
"debate_history": [
{
"agent": "bull_researcher",
"message": "...",
"timestamp": "..."
}
]
}Using JavaScript/TypeScript
interface GroqDebateRequest {
symbol: string
date?: string
max_debate_rounds?: number
}
async function analyzeStock(symbol: string) {
const response = await fetch('/api/groq-debate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
symbol,
date: new Date().toISOString().split('T')[0],
max_debate_rounds: 2
})
})
const result = await response.json()
if (result.success) {
console.log('Bull Arguments:', result.analysis.bull_arguments)
console.log('Bear Arguments:', result.analysis.bear_arguments)
console.log('Final Decision:', result.analysis.final_decision)
console.log('Reasoning:', result.analysis.reasoning)
}
return result
}
// Usage
analyzeStock('AAPL').then(result => {
console.log('Analysis complete:', result)
})Direct API Server Usage
You can also call the debate-analyst service directly:
# Direct call to debate-analyst
curl -X POST http://localhost:8001/analyze \
-H "Content-Type: application/json" \
-d '{
"symbol": "AAPL",
"date": "2024-12-11"
}'π§ How It Works
Data Collection Phase
- Market Analyst: Gathers OHLCV data, technical indicators
- News Analyst: Collects and analyzes recent news sentiment
- Social Media Analyst: Analyzes social sentiment (optional)
- Fundamentals Analyst: Reviews financial statements and metrics
Investment Debate Phase
- Bull Researcher: Presents optimistic case based on data
- Bear Researcher: Presents pessimistic case and risks
- Multiple Rounds: Agents debate back and forth (default: 2 rounds)
- Research Manager: Acts as judge, decides BUY/SELL/HOLD
Trading Decision
- Trader Agent: Makes action decision based on research manager's judgment
- Considers risk appetite, market conditions, portfolio context
Risk Management Debate
- Conservative Debator: Argues for minimal risk exposure
- Neutral Debator: Balanced risk perspective
- Aggressive Debator: Higher risk for higher returns
- Risk Manager: Final judgment on position size and risk level
Memory & Learning
- All decisions are stored in ChromaDB vector database
- Future analyses retrieve similar past situations
- Agents learn from past successes and failures