what does livekit cli does
# ask-ai
b
what does livekit cli does
t
Thanks for reaching out, Reuban. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The LiveKit CLI is a versatile command-line tool designed to simplify interactions with LiveKit services. It provides functionalities such as: • Token Generation: Create access tokens for room authentication and authorization. • Room Management: Create, list, update, and delete rooms. • Participant Operations: Join rooms, publish tracks, and stream media from sources like FFmpeg or Gstreamer. • Application Development: Bootstrap projects using predefined templates for voice assistants, video conferencing, and more. • Cloud Integration: Authenticate with LiveKit Cloud, manage API keys, and configure environment variables. • Advanced Features: Perform load testing, manage egresses for recording/streaming, and handle media publishing. It is a powerful tool for development, testing, and deployment workflows. Let me know if you need help with specific commands or features! Sources: LiveKit CLI | livekit/livekit_composite | DeepWiki | cmd/lk/utils.go | Bootstrapping an application | LiveKit Docs | CLI Setup | LiveKit Docs
b
oh now i have build basic voice agent with stt,tts, llm, vad and turn detection. now i like to monitor speed, and token consumption. now what should i do next
t
If you want to keep an eye on speed and token usage for your voice agent, LiveKit’s got you covered with its metrics collection system. Here’s a quick rundown: • Metrics Classes: Use
LLMMetrics
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:
Copy code
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...
b
now this is my agent.py help me with the code to improve all the above metrics and token usage, speed etc from dotenv import load_dotenv from livekit import agents from livekit.agents import AgentSession, Agent, RoomInputOptions from livekit.plugins import ( openai, cartesia, deepgram, noise_cancellation, silero, ) from livekit.plugins.turn_detector.multilingual import MultilingualModel load_dotenv() class Assistant(Agent): def __init__(self) -> None: super().__init__(instructions="You are a helpful voice AI assistant. You eagerly assist users with their questions by providing information from your extensive knowledge. Your responses are concise, to the point, and without any complex formatting or punctuation. You are curious, friendly, and have a sense of humor.") async def entrypoint(ctx: agents.JobContext): session = AgentSession( stt=deepgram.STT( model="nova-3", language="multi", detect_language=True, interim_results=True, no_delay=True, sample_rate=16000 ), llm=openai.LLM( model="gpt-4o-mini", temperature=0.8 ), tts=cartesia.TTS( model="sonic-2", voice="4df027cb-2920-4a1f-8c34-f21529d5c3fe", language="en", speed=1.0 ), vad=silero.VAD.load( min_speech_duration=0.05, min_silence_duration=0.3, activation_threshold=0.5, force_cpu=True ), turn_detection=MultilingualModel(), ) await session.start( room=ctx.room, agent=Assistant(), room_input_options=RoomInputOptions( noise_cancellation=noise_cancellation.BVC() ), ) await session.generate_reply( instructions="Greet the user in English with 'Hello, Reuben! What’s the deal today?' and then respond in the detected language of the user's input." ) if name == "__main__": agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))
t
To help you boost metrics collection, token usage tracking, and speed in your agent code, here are some handy tips you can try out: • Integrate UsageCollector: The
UsageCollector
class is great for gathering metrics like token counts and audio durations. Here’s a quick example:
Copy code
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