nt_template_voice_agent\\voice_agent.py\", line 66...
# ask-ai
c
nt_template_voice_agent\\voice_agent.py\", line 665, in entrypoint\n await ctx.wait_for_disconnect()\n ^^^^^^^^^^^^^^^^^^^^^^^\nAttributeError: 'JobContext' object has no attribute 'wait_for_disconnect'", "timestamp": "2025-10-08T213619.436967+00:00"}
t
Thanks for reaching out, Hai. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It looks like the error happens because the
JobContext
object doesn’t have a
wait_for_disconnect
method. No worries though! To handle disconnection in LiveKit, here’s a friendly approach you can try: Event-based Waiting:
Copy code
disconnect_event = asyncio.Event()

@context.room.on("disconnected")
def on_room_disconnect(*args):
    disconnect_event.set()

# Wait until the room is disconnected
await disconnect_event.wait()
This way, you’re listening for the
"disconnected"
event on the room object, and your code will wait until that event happens. Also, if you’re looking to wait for the room to empty rather than disconnect, you can watch for
"participant_disconnected"
events and keep an eye on the participant count. Feel free to reach out if you’d like a hand putting this together—I’m here to help! Sources: examples/voice_agents/realtime_joke_teller.py | sip-refer/README.mdoc | agent.py | Job lifecycle | LiveKit Docs