Repository navigation
Python: Adding support for nested workflows - #460
Conversation
…oExecutor, going to make a change to remove that restrivtion.
There was a problem hiding this comment.
Pull Request Overview
This PR introduces hierarchical workflow composition through sub-workflows, enabling workflows to execute other workflows as executors within their execution graph. The implementation includes support for external request interception, where parent workflows can intercept and handle sub-workflow requests before they reach external services.
Key changes:
- Sub-workflow execution: New
WorkflowExecutorclass wraps workflows to make them behave as executors - Request interception:
@intercepts_requestdecorator allows parent workflows to conditionally handle or forward requests from sub-workflows - Message routing infrastructure: Automatic routing between parent and sub-workflows via
SubWorkflowRequestInfoandSubWorkflowResponsemessage types
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
subflow_design.md |
Comprehensive design document analyzing 6 implementation approaches for sub-workflows |
python/samples/getting_started/workflow/ |
Three sample files demonstrating basic sub-workflows, request interception, and simple composition patterns |
python/packages/workflow/tests/ |
Unit tests covering sub-workflow functionality, request interception, and edge cases |
python/packages/workflow/examples/ |
Complete working example showing email validation with domain checking |
agent_framework_workflow/_executor.py |
Core implementation of WorkflowExecutor, request interception decorators, and message types |
agent_framework_workflow/_runner.py |
Message routing logic for handling sub-workflow requests and responses |
agent_framework_workflow/_workflow.py |
Workflow modifications to support RequestInfoExecutor discovery |
agent_framework_workflow/_validation.py |
Validation updates for single-executor workflows and interceptor output types |
docs/design/sub_workflows_guide.md |
Comprehensive user guide with examples and best practices |
Comments suppressed due to low confidence (2)
python/packages/workflow/agent_framework_workflow/_executor.py:149
- This assignment inside the loop will overwrite the value on each iteration. It should be moved outside the loop: move
self.expected_result_count = len(emails)before the for loop.
# Check additional condition
python/packages/workflow/agent_framework_workflow/_executor.py:140
- This field declaration without initialization will cause AttributeError when accessed before being set. Initialize it with a default value:
self.expected_result_count: int = 0
if hasattr(request.data, "__class__") and request.data.__class__.__name__ == request_type:
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
…a subflow with multiple requests in a single super step.
Eric Zhu (ekzhu)
left a comment
There was a problem hiding this comment.
I will clean up and resolve the conflicts.
|
I noticed it currently doesn't automatically forward sub-workflow's request info event externally when there is no interceptor or request info executor in the parent workflow. I added a warning for this. What is the reason for not automatically surface the sub workflow's RequestInfoEvent? agent-framework/python/packages/workflow/agent_framework_workflow/_runner.py Lines 205 to 211 in c1a4088 |
* Adding design documents and data flow descriptions for sub-workflows * Updating docs. * Sub-workflow implementation microsoft#1. Stuck because of singleton RequestInfoExecutor, going to make a change to remove that restrivtion. * Removed the singleton restriction on RequestInfoExecutor so enable sub-workflows. * Scenarios seem to be working. * Sample improved. * going to have intern add generic response wrappers. * Wrapped responses working. * Non-hardcoded routing is working. * Sample showing external approved and not approved. * Cleaning up. * Updating some samples and user guide. * Removing old design doc. * Cleaning up. * Adding python-package-setup.md back. * Update python/packages/workflow/agent_framework_workflow/_executor.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/packages/workflow/agent_framework_workflow/_validation.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Removing prints. * Fixing lint and type issues. * Fixing lint and type issues. * Update python/packages/workflow/agent_framework_workflow/_executor.py Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com> * Adding type hints to intercepts decorator. * Removing unused files. * Fixing issue with sample 5 groupchat with hil. * Removing redundent samples. * Updates to ensure no conflicting request interceptors and to support a subflow with multiple requests in a single super step. * Fixing pypi errors. * clean up samples * update samples to make it more clear * warning for unhandled request info from sub workflow * add logger info --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
Add Sub-Workflows Support to Agent Framework
Summary
This PR introduces hierarchical workflow composition through sub-workflows, enabling workflows to execute other
workflows as executors within their execution graph. Sub-workflows can make external requests that are
automatically routed to parent workflows for interception and handling.
Key Features
WorkflowExecutorclass enables embedding workflows as executors withinother workflows
@intercepts_requestdecorator
SubWorkflowRequestInfomessages are automatically routed between parent andsub-workflows
RequestInfoExecutorfor external datarequests
RequestResponse[TRequest, TResponse]pattern with automatic correlationtracking
Implementation Details
Core Components
workflow layers
sub-workflows
.handled()and.forward()methodsMessage Flow
Sub-Workflow → SubWorkflowRequestInfo → Parent Workflow Interceptor
↓ (if not intercepted)
RequestInfoExecutor → External Handler
↓
SubWorkflowResponse → Sub-Workflow
Contribution Checklist