victorious-midnight-79553
11/17/2025, 2:02 PMtall-airline-16756
11/17/2025, 2:02 PMtall-airline-16756
11/17/2025, 2:04 PMimport time
from livekit.agents.metrics import RealtimeModelMetrics
# Here’s an example of how you can track latency
start_time = time.time()
# Simulate request creation and processing
# You’ll want to replace this with your actual request handling logic
response = model.generate(input_data)
# Now, calculate the latency metrics
end_time = time.time()
ttft = response.first_token_timestamp - start_time
total_duration = end_time - start_time
# Finally, log the metrics
print(f"Time to First Token (TTFT): {ttft:.3f}s")
print(f"Total Duration: {total_duration:.3f}s")
3. Advanced Tracking: If you’d like to capture more detailed insights like token counts and generation speed, the RealtimeModelMetrics class is a great tool to use for automatic logging.
If you have any questions or want help with a more detailed implementation, please don’t hesitate to reach out—I’m here to help!
Sources: livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/... | Logs, metrics, and telemetry | LiveKit Docs | Operational Best Practices | livekit/livekit_composite | DeepWikivictorious-midnight-79553
11/17/2025, 2:10 PMRealtimeModelMetrics - to track latency in agent responding? and also the EOU delay
(all of this for realtime mode)tall-airline-16756
11/17/2025, 2:11 PMRealtimeModelMetrics class:
from livekit.agents.metrics import RealtimeModelMetrics
@agent.on("metrics_collected")
def on_metrics_collected(agent_metrics):
if isinstance(agent_metrics, RealtimeModelMetrics):
print(f"Agent response TTFT: {agent_metrics.ttft}s")
print(f"Total response duration: {agent_metrics.duration}s")
2. Tracking EOU Delay:
• End-of-Utterance Delay: This is the time between when the user finishes speaking and when the system decides to end the turn.
• Transcription Delay: This measures how long it takes to get the transcript after the user stops speaking.
For these, you can use the EOUMetrics class:
from livekit.agents.metrics import EOUMetrics
@agent.on("metrics_collected")
def on_metrics_collected(agent_metrics):
if isinstance(agent_metrics, EOUMetrics):
print(f"EOU delay: {agent_metrics.end_of_utterance_delay}s")
print(f"Transcription delay: {agent_metrics.transcription_delay}s")
3. Combining Metrics for Total Latency:
To get a complete picture, you can combine these metrics like this:
total_latency = eou.end_of_utterance_delay + llm.ttft + tts.ttfb
If you'd like, I’m here to help with any further questions or if you want a more detailed implementation. Just let me know!
Sources: examples/src/comprehensive_test.ts | agent-examples/agent_examples/pipeline_agent.py | Logs, metrics, and telemetry | LiveKit Docs