Agent Metrics Event
After every completed turn, the agent loop emits an agent.metrics event with millisecond-level timing breakdowns. Subscribe to this event to build latency dashboards, detect slow tools, or feed cost-tracking systems.
Event Payload
typescript
interface AgentMetricsPayload {
uid: string
agentId: string
sessionId: string
traceId: string
contextAssemblyMs: number // time to build context
inferenceMs: number // LLM round-trip
toolExecutionMs: number // total time in tool calls
totalTokens: number // prompt + completion tokens
round: number // 0-indexed turn number
timestamp: number // Unix ms
}Subscribing
typescript
import { bus } from './events'
bus.on('agent.metrics', (payload) => {
console.log(`[${payload.agentId}] inference=${payload.inferenceMs}ms tools=${payload.toolExecutionMs}ms tokens=${payload.totalTokens}`)
})Fields
| Field | Description |
|---|---|
contextAssemblyMs | Time spent in context/assembler.ts building the prompt |
inferenceMs | Round-trip time to the LLM provider |
toolExecutionMs | Wall-clock time for all tool calls this round |
totalTokens | Sum of prompt and completion tokens |
round | Current round number within the session (0-indexed) |
ℹ
agent.metrics is emitted even when tool calls fail. toolExecutionMs reflects wall-clock time for all tool calls including failures.