when does metrics_collected event trigger?
# ask-ai
h
when does metrics_collected event trigger?
t
Thanks for reaching out, Ahmed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The
metrics_collected
event in LiveKit triggers whenever there is a new metrics object available during an active session. This event is fired by various components within the LiveKit Agents framework, including: • Speech-to-Text (STT) • Large Language Models (LLM) • Text-to-Speech (TTS) • Voice Activity Detection (VAD) • Voice Pipeline Agent (VPA) The event carries metrics of various types, such as STTMetrics, LLMMetrics, TTSMetrics, VADMetrics, and EOUMetrics. To capture these events, you can subscribe to them on the `AgentSession`:
Copy code
@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
    metrics.log_metrics(ev.metrics)
This provides detailed insights into duration, latency, and usage across different stages of the agent's operation. Sources: Events and error handling | LiveKit Docs | SpeechEventType | LiveKit Agents | LLMEvent | LiveKit Agents | TTSEvent | LiveKit Agents | VADEventType | LiveKit Agents