How can I get to know if livekit agent is running ...
# ask-ai
h
How can I get to know if livekit agent is running STT, LLM or TTS.. like I want a log when STT runs .. a log when LLM run and alog when TTS runs
t
Thanks for reaching out, Abhishek. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're interested in logging when Speech-to-Text (STT), Large Language Model (LLM), or Text-to-Speech (TTS) components run in LiveKit! You can easily do this by using the metrics_collected event emitted by the
AgentSession
. Every time one of these components processes data, this event is triggered, and you can capture and log it using event handlers. Here’s a simple way to set it up: • Python:
Copy code
from livekit.agents import metrics, MetricsCollectedEvent

@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
    metrics.log_metrics(ev.metrics)
Node.js:
Copy code
import { logMetrics } from 'livekit-agent';

session.on("metrics_collected", (ev) => {
  logMetrics(ev.metrics);
});
This will help you log structured output for each component, such as: • STT: Audio duration, processing duration, and streaming mode. • LLM: Time-to-first-token (TTFT), input/output tokens, and tokens per second. • TTS: Time-to-first-byte (TTFB) and audio duration. If you'd like even more control, you can also subscribe directly to metrics from individual components. Please don’t hesitate to reach out if you’d like me to walk you through that or if you have any other questions—I’m here to help! Sources: Logs, metrics, and telemetry | LiveKit Docs | agents/src/voice/agent_session.ts | livekit-agents/livekit/agents/voice/agent.py | metrics/send-metrics-to-3p/send_metrics_to_3p.py