121 lines
3.6 KiB
Markdown
121 lines
3.6 KiB
Markdown
# TradingAgents Issue Analysis and Fix Plan
|
|
|
|
## 1. Issues Identified
|
|
|
|
### 1.1 Risk Judge Error
|
|
**Issue**: "I'm sorry, but I need the text from the paragraph or financial report to provide the investment decision."
|
|
**Root Cause**: The Risk Judge (risk_manager) is not receiving the proper input from the Risk Aggregator
|
|
**Location**: `tradingagents/agents/risk_management.py`
|
|
|
|
### 1.2 API Key Configuration
|
|
**Issue**: Invalid API key error (401)
|
|
**Root Cause**: Test placeholder API keys in .env file
|
|
**Impact**: All agents fail to execute
|
|
|
|
### 1.3 Missing Tool Wrapper
|
|
**Issue**: `tool_wrapper.py` was deleted but may still be referenced
|
|
**Location**: `tradingagents/graph/` directory
|
|
|
|
### 1.4 Performance Monitoring
|
|
**Issue**: No timing information for individual agents
|
|
**Impact**: Cannot identify performance bottlenecks
|
|
|
|
## 2. Fix Plan
|
|
|
|
### Priority 1: Fix Risk Judge Input Issue
|
|
|
|
1. **Analyze Risk Aggregator Output**
|
|
- Check what data is being passed from risk_aggregator to risk_manager
|
|
- Ensure the state contains required fields
|
|
|
|
2. **Fix Risk Manager Prompt**
|
|
- Update the prompt to handle cases where input might be incomplete
|
|
- Add validation for required input fields
|
|
|
|
### Priority 2: Add Timing and Logging
|
|
|
|
1. **Agent-Level Timing**
|
|
- Add timing decorators to each agent
|
|
- Log start/end times for each agent execution
|
|
|
|
2. **Tool-Level Timing**
|
|
- Track time spent in each tool call
|
|
- Identify slow API calls
|
|
|
|
### Priority 3: Code Organization
|
|
|
|
1. **Directory Structure**
|
|
```
|
|
backend/
|
|
├── tradingagents/
|
|
│ ├── agents/ # All agent implementations
|
|
│ ├── tools/ # Tool implementations by category
|
|
│ ├── graph/ # Graph setup and configuration
|
|
│ ├── models/ # Data models and schemas
|
|
│ ├── utils/ # Utility functions
|
|
│ └── config/ # Configuration management
|
|
├── tests/
|
|
│ ├── unit/ # Unit tests
|
|
│ ├── integration/ # Integration tests
|
|
│ └── e2e/ # End-to-end tests
|
|
└── scripts/ # Utility scripts
|
|
```
|
|
|
|
2. **Remove Redundant Files**
|
|
- Consolidate test files
|
|
- Remove duplicate implementations
|
|
|
|
## 3. Implementation Steps
|
|
|
|
### Step 1: Fix Risk Judge (Immediate)
|
|
```python
|
|
# In risk_aggregator, ensure proper state is passed:
|
|
state["aggregated_report"] = full_report_text
|
|
state["risk_assessment_input"] = {
|
|
"reports": all_reports,
|
|
"ticker": ticker,
|
|
"date": analysis_date
|
|
}
|
|
```
|
|
|
|
### Step 2: Add Timing Decorator
|
|
```python
|
|
def timed_agent(agent_name):
|
|
def decorator(func):
|
|
def wrapper(*args, **kwargs):
|
|
start = time.time()
|
|
result = func(*args, **kwargs)
|
|
duration = time.time() - start
|
|
logger.info(f"{agent_name} completed in {duration:.2f}s")
|
|
return result
|
|
return wrapper
|
|
return decorator
|
|
```
|
|
|
|
### Step 3: Refactor Following SOLID Principles
|
|
- Extract interfaces for agents
|
|
- Create base classes for common functionality
|
|
- Use dependency injection for tools and LLMs
|
|
|
|
## 4. Testing Strategy
|
|
|
|
1. **Mock API Responses**
|
|
- Create mock responses for OpenAI API
|
|
- Test without requiring real API keys
|
|
|
|
2. **Unit Tests**
|
|
- Test each agent in isolation
|
|
- Test tool functions independently
|
|
|
|
3. **Integration Tests**
|
|
- Test agent interactions
|
|
- Test graph execution flow
|
|
|
|
## 5. Next Actions
|
|
|
|
1. [ ] Fix Risk Judge input issue
|
|
2. [ ] Add timing to all agents
|
|
3. [ ] Create mock testing framework
|
|
4. [ ] Reorganize code structure
|
|
5. [ ] Add comprehensive logging
|
|
6. [ ] Create performance benchmarks |