async def entrypoint(ctx: JobContext): print("...
# agents
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.