async def entrypoint(ctx: JobContext): print("...
# ask-ai
f
async def entrypoint(ctx: JobContext): print("[ENTRYPOINT] Starting entrypoint function") # Create assistant instance assistant = Assistant(room=ctx.room) print("[ENTRYPOINT] Assistant created") # IMPORTANT: Connect to the room FIRST await ctx.connect() print("[ENTRYPOINT] Connected to room") # Create session session = AgentSession( stt="assemblyai/universal-streaming:en", llm="google/gemini-2.5-flash", tts="cartesia/sonic-2:9626c31c-bec5-4cca-baa8-f8ba9e84c8bc", turn_detection=MultilingualModel(), vad=ctx.proc.userdata["vad"], ) print("[ENTRYPOINT] Session created") # Start the session - this will make the agent start listening await session.start( agent=assistant, room=ctx.room, room_input_options=RoomInputOptions( noise_cancellation=noise_cancellation.BVC(), close_on_disconnect=False, ), ) print("[ENTRYPOINT] Session started - agent should be listening now") # -------- Dynamic prompt fetch -------- session_uuid = None try: meta = json.loads(ctx.room.metadata or "{}") session_uuid = meta.get("sessionId") print(f"[ENTRYPOINT] Session UUID: {session_uuid}") except Exception as e: print(f"[ENTRYPOINT] Error parsing room metadata: {e}") if not session_uuid: print("[ENTRYPOINT] No session UUID found, using default greeting") await session.say( "Hello! I'm your AI Tutor. It seems there was an issue loading your session. Please try again." ) # DON'T return - let the agent continue running so it can still listen return dynamic_prompt = "" try: async with aiohttp.ClientSession() as http_session: url = f"http://localhost:3000/start-learning-prompt/{session_uuid}" print(f"[ENTRYPOINT] Fetching dynamic prompt from: {url}") async with http_session.get(url, timeout=aiohttp.ClientTimeout(total=5.0)) as response: if response.status == 200: data = await response.json() system_prompt = data.get("systemPrompt", "") messages = data.get("messages", []) dynamic_prompt = system_prompt or "" if messages: messages_str = json.dumps(messages, ensure_ascii=False) dynamic_prompt += "\n" + messages_str print(f"[ENTRYPOINT] Dynamic prompt fetched successfully (length: {len(dynamic_prompt)})") else: print(f"[ENTRYPOINT] Failed to fetch dynamic prompt: HTTP {response.status}") except asyncio.TimeoutError: print("[ENTRYPOINT] Timeout fetching dynamic prompt") except Exception as e: print(f"[ENTRYPOINT] Error fetching dynamic prompt: {e}") if not dynamic_prompt: print("[ENTRYPOINT] No dynamic prompt available, using default greeting") await session.say( "Hello! I'm your AI Tutor. It seems there was an issue loading your session. Please try again." ) # DON'T return - let the agent continue running return try: await assistant.update_instructions(dynamic_prompt) print("[ENTRYPOINT] Instructions updated successfully") except Exception as e: print(f"[ENTRYPOINT] Error updating instructions: {e}") await session.say( "I couldn't load the lesson instructions this time. Please try starting the session again." ) # DON'T return - let the agent continue running return if name == "__main__": cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, prewarm_fnc=prewarm)) Why this code gets stuck here? PROBLEM warning livekit.agents - The room connection was not established within 10 seconds after calling job_entry. This may indicate that job_ctx.connect() was not called. code gets stuck here, not fetching dynamic prompt and working , as it is not able to join in the session.
t
Thanks for reaching out, arpit. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It looks like the issue happens because the room connection isn’t established within 10 seconds, which usually means the
ctx.connect()
method didn’t run successfully. This step is really important to set up the connection properly and avoid that warning. Here are a few things you can try to fix this: • Make sure you’re explicitly calling
ctx.connect()
in your entrypoint function right after initializing the assistant, before moving on to anything else. • Take a look at your agent deployment setup to confirm there are enough workers available and that your agent is healthy. You can use commands like
lk agent status
and
lk agent logs
to help identify any issues. • Consider running multiple agent instances for better availability and set up load balancing to smoothly handle any traffic spikes. • Also, check that the server hosting your agent isn’t overloaded with other applications, which might slow things down. If you’re still running into problems after trying these steps, please don’t hesitate to reach out. I’m here to help and we can dig deeper together to get this sorted out. Sources: livekit-agents/livekit/agents/job.py | agents/src/ipc/job_proc_lazy_main.ts | Community & Support | livekit/livekit_composite | DeepWiki | Troubleshooting & Common Issues | livekit/livekit_composite | DeepWiki | How to Get Help from LiveKit
f
• Take a look at your agent deployment setup to confirm there are enough workers available and that your agent is healthy. You can use commands like
lk agent status
and
lk agent logs
to help identify any issues. can i check this on cloud dashboard?
t
Absolutely! You can easily check your agent deployment status and logs right on the LiveKit Cloud dashboard. Let me walk you through it: • Head over to the Agents dashboard within your LiveKit Cloud project. • Choose the agent you'd like to keep an eye on. There, you'll find real-time metrics like session count, agent status, replica count, CPU/memory usage, and error tracking—all in one place. • When it comes to logs, you can view build logs directly on the dashboard. Just a heads-up: runtime logs aren’t stored by LiveKit Cloud. But no worries! You can set up integrations with tools like Datadog, CloudWatch, Sentry, or New Relic to keep those runtime logs handy. If you’d like any help accessing this info or understanding what it all means, please don’t hesitate to reach out—I’m here for you! Sources: Deploying to production | LiveKit Docs | cmd/lk/agent.go | Log collection | LiveKit Docs