# stop()

Canonical URL: https://developers.iagenify.com/sdk/ref/local-agent/stop/
Language: en

`agent.stop()`

Ends the current run. The model request in flight is aborted, queued tool calls do not start, and subagents stop with it.

Status: synchronous · stops children · stopReason: stopped

```javascript
const running = agent.run({ message: "…" });

setTimeout(() => agent.stop(), 30_000);

const result = await running;     // stopReason: "stopped"
```

## What it does {#what}

- Aborts the model request in flight.
- Sets the flag the loop reads at the top of each step.
- Makes queued calls in a sequential turn answer « Stopped by the user. » rather than run.
- Stops every subagent.

> **A tool already running finishes**
>
> A command in progress, a file being written, a parallel batch already in flight — none of it is interrupted mid-way. Stopping is clean, not immediate.

## A stopped run is never retried {#no-retry}

The retry and fallback logic checks for it: trying again is the opposite of what was asked.

## The conversation is kept {#state}

Everything up to the stop stays in the agent and, in a session, on the account. Calling `run()` again continues from there.

## Stop before rewinding {#rewind}

`rewind()` on a running agent throws `agent_running`. Stop it first — cutting a conversation while it is being written to is not something to attempt.

- [rewind()](/sdk/ref/local-agent/rewind): What needs a stopped agent.
- [The loop](/sdk/agent/loop): Where the flag is read.

```python
import threading

threading.Timer(30, agent.stop).start()

result = agent.run(message="…")    # stopReason: "stopped"
```
