-
Notifications
You must be signed in to change notification settings - Fork 1k
Python: Add more specific exceptions to Workflow #3188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python: Add more specific exceptions to Workflow #3188
Conversation
Python Test Coverage Report •
Python Unit Test Overview
|
|||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this 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.pymodule withWorkflowException,WorkflowRunnerException,WorkflowConvergenceException, andWorkflowCheckpointException - Updated
_runner.pyto use new exception types for convergence and checkpoint errors, and changedrestore_from_checkpointto 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 |
Motivation and Context
Addresses #695
Workflows have been using very generic exception types (
RuntimeErrororValueError) and users must heavily rely on exception messages to distinguish different types of exceptions.Description
This PR sets up a new
_exceptionsmodule for us to add more specific exceptions to Workflows.This PR adds the following to start:
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