File size: 1,503 Bytes
e5e35a3
 
 
 
cc8beab
e5e35a3
 
 
 
 
 
 
 
 
 
 
6710fbe
 
e5e35a3
 
 
6710fbe
e5e35a3
cc8beab
 
 
 
 
 
 
e5e35a3
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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