fierce-jordan-44682
09/28/2025, 5:50 AMtall-airline-16756
09/28/2025, 5:50 AMtall-airline-16756
09/28/2025, 5:51 AMon_exit node for a LiveKit agent is called right before the agent hands over control to another agent within the same session. This usually happens during an agent handoff or transition, which can be done either manually through workflow logic or programmatically using tools like llm.handoff().
It's important to note that this doesn’t get triggered when the session itself ends—only when the agent is being replaced by another agent during the ongoing session. People often use it for tasks like cleanup, saving data, or even generating a friendly final message like "Goodbye!" before exiting. I hope this helps clarify things for you!
Sources: Pipeline nodes and hooks | LiveKit Docs | Docs::Agents | README.md | livekit-agents/livekit/agents/voice/agent_session.py | docs/index.yamlfierce-jordan-44682
09/28/2025, 5:52 AMtall-airline-16756
09/28/2025, 5:52 AMon_exit node isn’t quite meant for that since it’s triggered during agent handoffs within the same session. But don’t worry, there are some great alternatives you can try:
• Explicitly generate a message before closing the session: You can use self.session.generate_reply() or self.session.say() to warmly deliver a final message right before calling session termination methods like self.session.aclose() or deleting the room.
• Use the session.on("close") event handler: By registering a callback for the "close" event, you can handle any post-processing, just keep in mind the message needs to be spoken before the session actually closes.
• Use shutdown callbacks: For cleanup or other tasks after the session ends, ctx.add_shutdown_callback() is a handy tool.
If you’d like, I’m more than happy to walk you through an example implementation to make sure your final message is delivered before the room closes. Just let me know!
Sources: Docs::Agents | Pipeline nodes and hooks | LiveKit Docs | main.py | livekit-agents/livekit/agents/inference/stt.py | Docs::Agentsfierce-jordan-44682
09/28/2025, 5:55 AMsession.on("close") event handler: By registering a callback for the "close" event, you can handle any post-processing, just keep in mind the message needs to be spoken before the session actually closes.
How do i ensure the message is spoken before i close the session??
Currently, how do i enforce such that the agent session is able to close the session after the time limit has reached?tall-airline-16756
09/28/2025, 5:55 AM