mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
* 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
35 lines
1.1 KiB
C#
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}.")
|
|
};
|
|
}
|