millions-eye-11809
10/08/2025, 1:19 PMtall-airline-16756
10/08/2025, 1:19 PMtall-airline-16756
10/08/2025, 1:19 PMmillions-eye-11809
10/08/2025, 1:21 PMtall-airline-16756
10/08/2025, 1:21 PMsession.shutdown() or session.aclose() method on your AgentSession instance. This way, the agent will disconnect smoothly, and the other participants will remain unaffected.
Here’s a friendly example in Python to guide you:
await self.session.generate_reply(instructions="say goodbye to the user")
self.session.shutdown()
Also, to make sure the room stays intact after the agent session ends, just set delete_room_on_close=False in your RoomInputOptions configuration like this:
session = AgentSession(
stt=deepgram.STT(),
llm=openai.LLM(),
tts=cartesia.TTS(),
vad=silero.VAD.load(),
input_options=RoomInputOptions(delete_room_on_close=False)
)
And if you'd like, you can set up an on_close event listener to take care of any cleanup tasks after the session ends:
@session.on("close")
def on_close(ev: CloseEvent):
print(f"Agent Session closed, reason: {ev.reason}")
# Perform any necessary cleanup here
This way, the agent disconnects gracefully, any cleanup you need happens smoothly, and the room stays ready for everyone else. If you have any questions or need further help, I’m here for you!
Sources: Job lifecycle | LiveKit Docs | Agent Session & Activity Management | livekit/livekit_composite | DeepWiki | livekit-agents/livekit/agents/voice/room_io/room_io.py | Events and error handling | LiveKit Docs