bright-stone-42953
08/01/2025, 6:39 AMtall-airline-16756
08/01/2025, 6:39 AMtall-airline-16756
08/01/2025, 6:40 AMbright-stone-42953
08/01/2025, 8:39 AMtall-airline-16756
08/01/2025, 8:40 AMLLMMetrics to track language model stuff like tokensPerSecond and completionTokens, TTSMetrics for text-to-speech details like audioDuration, and STTMetrics for speech-to-text info such as audioDuration.
• UsageCollector: This handy tool gathers all your metrics into a UsageSummary object, so you can easily track things like llmCompletionTokens, llmPromptTokens, ttsCharactersCount, and sttAudioDuration.
• Implementation: Just plug the UsageCollector into your agent code to start collecting and analyzing those metrics. Here’s a simple example:
from livekit.agents.metrics import UsageCollector
class MyAgent(Agent):
def __init__(self):
super().__init__(...)
self.usage_collector = UsageCollector()
async def on_agent_metrics(self, metrics):
self.usage_collector.collect(metrics)
Keep an eye on key metrics like tokensPerSecond to check speed and llmCompletionTokens for token usage. If you want a hand setting this up or have any questions, just let me know—I’m here to help!
Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/realtime...bright-stone-42953
08/01/2025, 8:42 AMtall-airline-16756
08/01/2025, 8:43 AMUsageCollector class is great for gathering metrics like token counts and audio durations. Here’s a quick example:
from livekit.agents.metrics import UsageCollector
usage_collector = UsageCollector()
@session.on("metrics_collected")
def _on_metrics_collected(ev):
usage_collector.collect(ev.metrics)
async def log_usage():
summary = usage_collector.get_summary()
print(f"LLM Prompt Tokens: {summary.llm_prompt_tokens}")
print(f"LLM Completion Tokens: {summary.llm_completion_tokens}")
• Keep an Eye on Key Metrics: Tracking llm_prompt_tokens, llm_completion_tokens, tts_audio_duration, and stt_audio_duration can give you great insights.
• Speed Things Up: Try to position your agent close to LLM, STT, and TTS services to cut down on network delays. Also, watch latency metrics like ttft (time-to-first-token) for a smoother experience.
• Set Rate Limits: Putting limits on token usage helps you stay on budget and spot usage trends early.
• Visualize Your Metrics: Logging or using OpenTelemetry for distributed tracing can really help you keep everything in check.
If you’d like, I’m here to help you weave these improvements into your code—just let me know!
Sources: examples/voice_agents/basic_agent.py | Voice Assistants | livekit/livekit_composite | DeepWiki | LLMMetrics | LiveKit Agents