Agent Wealth HubFree public resources
中文 EN العربية

Back to catalog / Agent reliability

Stop an agent run when the user cancels or the client disconnects

Pass a client cancellation signal to the Runner so long tools or workflow nodes stop and the event stream closes cleanly.

Goal

Stop computation when the user is no longer waiting, reducing waste and preventing later side effects.

Steps

  1. Identify cancellation sources such as a stop button, request deadline, or closed SSE connection. [abort]
  2. Pass asyncio.Event() as abort_signal to runner.run_async(..., abort_signal=signal) and call signal.set() when the user stops. [abort]
  3. Poll ctx.is_aborted in long synchronous loops; the SDK cancels child tasks, seals pending tool calls, and ends with an abort event. [abort]
  4. Test normal completion, client disconnect, and mid-run cancellation; verify session history remains valid. [abort]

How to verify

Cancellation ends the stream cleanly with an `INVOCATION_ABORTED` event when no tool call is pending, or a synthetic response for dangling calls; the session remains usable.

Troubleshooting

If a tool keeps running, propagate cancellation into downstream I/O; add safe checkpoints for non-cancellable actions.

Permissions

Prerequisites

Permissions

Limitations

This procedure follows Google ADK at the pinned revision; other versions, models, or remote services may differ in APIs and event semantics. Recheck permissions, retention, and recovery before production.

Pinned upstream source

https://github.com/google/adk-python/blob/e9b74d36140f2594b24c481fb7a3825b2cb01e96/docs/guides/runners/runner/abort.md

Repository
google/adk-python
File path
docs/guides/runners/runner/abort.md
Pinned commit
e9b74d36140f2594b24c481fb7a3825b2cb01e96
Source checked
2026-10-14 · Reviewed against the pinned upstream source

Repository metrics

These values describe the upstream repository, not popularity or likes for an individual skill or playbook.

Stars
Not collected
Forks
Not collected
Observed at
Not collected

No metrics snapshot is available yet.

License: Apache-2.0

Main topic

Turn ecommerce campaign materials into a reviewable weekly brief

Related resources