is departure_timeout activated if the agent is sti...
# ask-ai
d
is departure_timeout activated if the agent is still in the room?
t
Thanks for reaching out, Basile. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking whether
departure_timeout
(empty timeout) activates if an agent is still in the room. No —
departure_timeout
only applies after all participants have left. If an agent remains present, the timeout is not triggered and the room stays open. To close a room while an agent is still present, you must explicitly delete the room (for example, call the
DeleteRoom
API). Sources: Job lifecycle | LiveKit docs
d
Are you sure?
t
You're right to double-check — yes, I'm sure. To confirm:
departure_timeout
(aka
empty_timeout
) does not activate while an agent participant remains in the room. The timeout only starts when all participants have left. If you need the room closed while an agent is still present, you must explicitly delete the room (for example, call the
DeleteRoom
API).
d
How can I check if there is still an agent in the room? This is my current code def on_participant_disconnected(self, p: rtc.RemoteParticipant) -> None: """ Handles logic when a participant disconnects. Checks if the room is empty of humans, and if so, starts the grace period. """ # Determine if there are any humans left humans_left = [ rp for rp in self.ctx.room.remote_participants.values() if rp.kind != rtc.ParticipantKind.PARTICIPANT_KIND_AGENT ] print("PARTICIPANTS:") print(self.ctx.room.remote_participants.values()) if not humans_left: logger.info( "Lifecycle: Candidate disconnected. Starting departure timeout." ) self.is_candidate_connected = False self._cancel_task("candidate_inactivity_task") logger.info("STARTING TIME . SLEEP") for i in range(0, 100): print(i) # making delay for 1 second time.sleep(1) logger.info("END TIME . SLEEP")
t
You're on the right track — your code filters participants by
kind
to find humans. To explicitly check for any agent participants, test whether any remote participant has
kind == rtc.ParticipantKind.PARTICIPANT_KIND_AGENT
. Suggested minimal change (keeps your structure):
Copy code
def on_participant_disconnected(self, p: rtc.RemoteParticipant) -> None:
    # list humans
    humans_left = [
        rp
        for rp in self.ctx.room.remote_participants.values()
        if rp.kind != rtc.ParticipantKind.PARTICIPANT_KIND_AGENT
    ]

    # check for agents
    agents_present = any(
        rp.kind == rtc.ParticipantKind.PARTICIPANT_KIND_AGENT
        for rp in self.ctx.room.remote_participants.values()
    )

    print("PARTICIPANTS:", list(self.ctx.room.remote_participants.values()))
    print("Agents present:", agents_present)

    if not humans_left:
        logger.info("Lifecycle: Candidate disconnected. Starting departure timeout.")
        self.is_candidate_connected = False
        self._cancel_task("candidate_inactivity_task")

        # If an agent is present, departure_timeout should NOT be started.
        if agents_present:
            logger.info("Agent still present — not starting departure timeout.")
            return

        logger.info("STARTING TIME . SLEEP")
        for i in range(0, 100):
            print(i)
            time.sleep(1)
        logger.info("END TIME . SLEEP")
Notes: •
agents_present
explicitly prevents starting the departure timeout when any agent remains. •
self.ctx.room.remote_participants
should reflect current participants; ensure you update state on connect/disconnect events. • If participant
kind
can be missing or different, add a safe check:
getattr(rp, "kind", None) == ...
. Would you like this adapted to use async sleep or to run the timeout in a cancellable background task?