Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def __init__(
builtin_type[Any] | types.UnionType, Callable[[Any, WorkflowContext[Any, Any]], Awaitable[None]]
] = {}
self._handler_specs: list[dict[str, Any]] = []
self._response_handler_specs: list[dict[str, Any]] = []
if not defer_discovery:
self._discover_handlers()

Expand Down Expand Up @@ -465,7 +466,7 @@ def output_types(self) -> list[type[Any] | types.UnionType]:
output_types: set[type[Any] | types.UnionType] = set()

# Collect output types from all handlers
for handler_spec in self._handler_specs + self._response_handler_specs:
for handler_spec in self._handler_specs + getattr(self, "_response_handler_specs", []):
handler_output_types = handler_spec.get("output_types", [])
output_types.update(handler_output_types)

Expand All @@ -481,7 +482,7 @@ def workflow_output_types(self) -> list[type[Any] | types.UnionType]:
output_types: set[type[Any] | types.UnionType] = set()

# Collect workflow output types from all handlers
for handler_spec in self._handler_specs + self._response_handler_specs:
for handler_spec in self._handler_specs + getattr(self, "_response_handler_specs", []):
handler_workflow_output_types = handler_spec.get("workflow_output_types", [])
output_types.update(handler_workflow_output_types)

Expand Down
25 changes: 25 additions & 0 deletions python/packages/core/tests/workflow/test_request_info_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,31 @@ async def handle_str_int(self, original_request: str, response: int, ctx: Workfl
# Should return False when _response_handlers attribute doesn't exist
assert executor.is_request_supported(str, int) is False
assert executor.is_request_supported(dict[str, Any], bool) is False
assert executor.input_types == []
assert executor.output_types == []
assert executor.workflow_output_types == []

def test_executor_output_types_before_discovery(self):
"""Test that output_types and workflow_output_types return empty lists before discovery."""

class DeferredExecutor(Executor):
def __init__(self):
super().__init__(id="deferred_executor", defer_discovery=True)

@handler
async def handle_str(self, message: str, ctx: WorkflowContext[int, float]) -> None:
pass

executor = DeferredExecutor()
assert executor.input_types == []
assert executor.output_types == []
assert executor.workflow_output_types == []

# After discovering handlers, types should be populated
executor._discover_handlers()
assert executor.input_types == [str]
assert executor.output_types == [int]
assert executor.workflow_output_types == [float]

def test_is_request_supported_with_compatible_types(self):
"""Test is_request_supported with type-compatible scenarios."""
Expand Down
Loading