Skip to content

latent.agents.metrics

Utilities for extracting timing and token metrics from agent events.

Classes

CallMetrics

CallMetrics(duration_seconds: float, input_tokens: int, output_tokens: int, total_tokens: int)

Aggregated timing and token metrics from agent events.

Functions

collect_call_metrics

collect_call_metrics(events: list[AgentEvent]) -> CallMetrics

Extract aggregated timing and token metrics from agent events.

Sums across all LLM calls in the event list. Duration is computed from matched LLMCallStart/LLMCallEnd timestamp pairs.

Args: events: List of agent events (typically from agent.events).

Returns: CallMetrics with total duration, input/output/total tokens.