> This page is for Server SDKs.

> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# on_exit

> Lifecycle hook called when the agent exits a session.

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**

```python {6}
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)
```