on_exit

View as MarkdownOpen in Claude

Lifecycle hook called when the agent exits a session. Override in a subclass to run cleanup logic when the agent’s session ends.

Parameters

None.

Returns

None

Example

from signalwire.livewire import Agent, AgentSession, AgentServer, JobContext, run_app
server = AgentServer()
class TrackedAgent(Agent):
async def on_exit(self):
print("Agent session has ended, running cleanup.")
@server.rtc_session()
async def entrypoint(ctx: JobContext):
await ctx.connect()
agent = TrackedAgent(instructions="You are a helpful assistant.")
session = AgentSession()
await session.start(agent, room=ctx.room)
run_app(server)