Skip to content

Conversation

@TaoChenOSU
Copy link
Contributor

@TaoChenOSU TaoChenOSU commented Jan 12, 2026

Motivation and Context

Addresses #695

Workflows have been using very generic exception types (RuntimeError or ValueError) and users must heavily rely on exception messages to distinguish different types of exceptions.

Description

This PR sets up a new _exceptions module for us to add more specific exceptions to Workflows.
This PR adds the following to start:

  • WorkflowException
  • WorkflowRunnerException
  • WorkflowConvergenceException
  • WorkflowCheckpointException

This PR also fixes a less obvious issue in the runner: the runner no longer resets the iteration counts after converging. Reset is purely driven externally now, via reset_iteration_count. This makes sure that if the workflow converges because it's waiting for responses for requests, the runner maintains its iteration count.

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.

@TaoChenOSU TaoChenOSU self-assigned this Jan 12, 2026
Copilot AI review requested due to automatic review settings January 12, 2026 23:26
@TaoChenOSU TaoChenOSU added the workflows Related to Workflows in agent-framework label Jan 12, 2026
@TaoChenOSU TaoChenOSU moved this to In Review in Agent Framework Jan 12, 2026
@github-actions github-actions bot changed the title Add more specific exceptions to Workflow Python: Add more specific exceptions to Workflow Jan 12, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Jan 12, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework/_workflows
   _exceptions.py90100% 
   _runner.py2133284%124–125, 165–168, 172, 213–215, 240–241, 243, 278–280, 304–308, 312, 347, 351, 353, 359, 367–370, 383, 423
   _runner_context.py166696%78, 81, 377, 397, 485, 489
   _workflow.py2471793%88, 258–260, 262–263, 281, 309, 410, 687, 721, 726, 729, 748–750, 815
TOTAL16801252085% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3031 207 💤 0 ❌ 0 🔥 1m 4s ⏱️

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 introduces a new exception hierarchy for workflows to replace generic RuntimeError and ValueError exceptions with more specific exception types. The changes enable users to catch and handle workflow-specific errors more precisely.

Changes:

  • Added new _exceptions.py module with WorkflowException, WorkflowRunnerException, WorkflowConvergenceException, and WorkflowCheckpointException
  • Updated _runner.py to use new exception types for convergence and checkpoint errors, and changed restore_from_checkpoint to raise exceptions instead of returning boolean
  • Removed iteration count reset after convergence (preserves iteration count for inspection)
  • Updated all related tests to expect the new exception types

Reviewed changes

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

Show a summary per file
File Description
python/packages/core/agent_framework/_workflows/_exceptions.py New module defining the workflow exception hierarchy
python/packages/core/agent_framework/_workflows/_runner.py Updated to use new exception types; changed restore_from_checkpoint to raise exceptions; removed iteration reset
python/packages/core/agent_framework/_workflows/_workflow.py Simplified checkpoint restoration error handling by removing boolean check
python/packages/core/agent_framework/_workflows/__init__.py Added exports for new exception types
python/packages/core/tests/workflow/test_workflow.py Updated tests to expect WorkflowConvergenceException and WorkflowCheckpointException; formatting improvements
python/packages/core/tests/workflow/test_runner.py Updated tests to expect new exception types; added test for iteration count preservation
python/packages/core/tests/workflow/test_magentic.py Updated tests to expect WorkflowCheckpointException; formatting improvements
python/packages/core/tests/workflow/test_checkpoint_validation.py Updated test to expect WorkflowCheckpointException

@TaoChenOSU TaoChenOSU enabled auto-merge January 14, 2026 20:00
@TaoChenOSU TaoChenOSU added this pull request to the merge queue Jan 14, 2026
Merged via the queue into microsoft:main with commit 6c956ec Jan 14, 2026
23 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in Agent Framework Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python workflows Related to Workflows in agent-framework

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants