Skip to content

.NET: [Feature Branch] Add nested sub-workflow support for durable workflows#4190

Merged
kshyju merged 5 commits intofeat/durable_taskfrom
shkr/feat_durable_task-nested
Feb 25, 2026
Merged

.NET: [Feature Branch] Add nested sub-workflow support for durable workflows#4190
kshyju merged 5 commits intofeat/durable_taskfrom
shkr/feat_durable_task-nested

Conversation

@kshyju
Copy link
Contributor

@kshyju kshyju commented Feb 23, 2026

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 via CallSubOrchestratorAsync, with conversion of DurableWorkflowResult to DurableExecutorOutput for seamless integration with the parent workflow's result processing.
  • DurableWorkflowResult — Added SentMessages property (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 a SentMessage so parent workflows can route it to connected executors via the edge map.

Public API Changes

None.

Sample (07_SubWorkflows)

New console app sample demonstrating:

  • Sub-workflows: Using Workflow.BindAsExecutor() to embed a workflow as an executor
  • Multi-level nesting: FraudCheck sub-workflow nested inside a Payment sub-workflow (Level 2)
  • Automatic discovery: Only the top-level workflow is registered; sub-workflows are discovered automatically
  • Event propagation: Custom FraudRiskAssessedEvent bubbles up from nested sub-workflows
  • Message passing: SelectCarrier uses Executor<TInput> (void return) with SendMessageAsync to forward typed messages to connected executors
  • Shared state: AnalyzePatternsCalculateRiskScore communicate via QueueStateUpdateAsync/ReadStateAsync
OrderProcessing (main workflow)
├── OrderReceived
├── Payment (sub-workflow)
│   ├── ValidatePayment
│   ├── FraudCheck (sub-sub-workflow)
│   │   ├── AnalyzePatterns
│   │   └── CalculateRiskScore
│   └── ChargePayment
├── Shipping (sub-workflow)
│   ├── SelectCarrier (void-return + SendMessageAsync)
│   └── CreateShipment
└── OrderCompleted

Tests

  • Added SubWorkflowsSampleValidationAsync integration test to WorkflowConsoleAppSamplesValidation — validates all executor log entries across all three nesting levels, verifies event propagation, and confirms end-to-end workflow completion.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@kshyju kshyju requested a review from Copilot February 23, 2026 19:50
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation .NET labels Feb 23, 2026
@kshyju kshyju added workflows Related to Workflows in agent-framework azure-functions Issues and PRs related to Azure Functions labels Feb 23, 2026
Copy link
Contributor

Copilot AI left a 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 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 DurableWorkflowResult with a SentMessages property to enable message routing from sub-workflows to parent workflow executors
  • Enhanced DurableExecutorDispatcher to detect and dispatch sub-workflow executors via CallSubOrchestratorAsync with automatic result format conversion
  • Modified DurableWorkflowRunner to 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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

@kshyju kshyju requested a review from cgillum February 23, 2026 20:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Copy link
Member

@cgillum cgillum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see this feature landing. Just a few comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

@kshyju kshyju requested a review from cgillum February 25, 2026 22:42
Copy link
Member

@cgillum cgillum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - just one minor comment.

@kshyju kshyju merged commit 2988568 into feat/durable_task Feb 25, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azure-functions Issues and PRs related to Azure Functions documentation Improvements or additions to documentation .NET workflows Related to Workflows in agent-framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants