Skip to main content

Overview

Run cancellation lets you abort an agent mid-execution using the standard AbortSignal API. The signal is checked at the start of each LLM roundtrip and before tool execution.

Quick Start

Cancellation Points

The signal is checked at three points in the execution loop:
  1. Before each LLM call — prevents starting a new API request
  2. Before tool execution — prevents running tools after cancellation
  3. At run start — immediately returns if already aborted

Output on Cancellation

When a run is cancelled, it returns a RunOutput with:

Events

The run.cancelled event is emitted on cancellation:

Error Class

You can import RunCancelledError for custom handling:

HTTP API Cancellation

When using the transport layer, you can implement cancellation via request timeouts or client disconnects by wiring AbortSignal in your middleware.