I'm confused about when to call session.aclose vs....
# ask-ai
w
I'm confused about when to call session.aclose vs. ctx.shutdown vs. api_client.reoom.delete_room. Which does what, and when should I be doing each?
t
Thanks for reaching out, Alex. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
When working with LiveKit, the methods
session.aclose()
,
ctx.shutdown()
, and
api_client.room.delete_room()
serve distinct purposes: •
ctx.shutdown()
: Use this method when the agent should disconnect from the room but allow other participants to continue their session. It triggers shutdown hooks for any necessary cleanup. •
api_client.room.delete_room()
: This method ends the session for all participants by deleting the room. It’s typically used when the session should be terminated entirely, such as when a specific condition is met (e.g., a game over scenario). •
session.aclose()
: Use this to close the agent’s session properly, ensuring any ongoing operations are completed before termination. It’s often used in conjunction with
ctx.shutdown()
. In summary,
ctx.shutdown()
is for agent disconnection,
api_client.room.delete_room()
for ending the entire session, and
session.aclose()
for graceful session closure. Sources: Inside a session | LiveKit Docs | flows/simple_flow.py