TurnMetricsEvent
Emitted once per conversation turn with the turn's latency breakdown.
Defined in: src/core/events/types.ts:1134
Emitted once per conversation turn with the turn’s latency breakdown.
Remarks
Captures the timing of every pipeline stage for one turn — STT final → LLM first token → TTS first audio → playback start — as both absolute timestamps and derived durations. Use it to tune the eager pipeline (durations.sttFinalToFirstToken goes negative when a speculative generation was adopted) and to compare provider choices on real traffic.
Timestamps are epoch milliseconds, so each phase maps directly onto a tracing span (OpenTelemetry or otherwise) without clock translation.
Interrupted turns (barge-in, stopSpeaking(), pipeline errors) are also reported, with interrupted: true and whatever marks were captured before the interruption.
Example
agent.on('turn.metrics', (event) => {
const { voiceToVoice, sttFinalToFirstToken } = event.durations;
console.log(`turn ${event.turnId}: ${voiceToVoice}ms voice-to-voice`);
if (event.eagerUsed) {
console.log(`eager pipeline saved ${-sttFinalToFirstToken!}ms`);
}
});
See
TurnMetricsSummary for field documentation
Extends
BaseEvent.TurnMetricsSummary
Properties
| Property | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|
durations | TurnDurations | Derived phase durations in milliseconds. | TurnMetricsSummary.durations | src/core/pipeline/TurnMetrics.ts:144 |
eagerUsed | boolean | Whether an eager (preflight-triggered) LLM generation was adopted. | TurnMetricsSummary.eagerUsed | src/core/pipeline/TurnMetrics.ts:132 |
interrupted | boolean | Whether the turn ended early — barge-in, stopSpeaking(), or a pipeline error — rather than completing playback. | TurnMetricsSummary.interrupted | src/core/pipeline/TurnMetrics.ts:138 |
metadata? | Record<string, unknown> | Optional metadata associated with the event. Remarks May contain provider-specific data or debugging information. | BaseEvent.metadata | src/core/events/types.ts:94 |
modality | "voice" | "text" | How the turn was initiated: transcribed speech or typed text. | TurnMetricsSummary.modality | src/core/pipeline/TurnMetrics.ts:129 |
timestamp | number | Unix timestamp (in milliseconds) when the event occurred. Remarks Useful for latency measurements and debugging the pipeline timing. | BaseEvent.timestamp | src/core/events/types.ts:86 |
timestamps | TurnTimestamps | Absolute timestamps (epoch ms) for each captured stage. | TurnMetricsSummary.timestamps | src/core/pipeline/TurnMetrics.ts:141 |
transcript | string | The user text that started the turn. | TurnMetricsSummary.transcript | src/core/pipeline/TurnMetrics.ts:126 |
turnId | number | Monotonic turn counter, starting at 1 for the first turn. | TurnMetricsSummary.turnId | src/core/pipeline/TurnMetrics.ts:123 |
type | "turn.metrics" | Discriminant for this event type. | - | src/core/events/types.ts:1136 |