I am getting the following error while running the...
# ask-ai
m
I am getting the following error while running the livekit agent: {"message": "unhandled exception while running the job task\nTraceback (most recent call last):\n File \"/home/appuser/query_engine.py\", line 313, in entrypoint\n session = AgentSession(userdata=MySessionInfo(user_name=username, vector_store_id=vector_store_ids[0]),vad=silero.VAD.load(),)\n {"message": "worker is at full capacity, marking as unavailable", "level": "INFO", "name": "livekit.agents", "load": 0.9986152, "threshold": "_WorkerEnvOption(dev_default=inf, prod_default=0.75)", "timestamp": "2025-12-19T151509.611817+00:00"} {"message": "process initialized", "level": "INFO", "name": "livekit.agents", "pid": 40, "elapsed_time": 4.29, "timestamp": "2025-12-19T151510.079982+00:00"} {"message": "worker is below capacity, marking as available", "level": "INFO", "name": "livekit.agents", "load": 0.21115040000000004, "threshold": "_WorkerEnvOption(dev_default=inf, prod_default=0.75)", "timestamp": "2025-12-19T151512.112798+00:00"} How to fix it?
t
Thanks for reaching out, shreyasraoinna. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to the error excerpts you shared (the "worker is at full capacity" logs and the unhandled exception during
AgentSession
creation). Root cause: you’re loading the Silero VAD model per session (
silero.VAD.load()
in the entrypoint), which can exhaust CPU/memory when multiple sessions start and push the worker above the load threshold. What to do next (quick fixes): 1. Preload the VAD once per process and reuse it • Use a prewarm/setup function (runs once per worker process) to call
silero.VAD.load()
and store the instance on the process userdata. • In your entrypoint, pass the preloaded instance (e.g.,
ctx.proc.userdata["vad"]
) to
AgentSession
instead of calling
silero.VAD.load()
there. 1. Restart the agent after changing code • This clears any overloaded processes and ensures the prewarm runs. Optional (self-hosted only): if your host can handle more concurrent load, you can raise the load threshold or implement a custom
load_fnc
. Note: LiveKit Cloud does not allow changing these values. If you want, tell me: • whether you’re running self-hosted or on LiveKit Cloud, • a short snippet of your current entrypoint and where you call
silero.VAD.load()
, and I’ll provide an exact code snippet tailored to your setup. Sources: Silero VAD plugin | LiveKit docs | Agent server options | LiveKit docs
m
My entrypoint function : async def entrypoint(ctx: JobContext): await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY) participant = await ctx.wait_for_participant() logger.info(f"starting voice assistant for participant {participant.identity}") if participant.identity: username = participant.identity else: # Adding this line so that conversations will work in sandbox frontend username = "PaulSmith" system_instructions, vector_store_ids = get_system_instructions(username) voice_instructions = "You are a voice agent. Ensure that your responses are short and concise.\n" system_instructions = voice_instructions + system_instructions agent = Agent( instructions=system_instructions, vad=silero.VAD.load(), stt=deepgram.STT(), llm=openai.LLM.with_azure(azure_deployment="gpt-4o", model="gpt-4o", azure_endpoint=AZURE_OPENAI_ENDPOINT, api_key=AZURE_OPENAI_API_KEY, api_version="2024-12-01-preview"), # tts=openai.TTS(model="tts-1", voice="sage"), tts=openai.TTS.with_azure(model="tts", voice="nova", api_version="2024-02-15-preview", instructions="Speak slowly in a calm and soothing voice."), # llm=openai.LLM(model="gpt-4o"), # tts=openai.TTS(model="tts-1",voice="sage"), ) session = AgentSession(userdata=MySessionInfo(user_name=username, vector_store_id=vector_store_ids[0])) # log metrics as they are emitted, and total usage after session is over usage_collector = metrics.UsageCollector() @session.on("metrics_collected") def _on_metrics_collected(ev: MetricsCollectedEvent): metrics.log_metrics(ev.metrics) usage_collector.collect(ev.metrics) async def log_usage(): summary = usage_collector.get_summary() # chat_history = str(session.history.to_dict()) # write_chat_to_db(chat_history, username=username) logger.info(f"Usage: {summary}") # shutdown callbacks are triggered when the session is over ctx.add_shutdown_callback(log_usage) await session.start(agent=agent, room=ctx.room, room_input_options=RoomInputOptions( # LiveKit Cloud enhanced noise cancellation # - If self-hosting, omit this parameter # - For telephony applications, use
BVCTelephony
for best results noise_cancellation=noise_cancellation.BVC(), ), ) await session.say("Hey, how can I help you today?", allow_interruptions=True)
t
Thanks — I’m responding to your entrypoint snippet and showing exactly how to preload the Silero VAD once per worker and reuse it in each session. Key change: move
silero.VAD.load()
into a `prewarm`/setup function so the model is loaded once per process and stored on
proc.userdata
. In the entrypoint use that stored instance instead of calling
.load()
. Example (self-contained):
Copy code
from livekit.agents import AgentServer, JobProcess, JobContext, AutoSubscribe
# import your other modules: silero, deepgram, openai, Agent, AgentSession, etc.

def prewarm(proc: JobProcess):
    # load VAD once per worker process and store it
    proc.userdata["vad"] = silero.VAD.load()

server = AgentServer(setup_fnc=prewarm)  # ensure prewarm runs for each worker process

@server.rtc_session()
async def entrypoint(ctx: JobContext):
    await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
    participant = await ctx.wait_for_participant()
    <http://logger.info|logger.info>(f"starting voice assistant for participant {participant.identity}")

    username = participant.identity or "PaulSmith"
    system_instructions, vector_store_ids = get_system_instructions(username)
    voice_instructions = "You are a voice agent. Ensure that your responses are short and concise.\n"
    system_instructions = voice_instructions + system_instructions

    # reuse preloaded VAD from the process userdata
    vad_instance = ctx.proc.userdata.get("vad")
    if vad_instance is None:
        # fallback (should not happen if prewarm ran)
        vad_instance = silero.VAD.load()

    agent = Agent(
        instructions=system_instructions,
        vad=vad_instance,
        stt=deepgram.STT(),
        llm=openai.LLM.with_azure(
            azure_deployment="gpt-4o",
            model="gpt-4o",
            azure_endpoint=AZURE_OPENAI_ENDPOINT,
            api_key=AZURE_OPENAI_API_KEY,
            api_version="2024-12-01-preview",
        ),
        tts=openai.TTS.with_azure(
            model="tts",
            voice="nova",
            api_version="2024-02-15-preview",
            instructions="Speak slowly in a calm and soothing voice.",
        ),
    )

    session = AgentSession(userdata=MySessionInfo(user_name=username, vector_store_id=vector_store_ids[0]))

    usage_collector = metrics.UsageCollector()

    @session.on("metrics_collected")
    def _on_metrics_collected(ev: MetricsCollectedEvent):
        metrics.log_metrics(ev.metrics)
        usage_collector.collect(ev.metrics)

    async def log_usage():
        summary = usage_collector.get_summary()
        <http://logger.info|logger.info>(f"Usage: {summary}")

    ctx.add_shutdown_callback(log_usage)

    await session.start(
        agent=agent,
        room=ctx.room,
        room_input_options=RoomInputOptions(noise_cancellation=noise_cancellation.BVC()),
    )

    await session.say("Hey, how can I help you today?", allow_interruptions=True)
Next steps: • Apply this change and restart the agent processes so prewarm runs. • If you still see capacity logs, tell me whether you run self-hosted or LiveKit Cloud and how many concurrent sessions you expect — I’ll suggest load tuning or further optimizations.
m
Thanks, will check if it works
t
You’re welcome — glad to help. If the prewarm change doesn’t fully fix it, please tell me: • whether you run self-hosted or on LiveKit Cloud, and • roughly how many concurrent sessions you expect, and share any new logs (especially repeated "worker is at full capacity" lines). I’ll suggest next steps (load tuning, further optimizations, or debugging suggestions).
m
I am running livekit cloud. Concurrent sessions - 3-4
t
Thanks — since you’re on LiveKit Cloud and expect 3–4 concurrent sessions, the prewarm change you applied is the correct fix. Preloading the Silero VAD once per worker prevents multiple heavy model loads (which cause the worker to hit the cloud load threshold). Quick checklist: • Confirm you added a prewarm/setup function that does
proc.userdata["vad"] = silero.VAD.load()
. • Confirm your entrypoint uses
ctx.proc.userdata["vad"]
(fallback only if missing). • Restart/redeploy the agent so prewarm runs for each worker process. Notes: • You cannot change load_threshold on LiveKit Cloud; reducing per-process resource use (prewarm) is the right approach. • If you still see "worker is at full capacity" logs after redeploy, please share the new logs (especially any repeated capacity lines) and I’ll help troubleshoot further. Would you like me to review your updated code or new logs after you redeploy? Sources: Silero VAD plugin | LiveKit docs | Agent server options | LiveKit docs | STT Metrics | LiveKit docs | Pipeline Translator Agent | LiveKit docs | Repeater | LiveKit docs
m
That is all for now