agents icon indicating copy to clipboard operation
agents copied to clipboard

How to post-process cleanup at time of room completion?

Open yuyuma opened this issue 9 months ago • 1 comments

We're in amidst of migrating our v0 code to v1. Our use case involves a possible warm SIP handoff while removing the AI agent so we end up with a Human + Human interaction.

In v0, the shutdown hook that we register doesn't trigger at time of Agent removal. It only triggers when the room is removed by Livekit due to 0 participants or if we forcibly delete the room. This was desirable as we run some clean up code after.

In v1, the shutdown hook triggers when the Agent is removed from the room. This seems to be intended behavior based on the description here https://docs.livekit.io/agents/worker/job/#post-processing-and-cleanup. But as soon as this happens (e.g. when we have 2 human participants left in the room), we seem to lose all further control.

  1. Our ctx.room.on("participant_disconnected") hook ceases to be triggered when one or both of the human participants leave the room.
  2. The documentation at https://docs.livekit.io/agents/worker/job/#disconnecting-everyone implies that we can register a ctx.room.on("disconnected") hook to perform cleanup when the room is removed. I poked around (and might very well be wrong) but can't seem to find anything indicating where this is emitted in the agents framework and given point 1 above unsure whether it would fire even if implemented.

Would appreciate any guidance.

yuyuma avatar Apr 18 '25 01:04 yuyuma

Related slack discussion: https://livekit-users.slack.com/archives/C07FY8WHGPM/p1745063954228409?thread_ts=1745063954.228409&cid=C07FY8WHGPM

yuyuma avatar Apr 19 '25 21:04 yuyuma