---
title: ".stop()"
description: "Close the agent and every initialized resource safely."
---

> Documentation Index
> Fetch the complete documentation index at: https://xsaf.ilha.build/llms.txt
> Use this file to discover all available pages before exploring further.

# .stop()

## Signature

```ts
agent.stop(): Promise<void>
agent.stop(): Promise<void>
```

## Usage

```ts
await agent.start();

try {
  await agent.invoke("Do the work");
} finally {
  await agent.stop();
}
```

`.stop()` is asynchronous and idempotent. Concurrent calls coalesce, and shutdown waits for an in-progress startup operation.

Resources close sequentially in reverse declaration order. XSAF attempts every close callback even when one fails. Multiple shutdown failures are returned together as an `AggregateError`.

Channels, memory, delegates, MCP drivers, scheduler resources, and serving drivers participate in the same lifecycle. Register process signal handlers in the host application when it owns a long-running listener.

Source: https://xsaf.ilha.build/xsaf/stop/index.mdx
