I seem to be getting a 10 second or so delay on cl...
# ask-ai
n
I seem to be getting a 10 second or so delay on closing an agent session after the participant leaves and it records dead air meanwhile. Is there a way to reduce this delay?
t
Thanks for reaching out, Blaine. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I understand you'd like to reduce the delay in closing an agent session after a participant leaves, and I'm here to help you with that! You can try one of these approaches: 1. Delete the room when the participant leaves: You can use the server API's
deleteRoom
endpoint to immediately end the session for everyone involved. This will stop any further audio or processing right away. 2. Enable automatic room deletion: When you start an
AgentSession
, simply set the
delete_room_on_close
option to
True
in
RoomInputOptions
. This way, the room will be deleted automatically as soon as the agent session closes. Here's a quick example:
Copy code
await session.start(
    agent=MyAgent(),
    room=ctx.room,
    room_input_options=RoomInputOptions(
        delete_room_on_close=True,
    ),
)
3. Manually stop egress or close the agent session: If you’re working with recordings, you might want to manually stop egress when the participant leaves or call
session.aclose()
to end the session immediately. From my experience, the best way to handle this is by deleting the room as soon as the participant leaves—either by using the server API or by enabling
delete_room_on_close
in your agent setup. If you have any questions or need further guidance, feel free to ask. I'm here to support you! Sources: Job lifecycle | LiveKit Docs | livekit-agents/livekit/agents/voice/room_io/room_io.py | How to capture real-time agent transcriptions during conversations
n
is there a default timeout that the process closes after the participant leaves?
t
Thanks for reaching out! I want to reassure you that there isn’t a default timeout delay for closing an agent session after a participant leaves. Usually, the session closes right away when the participant disconnects, as long as the
close_on_disconnect
option is set to
True
, which it is by default. If you’re noticing a delay, it could be related to other settings like room lifecycle configurations or recording processes. Please feel free to let me know if you'd like me to help you take a closer look at those—I’m here to help! Sources: CHANGELOG.md | livekit-agents/livekit/agents/utils/http_context.py | Worker options | LiveKit Docs