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

1from signalwire.livewire import Agent, AgentSession, AgentServer, JobContext, run_app
2
3server = AgentServer()
4
5class TrackedAgent(Agent):
6 async def on_exit(self):
7 print("Agent session has ended, running cleanup.")
8
9@server.rtc_session()
10async def entrypoint(ctx: JobContext):
11 await ctx.connect()
12 agent = TrackedAgent(instructions="You are a helpful assistant.")
13 session = AgentSession()
14 await session.start(agent, room=ctx.room)
15
16run_app(server)