diff --git a/galaxy/core/events.py b/galaxy/core/events.py index 5e0e5cc4d..156733fe0 100644 --- a/galaxy/core/events.py +++ b/galaxy/core/events.py @@ -45,6 +45,10 @@ class EventType(Enum): ) DEVICE_STATUS_CHANGED = "device_status_changed" # Device status changed + # LLM cost/token tracking events + LLM_CALL_COMPLETED = "llm_call_completed" # LLM API call finished + COST_THRESHOLD_EXCEEDED = "cost_threshold_exceeded" # Session cost exceeded configured threshold + @dataclass class Event: @@ -120,6 +124,37 @@ class DeviceEvent(Event): all_devices: Dict[str, Dict[str, Any]] # Snapshot of all devices in registry +@dataclass +class LLMCallEvent(Event): + """ + LLM API call completed event. + + Extends base Event class with LLM-specific cost and token usage + information for tracking and aggregation. + """ + + agent_type: str # e.g. "HOST_AGENT", "CONSTELLATION_AGENT" + model: str # e.g. "gpt-4o", "claude-3-5-sonnet-20241022" + prompt_tokens: int + completion_tokens: int + cost: float + duration_ms: float # wall time of the API call + + +@dataclass +class CostThresholdExceededEvent(Event): + """ + Session cost threshold exceeded event. + + Published when the accumulated session cost crosses the configured + cost_alert_threshold, allowing observers to surface alerts. + """ + + session_id: str + total_cost: float + threshold: float + + class IEventObserver(ABC): """ Interface for event observers. diff --git a/ufo/trajectory/parser.py b/ufo/trajectory/parser.py index 7aa2e7d3b..325e0119d 100644 --- a/ufo/trajectory/parser.py +++ b/ufo/trajectory/parser.py @@ -155,7 +155,7 @@ def _load_evaluation_data(self) -> Dict[str, Any]: try: evaluation_data = json.load(file) - except: + except json.JSONDecodeError: evaluation_data = {} else: