From 00380e54926a6c464637a2fd452283aff752f01f Mon Sep 17 00:00:00 2001 From: Varun Nuthalapati Date: Sat, 25 Apr 2026 12:04:43 -0700 Subject: [PATCH 1/2] fix: replace bare except with json.JSONDecodeError in trajectory parser --- ufo/trajectory/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: From 0889f0d2d038fdcbfaea027ced3f0a89213b1a41 Mon Sep 17 00:00:00 2001 From: Varun Nuthalapati Date: Sun, 26 Apr 2026 17:27:23 -0700 Subject: [PATCH 2/2] feat(galaxy): add LLMCallEvent and CostThresholdExceededEvent to event bus Add LLM_CALL_COMPLETED and COST_THRESHOLD_EXCEEDED to EventType enum. Add LLMCallEvent dataclass (agent_type, model, prompt/completion tokens, cost, duration_ms) and CostThresholdExceededEvent dataclass (session_id, total_cost, threshold) to support cost tracking pipeline. --- galaxy/core/events.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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.