// 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; /// /// Represents the workflow binding details for a subworkflow, including its instance, identifier, and optional /// executor options. /// /// /// /// public record SubworkflowBinding(Workflow WorkflowInstance, string Id, ExecutorOptions? ExecutorOptions = null) : ExecutorBinding(Throw.IfNull(Id), CreateWorkflowExecutorFactory(WorkflowInstance, Id, ExecutorOptions), typeof(WorkflowHostExecutor), WorkflowInstance) { private static Func> CreateWorkflowExecutorFactory(Workflow workflow, string id, ExecutorOptions? options) { object ownershipToken = new(); workflow.TakeOwnership(ownershipToken, subworkflow: true); return InitHostExecutorAsync; async ValueTask InitHostExecutorAsync(string sessionId) { ProtocolDescriptor workflowProtocol = await workflow.DescribeProtocolAsync().ConfigureAwait(false); return new WorkflowHostExecutor(id, workflow, workflowProtocol, sessionId, ownershipToken, options); } } /// public override bool IsSharedInstance => false; /// public override bool SupportsConcurrentSharedExecution => true; /// public override bool SupportsResetting => false; }