happy-dawn-98083
09/17/2025, 2:02 PMtall-airline-16756
09/17/2025, 2:02 PMtall-airline-16756
09/17/2025, 2:03 PMAgentSession. Every time one of these components processes data, this event is triggered, and you can capture and log it using event handlers.
Here’s a simple way to set it up:
• Python:
from livekit.agents import metrics, MetricsCollectedEvent
@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
metrics.log_metrics(ev.metrics)
• Node.js:
import { logMetrics } from 'livekit-agent';
session.on("metrics_collected", (ev) => {
logMetrics(ev.metrics);
});
This will help you log structured output for each component, such as:
• STT: Audio duration, processing duration, and streaming mode.
• LLM: Time-to-first-token (TTFT), input/output tokens, and tokens per second.
• TTS: Time-to-first-byte (TTFB) and audio duration.
If you'd like even more control, you can also subscribe directly to metrics from individual components. Please don’t hesitate to reach out if you’d like me to walk you through that or if you have any other questions—I’m here to help!
Sources: Logs, metrics, and telemetry | LiveKit Docs | agents/src/voice/agent_session.ts | livekit-agents/livekit/agents/voice/agent.py | metrics/send-metrics-to-3p/send_metrics_to_3p.py