Sentiment Analysis Agent
The Sentiment Analysis Agent is a specialized component of the trading system designed to gauge market psychology. It processes real-time news feeds, social sentiment, and volatility metrics to determine if the market is driven by irrational fear, excessive greed, or neutral fundamentals.
Overview
The agent leverages a Retrieval-Augmented Generation (RAG) architecture to combine live data with curated trading wisdom. By analyzing news headlines and the Crypto Fear & Greed Index, it identifies potential trend reversals and provides a "psychological" weight to the final trading decision.
Key Capabilities
- News Aggregation: Fetches and cleans news articles from multiple RSS feeds and the NewsAPI.
- Fear & Greed Interpretation: Analyzes market sentiment indices to identify overbought or oversold psychological conditions.
- Contrarian Signaling: Identifies scenarios where extreme sentiment may signal a reversal (e.g., "Buying the fear").
- RAG Integration: Accesses a local vector database of sentiment-specific trading strategies and historical papers.
Data Sources
The agent primarily consumes data through the NewsAPIConnector, which implements a tiered fetching strategy to ensure high availability:
| Source | Method | Description |
| :--- | :--- | :--- |
| Crypto RSS | Web Scraping | Fetches from CoinTelegraph and CoinDesk (includes full descriptions). |
| Google News | RSS | Provides broad market coverage without requiring an API key. |
| NewsAPI | REST API | Official fallback for high-quality, filtered financial news (requires NEWSAPI_KEY). |
Response Schema
The Sentiment Agent returns a structured SentimentAnalysis object. This ensures the TradingOrchestrator can programmatically parse its reasoning.
SentimentAnalysis Model
Inherits from AgentRecommendation.
| Field | Type | Description |
| :--- | :--- | :--- |
| recommendation | BUY \| SELL \| HOLD | The sentiment-driven action. |
| confidence | int (0-100) | Confidence level in the analysis. |
| reasoning | str | Detailed explanation of the current market mood. |
| metadata | SentimentMetadata | Specific sentiment metrics (see below). |
SentimentMetadata
| Field | Type | Description |
| :--- | :--- | :--- |
| news_sentiment | str | POSITIVE, NEGATIVE, or NEUTRAL. |
| fear_greed_interpretation | str | Interpretation of the Fear & Greed Index. |
| contrarian_signal | bool | True if the agent suggests acting against the crowd. |
Usage Example
The Sentiment Agent is typically invoked via the TradingOrchestrator, but it can be used independently for market research.
from agents.schemas import SentimentAnalysis
from data_connectors.newsapi_connector import NewsAPIConnector
# 1. Fetch live news data
connector = NewsAPIConnector()
news_data = connector.get_bitcoin_news(limit=5)
# 2. Example of the agent's structured output
# This is generated by the LLM via the SentimentAnalysis Pydantic schema
analysis = SentimentAnalysis(
recommendation="BUY",
confidence=75,
reasoning="Market is in a state of 'Extreme Fear' (20/100). News headlines show stabilization after a major dip. Historical RAG data suggests this is a high-probability accumulation zone.",
metadata={
"news_sentiment": "NEUTRAL",
"fear_greed_interpretation": "EXTREME_FEAR",
"contrarian_signal": True
}
)
print(f"Action: {analysis.recommendation} (Confidence: {analysis.confidence}%)")
print(f"Contrarian Play: {analysis.metadata.contrarian_signal}")
Knowledge Indexing (RAG)
The Sentiment Agent is "trained" on specific domain knowledge stored in knowledge/sentiment/. The KnowledgeIndexer processes these files into a vector store to help the agent ground its decisions in proven sentiment-trading theories.
To index new sentiment research or strategy PDFs:
- Place the files in
knowledge/sentiment/orknowledge/papers/. - Run the indexer:
from agents.rag.indexer import KnowledgeIndexer
indexer = KnowledgeIndexer()
results = indexer.index_domain("sentiment", "knowledge/sentiment")
print(f"Indexed {results} sentiment knowledge chunks.")
Internal Workflow
- Context Collection: The agent receives a query containing the latest price action and Fear & Greed values.
- Document Retrieval: The RAG system searches the
sentimentvector store for relevant psychological trading rules. - Sentiment Extraction: The LLM parses recent news headlines from the
NewsAPIConnector. - Synthesis: The agent compares the live news mood against historical sentiment cycles and outputs the structured
SentimentAnalysisschema.