Overview
Run cancellation lets you abort an agent mid-execution using the standardAbortSignal 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:- Before each LLM call — prevents starting a new API request
- Before tool execution — prevents running tools after cancellation
- At run start — immediately returns if already aborted
Output on Cancellation
When a run is cancelled, it returns aRunOutput with:
Events
Therun.cancelled event is emitted on cancellation:
Error Class
You can importRunCancelledError for custom handling:
HTTP API Cancellation
When using the transport layer, you can implement cancellation via request timeouts or client disconnects by wiringAbortSignal in your middleware.