Skip to main content
This guide covers how to cancel runs for your agent via the LangSmith Deployment API. You can cancel a single run by ID or cancel multiple runs by thread or status. Cancellation is useful for stopping long-running or stuck runs, or when a user abandons a request.

Setup

Create a client and thread:

Cancel a single run

The following examples create a run, cancel it with different options, and print the run to show what you get in each case. You can cancel runs in pending or running status. Trying to cancel a run that is not in pending or running status will result in an error.

Cancel with interrupt (default)

interrupt stops the worker executing the run and marks the run as interrupted. Nothing is deleted:
  • The run record remains (with status interrupted). You can fetch it, inspect inputs/outputs, and see the execution history.
  • All checkpoints for that run remain stored. The thread state at the last completed step is preserved.
  • You can later resume from a checkpoint (for example, with time travel) or inspect the partial state.
Use interrupt when you want to stop a run but keep it for debugging, auditing, or resuming from a checkpoint.

Cancel with rollback

rollback stops the run and then removes it and its checkpoints from storage:
  • The run record is deleted. The run no longer appears in run lists or history for that thread.
  • All checkpoints created by that run are deleted. The thread’s state is reverted to what it was before the run started (as if the run had never been executed).
  • You cannot resume or inspect the run after a rollback.
Use rollback when you want to fully discard a run and its effects (for example, after a user abandons a request and you do not need to keep partial work).

Cancel with wait

By default, the cancel request returns after the cancellation is requested and the run is cancelled asynchronously. wait=True makes the cancel request block until the run has been fully cancelled. This is useful when you want to know the final state of the run after it has been cancelled (e.g., what checkpoints were created, what the final output was).

Cancel multiple runs

Use the bulk cancel endpoint to cancel multiple runs in one request. Both the interrupt and rollback actions are supported.

Cancel by thread ID and run IDs

Cancel specific runs by passing their IDs.

Cancel by status

Cancel all runs that match a status across all threads in a deployment. Valid status options are pending, running, or all.

Cancel on disconnect

When starting a run with streaming or when waiting on a run, you can set on_disconnect="cancel" so that the run is cancelled if the client disconnects. This avoids leaving runs in progress when a user closes the app or loses connection.

Common scenarios

  • Human-in-the-loop and interrupts: Agents can pause at interrupts for human input. Cancelling a run stops execution; it is different from an interrupt, where the run is paused and can be resumed with new input.
  • Time travel: After cancelling with action interrupt, the run and checkpoints are still available. You can resume from a checkpoint (time travel) to replay or branch execution.
  • Double-texting: When a user sends new input while a run is in progress, the multitask strategy (enqueue, reject, interrupt, rollback) determines whether the existing run is interrupted or rolled back and how the new run is handled. To cancel runs explicitly from your application, use the cancel API described on this page.
  • Studio: In Studio, use the Cancel button in the run UI to cancel the current run.