Python: Improve error message when TypeVar is used in handler registration#4553
Open
ogkranthi wants to merge 2 commits intomicrosoft:mainfrom
Open
Python: Improve error message when TypeVar is used in handler registration#4553ogkranthi wants to merge 2 commits intomicrosoft:mainfrom
ogkranthi wants to merge 2 commits intomicrosoft:mainfrom
Conversation
…ation Fixes microsoft#4547. Adds early detection of unresolved TypeVar instances in: - @handler decorator (both explicit and introspected type paths) - @executor decorator (both explicit and introspected type paths) - WorkflowContext type argument validation (direct and union members) When a TypeVar is detected, a clear ValueError is raised with actionable guidance to use concrete types via @handler(input=ConcreteType, output=ConcreteType).
Member
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
Adds earlier, more actionable validation errors when unresolved TypeVar objects are used in workflow handler/executor registration, aiming to fail fast (during registration) rather than later during workflow edge/type validation.
Changes:
- Add
TypeVardetection in@handlerregistration for both explicit decorator parameters and introspected annotations. - Add
TypeVardetection inFunctionExecutorregistration for both explicit decorator parameters and introspected annotations. - Add
TypeVardetection inWorkflowContext[...]generic argument validation, including union members.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| python/packages/core/agent_framework/_workflows/_workflow_context.py | Adds early TypeVar checks for WorkflowContext type arguments (direct + union members) to raise clearer ValueErrors. |
| python/packages/core/agent_framework/_workflows/_function_executor.py | Adds early TypeVar checks for @executor registration (explicit params + introspected message type). |
| python/packages/core/agent_framework/_workflows/_executor.py | Adds early TypeVar checks for @handler registration (explicit params + introspected message type). |
You can also share your feedback on Copilot code review. Take the survey.
Author
|
@copilot open a new pull request to apply changes based on the comments in this thread |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TypeVarinstances during handler/executor registration, surfacing a clearValueErrorwith actionable guidance instead of a confusingTypeCompatibilityErrorat edge validation time@handler,@executor, andWorkflowContext[T]type argument validation (both direct and union members)Fixes #4547
Changes
_executor.py— TypeVar check in@handlerdecorator for both explicit type params and introspected annotation paths_function_executor.py— TypeVar check inFunctionExecutor.__init__for both explicit and introspected paths_workflow_context.py— TypeVar check invalidate_workflow_context_annotationfor direct type args and union membersTest plan
@handler(input=SomeTypeVar)raisesValueErrorwith actionable messageTypeVarannotation (introspection path) raisesValueError@executor(input=SomeTypeVar)raisesValueErrorWorkflowContext[SomeTypeVar]raisesValueError