cool-lizard-5130
05/15/2025, 12:58 PMtall-airline-16756
05/15/2025, 12:58 PMtall-airline-16756
05/15/2025, 12:58 PMmetrics
module and subscribe to the metrics_collected
event. Here’s an example implementation:
# Import the metrics module
from livekit.agents import metrics
# Subscribe to metrics collection events
@agent.on("metrics_collected")
def _on_metrics_collected(mtrcs: metrics.AgentMetrics):
# Use the helper to format and log based on metrics type
metrics.log_metrics(mtrcs)
You can calculate the total conversation latency using the formula:
total_latency = eou.end_of_utterance_delay + llm.ttft + tts.ttfb
Where: - end_of_utterance_delay: Time between VAD detecting end of speech and LLM inference. - ttft: Time to first token (LLM generating the first token). - ttfb: Time to first byte (TTS generating the first byte of audio). Let me know if you need further assistance! Sources: Capturing metrics | LiveKit Docs | Capturing metrics | LiveKit Docscool-lizard-5130
05/15/2025, 1:00 PM@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
metrics = ev.metrics
total_latency = (
metrics.eou.end_of_utterance_delay + metrics.llm.ttft + metrics.tts.ttfb
)
<http://logger.info|logger.info>(f"current total latency - {total_latency}")
metrics.log_metrics(metrics=ev.metrics, logger=logger)
tall-airline-16756
05/15/2025, 1:00 PMmetrics_collected
event in LiveKit. Here’s a breakdown:
@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
metrics = ev.metrics
total_latency = (
metrics.eou.end_of_utterance_delay + metrics.llm.ttft + metrics.tts.ttfb
)
<http://logger.info|logger.info>(f"current total latency - {total_latency}")
metrics.log_metrics(metrics=ev.metrics, logger=logger)
This should work as long as: - The metrics
object contains the eou
, llm
, and tts
attributes with the respective properties. - The log_metrics
function is correctly implemented to handle the metrics
object. If you encounter any issues, feel free to share the error or behavior, and I’ll assist further! Sources: Capturing metrics | LiveKit Docs | Capturing metrics | LiveKit Docs