Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions galaxy/core/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ufo/trajectory/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down