usage_collector = metrics.UsageCollector() @se...
# ask-ai
p
usage_collector = metrics.UsageCollector() @session.on("metrics_collected") def _on_metrics_collected(ev: MetricsCollectedEvent): usage_collector.collect(ev.metrics) from livekit.agents.metrics import RealtimeModelMetrics, EOUMetrics logger.warning(f"one") if isinstance (ev.metrics, RealtimeModelMetrics): logger.warning(f"two") metrics.log_metrics(ev.metrics) # end_delays = metrics.end_of_utterance_delay # logger.warning(f"three") ttft = ev.metrics.ttft # logger.warning(f"EOU DELAYS is: {end_delays}") logger.warning(f"TTFT is: {ttft}") this is the code I'm using now
t
Thanks for reaching out, Chandra. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks for reaching out! Could you please share a bit more about the specific issue or question you have with this code? Are you running into an error, noticing something unexpected, or maybe looking for some tips on how to implement or debug it? I'm here to help!
p
ok
t
I'd love to help you out! Could you please share a bit more about what you're experiencing with this code? Are you running into any errors, noticing something unexpected, or maybe looking for some tips on how to implement or debug it? I'm here to support you every step of the way!
p
I want eou and ttft metrics in realtime model metric
t
I'm happy to guide you through collecting and logging EOU (End of Utterance) and TTFT (Time to First Token) metrics in
RealtimeModelMetrics
. Here's how you can do it step-by-step: 1. Make sure you're using a Realtime API with
turn_detection
enabled, such as
vad
. 2. Choose a Realtime-capable model like GoogleRealtimeModel, AWSRealtimeModel, or OpenAIRealtimeModel. 3. Set up an event listener for the
metrics_collected
event to capture and log these metrics easily:
Copy code
@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
    if isinstance(ev.metrics, RealtimeModelMetrics):
        print(f"TTFT: {ev.metrics.ttft:.2f} s")
    if isinstance(ev.metrics, EOUMetrics):
        print(f"EOU Delay: {ev.metrics.end_of_utterance_delay} ms")
If you run into any questions or need a hand with implementation or troubleshooting, please don’t hesitate to reach out—I’m here to help! Sources: Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | agents/src/metrics/utils.ts | livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/...