chilly-balloon-11273
09/18/2025, 12:44 PMtall-airline-16756
09/18/2025, 12:44 PMtall-airline-16756
09/18/2025, 12:45 PMdelete_room API to end the entire room, which will disconnect everyone involved.
• Client-Side Disconnection: Adding a simple UI button that triggers Room.disconnect() lets users gracefully leave the call whenever they want.
• Programmatic Agent Session Closure: If you want to disconnect just the agent but keep others connected, session.aclose() is a great choice.
• Automatic Disconnection: You might also set up the session to close automatically when a participant leaves or the worker shuts down, making things seamless.
• Telephony Call Transfer: Another option is to use transfer_sip_participant to move the call to another destination, effectively ending the agent’s session.
If you could share a bit about your specific scenario—whether it’s web-based, telephony, or part of an automated workflow—I’d be more than happy to help you find the best approach tailored just for you!
Sources: Job lifecycle | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_session.py | complex-agents/drive-thru/frontend/components/livekit/agent-control-bar/age... | components/livekit/agent-control-bar/agent-control-bar.tsx | Agents telephony integration | LiveKit Docschilly-balloon-11273
09/18/2025, 12:52 PMtall-airline-16756
09/18/2025, 12:52 PMplayback_finished Event: You can listen for the playback_finished event from the AudioOutput. This way, you'll know exactly when the audio playback is complete. Here's an example:
@session.output.audio.on("playback_finished")
def _on_playback_finished(ev):
<http://logger.info|logger.info>("Playback finished")
# End the call safely here
• Using `SpeechHandle`: Another approach is to await the SpeechHandle returned by say() or generate_reply(). This ensures the playback finishes before the call ends. For example:
handle = session.generate_reply("Goodbye")
await handle # Wait for playback to complete
These methods help prevent the call from ending too soon. If you’d like, I’m here to help you implement this or answer any other questions you might have!
Sources: How to detect when an agent has finished speaking | Agent speech and audio | LiveKit Docs | Agent speech and audio | LiveKit Docs | livekit-plugins/livekit-plugins-elevenlabs/livekit/plugins/elevenlabs/tts.p...