-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Python: Add explicit input_type and output_type parameters to @handler and @executor decorators #3472
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
base: main
Are you sure you want to change the base?
Conversation
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 pull request adds explicit input_type and output_type parameters to the @handler and @executor decorators in the Python workflow framework. These optional parameters allow developers to specify types explicitly instead of relying on type introspection from function signatures, with explicit types taking precedence over introspected types. The feature supports union types via both str | int and Union[str, int] syntax.
Changes:
- Added
normalize_type_to_listutility function to convert union types to lists - Enhanced
@handlerand@executordecorators with optionalinput_typeandoutput_typeparameters - Modified signature validation functions to support skipping message annotation when explicit types are provided
- Added comprehensive test coverage for explicit type parameters
- Updated sample code to demonstrate the new feature
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
python/packages/core/agent_framework/_workflows/_typing_utils.py |
Added normalize_type_to_list utility function for handling union types; changed logger import pattern |
python/packages/core/agent_framework/_workflows/_executor.py |
Enhanced @handler decorator with input_type and output_type parameters; updated handler validation logic; refactored exception handling in _discover_handlers |
python/packages/core/agent_framework/_workflows/_function_executor.py |
Enhanced @executor decorator and FunctionExecutor class with explicit type parameters; updated function validation logic |
python/packages/core/tests/workflow/test_typing_utils.py |
Added comprehensive tests for normalize_type_to_list function covering single types, union types, and optional types |
python/packages/core/tests/workflow/test_executor.py |
Added comprehensive test suite for @handler with explicit types, covering precedence, union types, and partial specifications |
python/packages/core/tests/workflow/test_function_executor.py |
Added comprehensive test suite for @executor with explicit types, covering various edge cases and usage patterns |
python/samples/getting_started/workflows/_start-here/step1_executors_and_edges.py |
Added documentation and example demonstrating explicit type parameters with a new ExclamationAdder executor |
Motivation and Context
input_type,output_type, andworkflow_output_typeparameters to@handlerand@executordecoratorsstr | intandUnion[str, int]syntaxnormalize_type_to_listutility for converting union types to listsExample
Description
See above.
Contribution Checklist