busy-lunch-15701
11/28/2025, 7:48 AMtall-airline-16756
11/28/2025, 7:48 AMtall-airline-16756
11/28/2025, 7:48 AMhandle = ctx.session.generate_reply(instructions="Goodbye. Hanging up in 5s...")
try:
await asyncio.wait_for(handle.wait_for_playout(), timeout=5.0)
except asyncio.TimeoutError:
pass
else:
if handle.interrupted:
await ctx.session.generate_reply(instructions="Okay, I'll stay on the line.")
return "Interrupted"
ctx.session.close_soon()
return "Call ended"
2) Poll every second and check handle.interrupted
handle = ctx.session.generate_reply(instructions="Goodbye. Hanging up in 5s...")
for _ in range(5):
await asyncio.sleep(1)
if handle.interrupted:
await ctx.session.generate_reply(instructions="I'll stay on the line.")
return "Interrupted"
ctx.session.close_soon()
return "Call ended"
Which pattern fits your setup better — the single timed wait or the per-second poll? I can adapt the example to your existing code style.
Sources: Agent speech and audio | LiveKit docs | Turn detection and interruptions | LiveKit Docs | Tool definition and use | LiveKit docs