Skip to content

Conversation

@victordibia
Copy link
Contributor

@victordibia victordibia commented Dec 9, 2025

Motivation and Context

Add sample demonstrating how to cancel a running workflow using asyncio
tasks. Shows both cancellation mid-execution and normal completion paths.
Useful for implementing timeouts, graceful shutdown, or A2A executors, or cancellation from web app interfaces.

Added this based on a dev request on "how to cancel workflows"

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Add sample demonstrating how to cancel a running workflow using asyncio
tasks. Shows both cancellation mid-execution and normal completion paths.
Useful for implementing timeouts, graceful shutdown, or A2A executors.
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python labels Dec 9, 2025
@victordibia victordibia marked this pull request as ready for review December 9, 2025 19:13
Copilot AI review requested due to automatic review settings December 9, 2025 19:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new Python sample demonstrating workflow cancellation using asyncio tasks. The sample shows how to gracefully cancel a running workflow mid-execution as well as how to run a workflow to completion, providing a practical pattern for implementing timeouts, graceful shutdown, or cancellation support in agent-to-agent executors.

Key Changes:

  • New workflow cancellation sample with clear demonstration of both cancellation and completion scenarios
  • Three-step sequential workflow with timing designed to show mid-execution cancellation
  • Documentation update in README.md to reference the new sample

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
python/samples/getting_started/workflows/control-flow/workflow_cancellation.py New sample demonstrating workflow cancellation using asyncio.create_task() and task.cancel() patterns, with both cancellation and completion execution paths
python/samples/getting_started/workflows/README.md Added reference to the new workflow cancellation sample in the control-flow section

@percebus
Copy link

percebus commented Dec 9, 2025

thx for the quick turn-around!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants