Skip to main content
The Cancel Run feature allows you to cancel a running agent execution and later resume it from exactly where it left off. This is useful for implementing timeouts, user-initiated cancellations, or graceful shutdown handling.

Quick Start

Core API

cancel_run(run_id: str)

Cancels a running agent execution by its run ID. The agent will stop at the next checkpoint and save its current state.

agent.run_id

During execution, access the current run’s ID via agent.run_id. This is available as soon as the run starts.

output.is_cancelled

Check if a run was cancelled by inspecting the output:

output.status

Access the full status enum:

Continuation Methods

Resume with run_id (Same Agent)

The simplest approach - use the same agent instance with run_id:

Resume with task (Same Agent)

Use the task object for in-memory context continuation:

Resume with run_id (New Agent - Cross-Process)

For cross-process resumption where a new agent instance loads the cancelled run from storage:

Resume with task (New Agent - Cross-Process)

New agent using task object for continuation:

Advanced Patterns

Verify Resume from Cut-off Point

Verify that resumption continues from where execution left off, not from the beginning:

Important Notes

  • Direct Call Mode Only: HITL continuation only supports direct call mode. Streaming mode is not supported for continuation.
  • Persistent Storage: For cross-process resumption, always use persistent storage like SqliteDatabase.
  • Run ID Availability: The agent.run_id is available as soon as execution begins.
  • State Preservation: The agent saves its state at checkpoints, so resumption continues from the last completed step.