.NET: [Feature Branch] Add nested sub-workflow support for durable workflows#4190
.NET: [Feature Branch] Add nested sub-workflow support for durable workflows#4190kshyju merged 5 commits intofeat/durable_taskfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds support for nested sub-workflows in the Durable Task workflow system, enabling workflows to act as executors within other workflows with multi-level nesting capabilities (sub-workflow within sub-workflow). The implementation extends the existing durable workflow infrastructure to support hierarchical workflow execution via Durable Task sub-orchestrations, providing independent checkpointing, replay protection, and dashboard visualization for each sub-workflow instance.
Changes:
- Extended
DurableWorkflowResultwith aSentMessagesproperty to enable message routing from sub-workflows to parent workflow executors - Enhanced
DurableExecutorDispatcherto detect and dispatch sub-workflow executors viaCallSubOrchestratorAsyncwith automatic result format conversion - Modified
DurableWorkflowRunnerto include the final workflow result as a sent message for proper routing in parent workflows - Added comprehensive sample (07_SubWorkflows) demonstrating 2-level workflow nesting, event propagation, and shared state within sub-workflows
- Added integration test validating all executor execution across three nesting levels and event propagation
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/DurableWorkflowResult.cs |
Added SentMessages property to carry typed messages from sub-workflows to parent workflows |
dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/DurableExecutorDispatcher.cs |
Added ExecuteSubWorkflowAsync method to dispatch sub-workflows as sub-orchestrations and convert results to executor output format |
dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/DurableWorkflowRunner.cs |
Modified to include final result as a sent message and added null-conditional operators for defensive deserialization |
dotnet/tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/WorkflowConsoleAppSamplesValidation.cs |
Added SubWorkflowsSampleValidationAsync test validating all executors across three nesting levels |
dotnet/samples/Durable/Workflow/ConsoleApps/07_SubWorkflows/Program.cs |
Sample entry point demonstrating 2-level nested sub-workflow configuration and execution |
dotnet/samples/Durable/Workflow/ConsoleApps/07_SubWorkflows/Executors.cs |
Executor implementations showcasing sub-workflow features including event propagation and shared state |
dotnet/samples/Durable/Workflow/ConsoleApps/07_SubWorkflows/README.md |
Comprehensive documentation explaining sub-workflow concepts and sample structure |
dotnet/samples/Durable/Workflow/ConsoleApps/07_SubWorkflows/07_SubWorkflows.csproj |
Project configuration for the sub-workflows sample |
dotnet/agent-framework-dotnet.slnx |
Added sample project to solution file |
dotnet/samples/Durable/Workflow/ConsoleApps/07_SubWorkflows/07_SubWorkflows.csproj
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/DurableWorkflowResult.cs
Show resolved
Hide resolved
46e4c52 to
faa4563
Compare
dotnet/samples/Durable/Workflow/ConsoleApps/07_SubWorkflows/README.md
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/DurableWorkflowRunner.cs
Show resolved
Hide resolved
cgillum
left a comment
There was a problem hiding this comment.
Great to see this feature landing. Just a few comments.
dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/DurableExecutorDispatcher.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/DurableStreamingWorkflowRun.cs
Show resolved
Hide resolved
...ests/Microsoft.Agents.AI.DurableTask.UnitTests/Workflows/DurableStreamingWorkflowRunTests.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/DurableExecutorDispatcher.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/DurableExecutorDispatcher.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/DurableWorkflowRunner.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.DurableTask/Workflows/DurableWorkflowRunner.cs
Show resolved
Hide resolved
...ests/Microsoft.Agents.AI.DurableTask.IntegrationTests/WorkflowConsoleAppSamplesValidation.cs
Outdated
Show resolved
Hide resolved
cgillum
left a comment
There was a problem hiding this comment.
Looks good - just one minor comment.
Summary
Adds support for nested sub-workflows in the Durable Task workflow system. Sub-workflows can now act as executors within other workflows, including multi-level nesting (sub-workflow within sub-workflow).
Changes
Library (
Microsoft.Agents.AI.DurableTask)DurableExecutorDispatcher— Added sub-workflow dispatch viaCallSubOrchestratorAsync, with conversion ofDurableWorkflowResulttoDurableExecutorOutputfor seamless integration with the parent workflow's result processing.DurableWorkflowResult— AddedSentMessagesproperty (List<TypedPayload>) so sub-workflow results carry typed messages that get routed to connected executors in the parent workflow.DurableWorkflowRunner— The final workflow result is now included as aSentMessageso parent workflows can route it to connected executors via the edge map.Public API Changes
None.
Sample (
07_SubWorkflows)New console app sample demonstrating:
Workflow.BindAsExecutor()to embed a workflow as an executorFraudRiskAssessedEventbubbles up from nested sub-workflowsSelectCarrierusesExecutor<TInput>(void return) withSendMessageAsyncto forward typed messages to connected executorsAnalyzePatterns→CalculateRiskScorecommunicate viaQueueStateUpdateAsync/ReadStateAsyncTests
SubWorkflowsSampleValidationAsyncintegration test toWorkflowConsoleAppSamplesValidation— validates all executor log entries across all three nesting levels, verifies event propagation, and confirms end-to-end workflow completion.Contribution Checklist