Specialized Agent Personas
The system utilizes a multi-agent architecture where specialized AI personas collaborate to generate trading decisions. Each agent is constrained by a specific Pydantic schema, ensuring that the TradingOrchestrator receives structured, type-safe data for downstream processing and dashboard visualization.
Core Response Schema
Every agent inherits from the AgentRecommendation base class. This ensures a consistent interface across the entire analysis pipeline.
class AgentRecommendation(BaseModel):
recommendation: Literal["BUY", "SELL", "HOLD"]
confidence: int # Range: 0 to 100
reasoning: str # Detailed explanation of data points
key_factors: List[str] # Top 5 drivers of the decision
Specialized Agent Personas
The system splits market analysis into four distinct domains. Each persona utilizes specialized tools (like the NewsAPIConnector) and RAG-indexed domain knowledge.
1. Technical Analyst
The Technical Analyst focuses on price action, momentum, and volume. It processes raw OHLCV data to identify trends and pivot points.
- Logic: Evaluates RSI (Relative Strength Index), MACD crossovers, and Moving Averages.
- Schema:
TechnicalAnalysis - Metadata Fields:
rsi_signal: Interpretation (OVERSOLD/NEUTRAL/OVERBOUGHT).macd_signal: Interpretation (BULLISH/BEARISH).support_level/resistance_level: Float values for key price floors and ceilings.
2. Sentiment Analyst
The Sentiment Analyst monitors market psychology and news flow. It uses the NewsAPIConnector to pull data from sources like CoinTelegraph, CoinDesk, and Google News RSS.
- Logic: Aggregates news sentiment and evaluates the "Fear & Greed Index" to determine if the market is overextended.
- Schema:
SentimentAnalysis - Metadata Fields:
fear_greed_interpretation: Contextualizing the current index value.news_sentiment: Overall bias (POSITIVE/NEGATIVE/NEUTRAL).contrarian_signal: A boolean indicating if the agent suggests betting against the prevailing crowd sentiment.
3. Fundamental Analyst
The Fundamental Analyst looks at the long-term health of the asset. For Bitcoin, this involves on-chain metrics and network utility.
- Logic: Assesses network growth, valuation phases (Accumulation vs. Distribution), and macro-economic factors.
- Schema:
FundamentalAnalysis - Metadata Fields:
valuation_status: Determination of UNDERVALUED or OVERVALUED status.market_cycle_phase: Phase identification (e.g., ACCUMULATION, MARKUP).network_health: Assessment based on on-chain activity (STRONG/WEAK).
4. Risk Manager
The Risk Manager acts as the final gatekeeper. Unlike the other agents, it performs mathematical calculations to determine execution parameters.
- Logic: Analyzes volatility and calculates protective levels to ensure capital preservation.
- Schema:
RiskAnalysis - Metadata Fields:
volatility_assessment: Categorization (LOW/MEDIUM/HIGH).position_sizing: Suggested allocation (FULL/HALF/QUARTER/NONE).stop_loss_level: Calculated exit price for losing trades.take_profit_level: Target exit price for winning trades.
Knowledge Retrieval (RAG)
Each persona is backed by a specific knowledge domain indexed via the KnowledgeIndexer. When an agent is invoked, it retrieves relevant context from the vector store based on its domain:
| Domain | Source Material | | :--- | :--- | | Technical | Trend analysis whitepapers, indicator strategies | | Sentiment | Behavioral finance documents, psychology of trading | | Fundamental | Network valuation models, macro-economic reports | | Risk | ATR-based stop loss methods, Kelly Criterion, sizing models |
Implementation Example
The following example demonstrates how the TechnicalAnalysis schema is populated by an agent during a live analysis:
from agents.schemas import TechnicalAnalysis
# Example structured output from the Technical Agent
tech_response = TechnicalAnalysis(
recommendation="BUY",
confidence=85,
reasoning="RSI is showing bullish divergence at $42,000 support level.",
key_factors=["RSI Oversold", "Strong Support", "Volume Spiking"],
metadata={
"rsi_signal": "OVERSOLD",
"trend_direction": "UPTREND",
"support_level": 42000.0,
"resistance_level": 48500.0
}
)
This structured output is then stored in the database and surfaced via the FastAPI Backend, allowing the React Dashboard to display specific indicator signals for every trade recommendation.