Files
agent-framework/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Interpreter/WorkflowModelBuilder.cs
T
Jacob AlberandGitHub b25b0af49b .NET: [BREAKING] Unify ExecutorIsh and ExecutorRegistration, unify/simplify APIs (#1637)
* refactor: Unify ExecutorIsh and ExecutorRegistration => ExecutorBinding

* Switch to more modern Record type-tree for Sum Types
* Unify APIs for getting ExecutorBinding
* Fix an issue where workflows consisting entirely of cross-run shareable executors which are not instance-resettable do not properly clear state when running non-concurrently.

* feat: Simplify function-to-executor pattern

* refactor: Normalize API naming
2025-11-03 18:20:35 +00:00

35 lines
1.1 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Diagnostics;
namespace Microsoft.Agents.AI.Workflows.Declarative.Interpreter;
internal sealed class WorkflowModelBuilder : IModelBuilder<Func<object?, bool>>
{
public WorkflowModelBuilder(Executor rootAction)
{
this.WorkflowBuilder = new WorkflowBuilder(rootAction);
}
public WorkflowBuilder WorkflowBuilder { get; }
public void Connect(IModeledAction source, IModeledAction target, Func<object?, bool>? condition)
{
Debug.WriteLine($"> CONNECT: {source.Id} => {target.Id}{(condition is null ? string.Empty : " (?)")}");
this.WorkflowBuilder.AddEdge(
GetExecutorBinding(source),
GetExecutorBinding(target),
condition);
}
private static ExecutorBinding GetExecutorBinding(IModeledAction action) =>
action switch
{
RequestPortAction port => port.RequestPort,
Executor executor => executor,
_ => throw new DeclarativeModelException($"Unsupported modeled action: {action.GetType().Name}.")
};
}