Spaces:
Sleeping
Sleeping
| import logging | |
| from src.core.AgentCommand import AgentCommand | |
| from src.core.FinanceState import FinanceState | |
| from src.core.errors import add_error | |
| from src.rag.CcxtRag import CcxtRag | |
| logger = logging.getLogger(__name__) | |
| class CryptoAgent(AgentCommand): | |
| def __init__(self, state: FinanceState): | |
| self.state = state | |
| self.rag = CcxtRag() | |
| def process(self): | |
| trace_id = str(self.state.get("trace_id") or "") | |
| logger.info("[trace=%s] CryptoAgent.start", trace_id) | |
| symbol = self.state.get("crypto_symbol") | |
| if symbol: | |
| crypto_details = self.rag.get_crypto_details(symbol) | |
| logger.info("[trace=%s] CryptoAgent.details=%s", trace_id, crypto_details) | |
| if crypto_details.get("error"): | |
| add_error( | |
| self.state, | |
| code="crypto_data_error", | |
| message=str(crypto_details.get("error")), | |
| agent="crypto_agent", | |
| detail={"symbol": symbol}, | |
| ) | |
| self.state["response"] = ( | |
| f"Error retrieving crypto details for {symbol}: {crypto_details['error']}" | |
| ) | |
| else: | |
| self.state["response"] = ( | |
| f"Price Details for {symbol}:\n" | |
| f"Last Price: {crypto_details.get('last', 'N/A')}\n" | |
| f"24h Volume: {crypto_details.get('baseVolume', 'N/A')}" | |
| ) | |
| return self.state | |