Files
agent-framework/dotnet/src/Microsoft.Agents.AI.Workflows/SubworkflowBinding.cs
T
Jacob Alber 4940d0ef36 fix: Subworkflows do not work well with HostAsAgent (#3240)
Subworkflows run into issues with Checkpointing and the Chat Protocol:

* The concurrency rework made subtle changes in behaviour that introduced a hang when using subworkflows with ChatProtocol and streaming execution.
* The ResetAsync() implementation in WorkflowHostExecutor was improperly resetting the joinContext - this was happening on restore checkpoint _after_ the join context was attached when
* Subworkflows cannot be used as the start node when hosted AsAgent due to inability to treat Catch-All as a Chat Protocol
* Subworkflow ownership issue when used in non-concurrent mode after finishing a run

Also fixes:
* When ChatMessages are output by executors that are not agents, there is no corresponding AgentResponseUpdate/AgentResponse event

Breaking Changes
* [BREAKING CHANGE] It is possible to provide the wrong RunId when resuming from CheckpointInfo (even though the data already exists on CheckpointInfo)
2026-01-22 16:01:47 +00:00

45 lines
1.5 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Threading.Tasks;
using Microsoft.Agents.AI.Workflows.Specialized;
using Microsoft.Shared.Diagnostics;
namespace Microsoft.Agents.AI.Workflows;
/// <summary>
/// Represents the workflow binding details for a subworkflow, including its instance, identifier, and optional
/// executor options.
/// </summary>
/// <param name="WorkflowInstance"></param>
/// <param name="Id"></param>
/// <param name="ExecutorOptions"></param>
public record SubworkflowBinding(Workflow WorkflowInstance, string Id, ExecutorOptions? ExecutorOptions = null)
: ExecutorBinding(Throw.IfNull(Id),
CreateWorkflowExecutorFactory(WorkflowInstance, Id, ExecutorOptions),
typeof(WorkflowHostExecutor),
WorkflowInstance)
{
private static Func<string, ValueTask<Executor>> CreateWorkflowExecutorFactory(Workflow workflow, string id, ExecutorOptions? options)
{
object ownershipToken = new();
workflow.TakeOwnership(ownershipToken, subworkflow: true);
return InitHostExecutorAsync;
ValueTask<Executor> InitHostExecutorAsync(string runId)
{
return new(new WorkflowHostExecutor(id, workflow, runId, ownershipToken, options));
}
}
/// <inheritdoc/>
public override bool IsSharedInstance => false;
/// <inheritdoc/>
public override bool SupportsConcurrentSharedExecution => true;
/// <inheritdoc/>
public override bool SupportsResetting => false;
}