refined-hydrogen-81988
11/13/2025, 2:40 PMself.session or some other way through agent?tall-airline-16756
11/13/2025, 2:41 PMtall-airline-16756
11/13/2025, 2:41 PMself.session.shutdown() to gracefully stop the agent session without affecting other participants in the room. Here’s a simple example:
@llm.function_tool
async def close_session(self):
await self.session.generate_reply(instructions="say goodbye to the user")
self.session.shutdown()
• Closing the Entire Room: If you want to disconnect everyone, you can use the LiveKit Server API to call delete_room. Here’s how you might do it:
from livekit.api import LiveKitAPI, DeleteRoomRequest
lkapi = LiveKitAPI(
url="https://your-livekit-server-url",
api_key="your-api-key",
api_secret="your-api-secret"
)
await lkapi.room.delete_room(DeleteRoomRequest(room="my-room-name"))
await lkapi.aclose()
Another helpful option is to set delete_room_on_close=True in RoomInputOptions, which will automatically delete the room when the agent session closes.
If you have any questions or need more help, please don’t hesitate to ask. I’m here to support you!
Sources: Job lifecycle | LiveKit Docs | Managing rooms | LiveKit docs | livekit-agents/livekit/agents/voice/agent_session.py