Agents

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

FieldDescription
contextAssemblyMsTime spent in context/assembler.ts building the prompt
inferenceMsRound-trip time to the LLM provider
toolExecutionMsWall-clock time for all tool calls this round
totalTokensSum of prompt and completion tokens
roundCurrent 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.