Spaces:
Sleeping
Sleeping
| from agents.base import Agent | |
| from llm.prompts import ( | |
| TECHNICAL_ANALYST_SYSTEM, | |
| NEWS_ANALYST_SYSTEM, | |
| SENTIMENT_ANALYST_SYSTEM, | |
| build_technical_analyst_prompt, | |
| build_news_analyst_prompt, | |
| build_sentiment_analyst_prompt, | |
| ) | |
| class TechnicalAnalyst(Agent): | |
| def __init__(self, llm_client): | |
| super().__init__("TechnicalAnalyst", TECHNICAL_ANALYST_SYSTEM, llm_client) | |
| def build_prompt(self, context: dict) -> str: | |
| return build_technical_analyst_prompt(context) | |
| def parse(self, raw: str) -> dict: | |
| result = super().parse(raw) | |
| signal = result.get("signal", "NEUTRAL").upper() | |
| if signal not in ("BULLISH", "BEARISH", "NEUTRAL"): | |
| signal = "NEUTRAL" | |
| return { | |
| "signal": signal, | |
| "strength": float(result.get("strength", 0.5)), | |
| "key_levels": result.get("key_levels", {}), | |
| "summary": str(result.get("summary", "")), | |
| } | |
| class NewsAnalyst(Agent): | |
| def __init__(self, llm_client): | |
| super().__init__("NewsAnalyst", NEWS_ANALYST_SYSTEM, llm_client) | |
| def build_prompt(self, context: dict) -> str: | |
| return build_news_analyst_prompt( | |
| context.get("news", []), | |
| context.get("asset", "BTC/USDT"), | |
| ) | |
| def parse(self, raw: str) -> dict: | |
| result = super().parse(raw) | |
| sentiment = result.get("sentiment", "NEUTRAL").upper() | |
| if sentiment not in ("POSITIVE", "NEGATIVE", "NEUTRAL"): | |
| sentiment = "NEUTRAL" | |
| return { | |
| "sentiment": sentiment, | |
| "score": float(result.get("score", 0.0)), | |
| "key_themes": result.get("key_themes", []), | |
| "summary": str(result.get("summary", "")), | |
| } | |
| class SentimentAnalyst(Agent): | |
| def __init__(self, llm_client): | |
| super().__init__("SentimentAnalyst", SENTIMENT_ANALYST_SYSTEM, llm_client) | |
| def build_prompt(self, context: dict) -> str: | |
| return build_sentiment_analyst_prompt( | |
| context.get("onchain", {}), | |
| context.get("asset", "BTC/USDT"), | |
| ) | |
| def parse(self, raw: str) -> dict: | |
| result = super().parse(raw) | |
| return { | |
| "sentiment": str(result.get("sentiment", "NEUTRAL")), | |
| "score": float(result.get("score", 0.0)), | |
| "funding_bias": str(result.get("funding_bias", "NEUTRAL")), | |
| "summary": str(result.get("summary", "")), | |
| } | |