From 4fb1ecc019528ed67e73e7278f0a1551f943b970 Mon Sep 17 00:00:00 2001 From: Aditya-XR Date: Tue, 22 Sep 2026 23:31:08 +0530 Subject: [PATCH] fix(python): treat Any as compatible with any target type is_type_compatible() only handled Any as a target, so an executor declaring WorkflowContext[Any] could not be connected to a typed executor and workflow build failed with TypeCompatibilityError. --- .../core/agent_framework/_workflows/_typing_utils.py | 5 +++++ .../packages/core/tests/workflow/test_typing_utils.py | 4 ++++ python/packages/core/tests/workflow/test_validation.py | 10 ++++++++++ 3 files changed, 19 insertions(+) diff --git a/python/packages/core/agent_framework/_workflows/_typing_utils.py b/python/packages/core/agent_framework/_workflows/_typing_utils.py index 251441144fb..6496716f1ec 100644 --- a/python/packages/core/agent_framework/_workflows/_typing_utils.py +++ b/python/packages/core/agent_framework/_workflows/_typing_utils.py @@ -471,6 +471,11 @@ def is_type_compatible(source_type: type | UnionType | Any, target_type: type | if target_type is Any: return True + # Case 0b: source_type is Any - the value can be of any type, so it is compatible with every + # target, the same way static type checkers treat Any. + if source_type is Any: + return True + # Case 1: exact type match if source_type == target_type: return True diff --git a/python/packages/core/tests/workflow/test_typing_utils.py b/python/packages/core/tests/workflow/test_typing_utils.py index df08120282c..805ad197107 100644 --- a/python/packages/core/tests/workflow/test_typing_utils.py +++ b/python/packages/core/tests/workflow/test_typing_utils.py @@ -425,6 +425,10 @@ def test_type_compatibility_basic() -> None: # Any compatibility assert is_type_compatible(str, Any) assert is_type_compatible(list[int], Any) + assert is_type_compatible(Any, str) + assert is_type_compatible(Any, list[int]) + assert is_type_compatible(Any, Union[str, int]) + assert is_type_compatible(list[Any], list[str]) # Subclass compatibility class Animal: diff --git a/python/packages/core/tests/workflow/test_validation.py b/python/packages/core/tests/workflow/test_validation.py index c2f85614c85..5798c5ec778 100644 --- a/python/packages/core/tests/workflow/test_validation.py +++ b/python/packages/core/tests/workflow/test_validation.py @@ -121,6 +121,16 @@ def test_type_compatibility_with_any_type_passes(): assert workflow is not None +def test_type_compatibility_from_any_source_passes(): + """An executor declaring WorkflowContext[Any] can send to a typed executor.""" + any_executor = AnyExecutor(id="any_executor") + string_executor = StringExecutor(id="string_executor") + + workflow = WorkflowBuilder(start_executor=any_executor).add_edge(any_executor, string_executor).build() + + assert workflow is not None + + def test_type_compatibility_with_no_output_types(): no_output_executor = NoOutputTypesExecutor(id="no_output") string_executor = StringExecutor(id="string_executor")