const running = agent.run({ message: "…" });
setTimeout(() => agent.stop(), 30_000);
const result = await running; // stopReason: "stopped"import threading
threading.Timer(30, agent.stop).start()
result = agent.run(message="…") # stopReason: "stopped"What it does
- 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
The retry and fallback logic checks for it: trying again is the opposite of what was asked.
The conversation is kept
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() on a running agent throws agent_running. Stop it first — cutting a conversation while it is being written to is not something to attempt.