How to properly close a AgentSession in livekit 1....
# ask-ai
b
How to properly close a AgentSession in livekit 1.0?
t
Thanks for reaching out, Håvard. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To properly close an AgentSession in LiveKit 1.0, you can use the following methods depending on your context: • If you are working with a RealtimeModel, use the
close()
method:
Copy code
// Close the RealtimeModel
await realtimeModel.close();
• If you are working with an agent session in a JobContext, use the
shutdown()
method:
Copy code
# Disconnect from the room
ctx.shutdown(reason="Session ended")
Note: If you need to end the session for all participants, you can use the server API's
deleteRoom
method instead of just disconnecting the agent. Sources: RealtimeModel | LiveKit Agents | Job lifecycle | LiveKit Docs