how to track turn latency and have it broke down b...
# ask-ai
n
how to track turn latency and have it broke down between llm, tts, stt
t
Thanks for reaching out, rohit. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I’m glad you asked about tracking turn latency and breaking it down between LLM, TTS, and STT! You can easily do this using the built-in Agents Metrics API, which gives you detailed latency insights for each part of the conversational pipeline. Here’s a friendly guide to help you monitor each stage: • Speech-to-Text (STT) Latency: You can use the
STTMetrics
object to see how long speech recognition takes, including
duration
(processing time) and
audio_duration
(input length). • LLM Latency: The
LLMMetrics
object helps you capture
ttft
(time to first token) and
duration
(total response time). • Text-to-Speech (TTS) Latency: With the
TTSMetrics
object, you can measure
ttfb
(time to first byte) and
duration
(synthesis time). On top of that, you can keep an eye on end-to-end latency using metrics like
end_of_utterance_delay
and
transcription_delay
. These are accessible through the Python or JavaScript SDKs via the
AgentSession
object or event listeners. If you’d like, I’m here to help with more details or even some examples to get you started—just let me know! Sources: Logs, metrics, and telemetry | LiveKit Docs | Troubleshooting & Common Issues | livekit/livekit_composite | DeepWiki | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik... | examples/voice_agents/realtime_turn_detector.py | agents/src/voice/agent_activity.ts
n
what am I doing wrong here, both are 0 metrics.log_metrics(ev.metrics) Line 1991 metrics.log_metrics(ev.metrics) Line 1992 usage_collector.collect(ev.metrics) Line 1992 usage_collector.collect(ev.metrics) Line 1993 deleted - metric = ev.metrics Line 1994 deleted - duration = getattr(metric, "duration", None) Line 1995 deleted - if duration is not None: Line 1996 deleted - logger.info( Line 1997 deleted - "LLM request duration recorded", Line 1998 deleted - extra={ Line 1999 deleted - "metric_type": getattr(metric, "type", "unknown"), Line 2000 deleted - "duration_seconds": round(duration, 2), Line 2001 deleted - }, Line 2002 deleted - )
t
It looks like you’re seeing metrics showing as 0 when using
metrics.log_metrics(ev.metrics)
. This usually means that there hasn’t been any meaningful activity during the agent session to produce measurable data. Let’s walk through a few examples together: • LLM Metrics: Values like
ttft
and
tokens_per_second
will only show up when the LLM actually generates a response. • TTS Metrics: Metrics such as
ttfb
and
audio_duration
need the agent to synthesize speech to be recorded. • STT Metrics: These, like
audio_duration
, depend on the user’s audio input being transcribed. Here are a few things to double-check: 1. Make sure your
AgentSession
is correctly set up with STT, LLM, and TTS services. 2. Confirm the session is actively handling media or interactions — for example, the user is speaking or the agent is responding. 3. Verify that your logging level is set to capture INFO-level metric logs. For debugging, try to see if the
metrics_collected
event is being triggered. Also, check that the agent is processing audio or generating responses as expected. You can inspect the metrics using the
UsageCollector
. If you still find metrics showing zero despite activity, it might be helpful to review your model configurations and the agent’s execution flow for any issues. Sources: livekit-agents/livekit/agents/metrics/utils.py | Logs, metrics, and telemetry | LiveKit Docs