Canceling an agent run is not equivalent to undoing everything that happened during it. A background task may have sent an email, updated a database or initiated a payment before the cancellation request arrives. Cancellation therefore needs explicit semantics for pending, active and completed side effects.
How it works
Temporal’s developer documentation exposes workflow cancellation alongside timeouts, activities and child workflows. The broader principle is cooperative cancellation: a request can stop future work, but an already-running external call may complete before its worker notices. Design run state to differentiate requested cancellation, halted execution, unresolved side effects and confirmed compensation. A canceled agent conversation should not erase durable business history.
A practical, bounded workflow
Imagine an agent preparing and dispatching a purchase-order request. Its plan has three steps: validate the request, obtain approver confirmation and call a supplier API. If a cancellation arrives before the approval, exit without sending. If it arrives after the supplier accepted the order but before the response was recorded, query the supplier using a stable business reference; do not blindly retry and do not report the order canceled. Add a separate authorized cancellation or refund process if the external API supports it.
Failure modes and limits
Cancellation signals can race with worker crashes, lease expiration and delayed webhooks. Distinguish a task timed out while waiting from a task whose remote operation is still in flight. Require handlers to checkpoint their action IDs and results before moving to the next step. When the downstream service does not expose a reliable read-after-write endpoint, escalate the ambiguous state instead of assuming a safe rollback.
Deployment controls
Assign responsibility for each transition: scheduled, running, awaiting evidence, awaiting approval, writing, reconciled, canceled or unresolved. The controller, not a free-form language response, decides whether a next action is authorized. Persist operation IDs and deadlines so a restart does not erase obligations or repeat committed effects.
When to choose this approach
For short stateless work, a deadline and straightforward abort may suffice. Durable orchestration is appropriate when side effects span minutes, multiple systems or human approvals. Never give a language model autonomous authority to decide whether a refund is owed; that determination belongs to authoritative transaction rules.
What to evaluate before production
Inject cancellation before dispatch, during a slow response, immediately after a remote commit and during compensation. For every test, assert one eventual external result, consistent ledger state, an operator-visible unresolved flag when necessary and no repeated charge or email. Measure time until no new actions start rather than counting canceled transcripts.
Version, market and tier caution (25 October 2026): This is a technical and operational guide, not a live entitlement, pricing or geographic-availability certification. Numeric commercial limits and undocumented release dates are intentionally omitted. Reconfirm the exact account, deployment region, access policy and vendor release before procurement or publication.