bitter-analyst-30633
09/11/2025, 5:27 PMtall-airline-16756
09/11/2025, 5:27 PMtall-airline-16756
09/11/2025, 5:28 PMshutdown_process_timeout
setting in WorkerOptions
. This gives your process a bit more time to close gracefully. I hope this helps clarify things!
Sources: examples/voice_agents/basic_agent.py | Inside a session | LiveKit Docsbitter-analyst-30633
09/11/2025, 5:31 PMtall-airline-16756
09/11/2025, 5:32 PMDeleteRoom
API takes care of removing everyone, and the Disconnected
room event is sent with the reason ROOM_DELETED
. So, you don’t need to worry about handling participant disconnections separately after deleting the room — it’s all managed for you!
Sources: cmd/lk/room.go | Agents telephony integration | LiveKit Docs | livekit-api/livekit/api/room_service.py | pkg/service/roommanager.go | Connecting to LiveKit | LiveKit Docstall-airline-16756
09/11/2025, 5:32 PMDeleteRoom
API takes care of removing all participants, and you'll see the Disconnected
room event with the reason ROOM_DELETED
. So, there’s no need to worry about handling participant disconnections afterward—it’s all handled smoothly for you.bitter-analyst-30633
09/11/2025, 5:33 PMtall-airline-16756
09/11/2025, 5:35 PMclose_timeout
limit while shutting down.
Even if it seems like no tasks are running, it's a good idea to double-check that all shutdown callbacks finish quickly. If needed, you can also adjust the close_timeout
setting to give the processes a bit more time to close gracefully. I hope this helps, and please feel free to reach out if you need more assistance!
Sources: examples/avatar_agents/audio_wave/dispatcher.py | Docs::Home | mcp/server.pybitter-analyst-30633
09/11/2025, 5:36 PMtall-airline-16756
09/11/2025, 5:37 PMctx.add_shutdown_callback
. This is a great way to make sure any cleanup tasks, like saving conversation data, happen no matter how the session ends.
• Detect Session End Reason: By listening to the close
event on the session, you can find out why the session ended (such as user disconnect or room deletion) and then take any specific actions you might need.
• Access Conversation History: Using ctx.session.history
lets you retrieve the full conversation transcript, including messages, roles, and timestamps, which is perfect for saving to a database or file.
• Real-Time Transcription: You might also consider listening to events like conversation_item_added
to save messages as they come in during the session, so nothing gets missed.
By following this approach, you can feel confident that your conversation data will be saved reliably, no matter how the call wraps up. If you have any questions or want to explore this further, I'm here to help!
Sources: Session recording and transcripts | LiveKit Docs | Session recording and transcripts | LiveKit Docs | How to capture real-time agent transcriptions during conversations | Events and error handling | LiveKit Docs | Inside a session | LiveKit Docstall-airline-16756
09/11/2025, 5:37 PMctx.add_shutdown_callback
. This way, any cleanup tasks like saving your conversation data will run no matter how the session finishes.
2. Detect Session End Reason: By listening to the close
event on the session, you can find out why the session ended—whether it was a user disconnect, room deletion, or something else.
3. Access Conversation History: You can grab the full conversation transcript, including messages, roles, and timestamps, using ctx.session.history
. This makes it easy to save everything to a database or a file.
4. Real-Time Updates: If you want to save data as the conversation happens, listening to events like conversation_item_added
can help you capture updates in real time.
Here’s a simple example of how you might set up a shutdown callback to save your conversation data:
async def entrypoint(ctx: JobContext):
async def save_conversation_data():
history = ctx.session.history
# Save history to database or file
ctx.add_shutdown_callback(save_conversation_data)
This approach helps ensure your conversation data is saved reliably, no matter how the call ends. If you have any questions or want to explore this further, I’m here to help!bitter-analyst-30633
09/11/2025, 5:38 PMtall-airline-16756
09/11/2025, 5:39 PMclose_on_disconnect=True
in RoomInputOptions
. This way, the session will automatically close when the user leaves, making things seamless for you.
• Manual Shutdown via Hangup Tool: You can create a function tool (for example, end_session
) that calls session.aclose()
to gracefully end the session whenever needed.
• Room Deletion: Once the session ends, using ctx.delete_room()
will disconnect all participants and shut down the room, keeping everything tidy.
• Final Cleanup: It’s a great idea to register shutdown callbacks with ctx.add_shutdown_callback()
. This helps you handle important tasks like saving data or releasing resources smoothly.
By using these methods, you can ensure a complete and controlled shutdown process, whether it’s triggered by a user disconnect or the agent hangup tool. If you have any questions or need further assistance, I’m here to help!
Sources: examples/warm-transfer/warm_transfer.py | avatars/hedra/education_avatar/education-frontend/components/livekit/agent-... | Inside a session | LiveKit Docsbitter-analyst-30633
09/11/2025, 5:40 PMtall-airline-16756
09/11/2025, 5:41 PMtall-airline-16756
09/11/2025, 5:41 PMbitter-analyst-30633
09/11/2025, 5:43 PMtall-airline-16756
09/11/2025, 5:44 PMclose_on_disconnect=True
and you call delete_room
, the shutdown callback actually doesn't get triggered twice. Here's why: deleting the room disconnects all participants with the reason ROOM_DELETED
, which then triggers the shutdown logic just once. The close_on_disconnect
setting works at the participant level, but when the room is deleted, that action takes priority, resulting in only one shutdown callback. I hope this helps clarify things! If you have any more questions, feel free to ask—I’m here to help.
Sources: Job lifecycle | LiveKit Docs | examples/voice_agents/realtime_joke_teller.py | Inside a session | LiveKit Docs | Managing rooms | LiveKit Docs | livekit-rtc/livekit/rtc/_proto/participant_pb2.pyi