hello! I’m wondering how I should handle page relo...
# agents
m
hello! I’m wondering how I should handle page reloads / page close and reopen. I see that the agent session is closing, but I think the agent participant is still in the room. Does closing an agent session also remove the participant?
it seems like it doesn’t, which is tricky, because it’s difficult to tell whether I should re-dispatch an agent; there is a “zombie” agent participant in the room.
l
There are RoomOptions to control whether the room closes when the participant disconnects: https://docs.livekit.io/reference/python/v1/livekit/agents/voice/room_io/index.html#livekit.agents.voice.room_io.RoomOptions. By default the room will remain open for 20 seconds, which should allow the client browser reload to reconnect. For different sessions, it is recommended to create a new room ID.
m
Thanks for the response @lively-winter-88668. For the agent itself inside the room, does it have a session close timer? It’s less the room connection that’s giving me trouble, and more the agent participant.
l
No, because the agent is not responsible for controlling the lifecycle of the room, the LK server is responsible for dispatching agents to the room: https://docs.livekit.io/agents/server/agent-dispatch/. Maybe I'm not understanding your use case?
m
My use case is, on page reload, to re-dispatch an agent or to trust the current agent to respond. If the existing agent participant in the room has closed its session (which seems to happen after some timeout), I need to redispatch, but if the agent participant in the room still has an active session, then if i re-dispatch, two agents will be responding. So I’m just wondering if there’s an efficient way to check if the agent in the room has closed its session. Not worried about the lifecycle of the room, just the agent. Thank you for your responses!
l
Ah, so would it be an option to set
close_on_disconnect
to False (by default it is true): https://docs.livekit.io/reference/python/v1/livekit/agents/voice/room_io/index.html#livekit.agents.voice.room_io.RoomOptions. This will give the client up to 20 seconds to reconnect to the room if they leave, and avoid complex re-dispatching logic.
m
Oh perfect, thank you!
Adding something on https://docs.livekit.io/agents/build/sessions/ would probably help make that functionality a little clearer — but I also just missed that this parameter was available🙂
l
@dry-musician-70452 some docs feedback ^. We only surface a subset of the options available at https://docs.livekit.io/reference/python/v1/livekit/agents/voice/room_io/index.html#livekit.agents.voice.room_io.RoomInputOptions under the room options at https://docs.livekit.io/agents/build/sessions/#room-options. I'm not sure if that is intentional?