-
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
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 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 |
| from agent_framework import get_logger | ||
|
|
||
| logger = get_logger("agent_framework._workflows._typing_utils") | ||
|
|
Copilot
AI
Jan 28, 2026
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.
The logger is defined but never used in this file. The original code removed import logging and added get_logger, but there are no calls to logger.debug(), logger.info(), etc. anywhere in this file. This adds unnecessary imports and creates an unused variable. Consider removing the logger import and variable definition, or keep the original import logging if it might be needed in the future.
| from agent_framework import get_logger | |
| logger = get_logger("agent_framework._workflows._typing_utils") |
| async def handle_custom(self, message: Any, ctx: WorkflowContext[str]) -> None: | ||
| ... | ||
| """ | ||
| from ._typing_utils import normalize_type_to_list |
Copilot
AI
Jan 28, 2026
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.
The import of normalize_type_to_list is done locally inside the decorator function, while is_instance_of from the same module is imported at the top of the file (line 24). For consistency and clarity, both imports should be at the module level unless there's a specific reason for a local import (such as avoiding circular dependencies, which doesn't appear to be the case here). Consider moving this import to the top of the file alongside the other import from _typing_utils.
Motivation and Context
input_typeandoutput_typeparameters to@handlerand@executordecoratorsstr | intandUnion[str, int]syntaxnormalize_type_to_listutility for converting union types to listsExample
Description
See above.
Contribution Checklist