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
- Identify cancellation sources such as a stop button, request deadline, or closed SSE connection. [abort]
- Pass
asyncio.Event()asabort_signaltorunner.run_async(..., abort_signal=signal)and callsignal.set()when the user stops. [abort] - Poll
ctx.is_abortedin long synchronous loops; the SDK cancels child tasks, seals pending tool calls, and ends with an abort event. [abort] - 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
- Python 3.11+, google-adk compatible with the pinned revision, and an isolated test environment
- Configured model-provider credentials for live inference; never place them in code or logs
Permissions
- Use authorized test data only; isolate sessions and credentials per user; obtain human authorization before external side effects
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
- 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