mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.NET: [BREAKING] refactor: Normalize WorkflowBuilder APIs (#1935)
* [BREAKING] refactor: Normalize WorkflowBuilder APIs * "partitioner" => "assigner" * normalize ordering so sources always to the left of targets for edges * normalize parameter ordering so sources and targets are always first arguments * remove `params` (users should use collection expressions instead) * refactor: Align name with Python
This commit is contained in:
+9
-9
@@ -68,10 +68,10 @@ internal static class Step9EntryPoint
|
||||
|
||||
var requestPort = RequestPort.Create<TRequest, TResponse>(id);
|
||||
|
||||
return builder.ForwardMessage<ExternalRequest>(source, executors: [filter], condition: message => message.DataIs<TRequest>())
|
||||
.ForwardMessage<ExternalRequest>(filter, executors: [requestPort], condition: message => message.DataIs<TRequest>())
|
||||
.ForwardMessage<ExternalResponse>(requestPort, executors: [filter], condition: message => message.DataIs<TResponse>())
|
||||
.ForwardMessage<ExternalResponse>(filter, executors: [source], condition: message => message.DataIs<TResponse>());
|
||||
return builder.ForwardMessage<ExternalRequest>(source, targets: [filter], condition: message => message.DataIs<TRequest>())
|
||||
.ForwardMessage<ExternalRequest>(filter, targets: [requestPort], condition: message => message.DataIs<TRequest>())
|
||||
.ForwardMessage<ExternalResponse>(requestPort, targets: [filter], condition: message => message.DataIs<TResponse>())
|
||||
.ForwardMessage<ExternalResponse>(filter, targets: [source], condition: message => message.DataIs<TResponse>());
|
||||
}
|
||||
|
||||
public static WorkflowBuilder AddExternalRequest<TRequest, TResponse>(this WorkflowBuilder builder, ExecutorBinding source, string? id = null)
|
||||
@@ -88,10 +88,10 @@ internal static class Step9EntryPoint
|
||||
|
||||
public static WorkflowBuilder AddExternalRequest<TRequest, TResponse>(this WorkflowBuilder builder, ExecutorBinding source, RequestPort<TRequest, TResponse> inputPort)
|
||||
{
|
||||
return builder.ForwardMessage<TRequest>(source, inputPort)
|
||||
.ForwardMessage<ExternalRequest>(source, inputPort)
|
||||
.ForwardMessage<TResponse>(inputPort, source)
|
||||
.ForwardMessage<ExternalResponse>(inputPort, source);
|
||||
return builder.ForwardMessage<TRequest>(source, [inputPort])
|
||||
.ForwardMessage<ExternalRequest>(source, [inputPort])
|
||||
.ForwardMessage<TResponse>(inputPort, [source])
|
||||
.ForwardMessage<ExternalResponse>(inputPort, [source]);
|
||||
}
|
||||
|
||||
public static Workflow CreateSubWorkflow()
|
||||
@@ -113,7 +113,7 @@ internal static class Step9EntryPoint
|
||||
ExecutorBinding subworkflow = CreateSubWorkflow().BindAsExecutor("ResourceWorkflow");
|
||||
|
||||
return new WorkflowBuilder(coordinator)
|
||||
.AddChain(coordinator, allowRepetition: true, subworkflow, coordinator)
|
||||
.AddChain(coordinator, [subworkflow, coordinator], allowRepetition: true)
|
||||
.AddPassthroughRequestHandler<ResourceRequest, ResourceResponse>(subworkflow, cache)
|
||||
.AddPassthroughRequestHandler<PolicyCheckRequest, PolicyResponse>(subworkflow, policyEngine)
|
||||
.WithOutputFrom(coordinator)
|
||||
|
||||
@@ -111,8 +111,8 @@ public class WorkflowVisualizerTests
|
||||
|
||||
// Build a connected workflow: start fans out to s1 and s2, which then fan-in to t
|
||||
var workflow = new WorkflowBuilder("start")
|
||||
.AddFanOutEdge(start, s1, s2)
|
||||
.AddFanInEdge(t, s1, s2) // AddFanInEdge(target, sources)
|
||||
.AddFanOutEdge(start, [s1, s2])
|
||||
.AddFanInEdge([s1, s2], t) // AddFanInEdge(target, sources)
|
||||
.Build();
|
||||
|
||||
var dotContent = workflow.ToDotString();
|
||||
@@ -174,7 +174,7 @@ public class WorkflowVisualizerTests
|
||||
var target3 = new MockExecutor("target3");
|
||||
|
||||
var workflow = new WorkflowBuilder("start")
|
||||
.AddFanOutEdge(start, target1, target2, target3)
|
||||
.AddFanOutEdge(start, [target1, target2, target3])
|
||||
.Build();
|
||||
|
||||
var dotContent = workflow.ToDotString();
|
||||
@@ -199,8 +199,8 @@ public class WorkflowVisualizerTests
|
||||
|
||||
var workflow = new WorkflowBuilder("start")
|
||||
.AddEdge<string>(start, a, Condition) // Conditional edge
|
||||
.AddFanOutEdge(a, b, c) // Fan-out
|
||||
.AddFanInEdge(end, b, c) // Fan-in - AddFanInEdge(target, sources)
|
||||
.AddFanOutEdge(a, [b, c]) // Fan-out
|
||||
.AddFanInEdge([b, c], end) // Fan-in - AddFanInEdge(target, sources)
|
||||
.Build();
|
||||
|
||||
var dotContent = workflow.ToDotString();
|
||||
@@ -307,8 +307,8 @@ public class WorkflowVisualizerTests
|
||||
var t = new ListStrTargetExecutor("t");
|
||||
|
||||
var workflow = new WorkflowBuilder("start")
|
||||
.AddFanOutEdge(start, s1, s2)
|
||||
.AddFanInEdge(t, s1, s2)
|
||||
.AddFanOutEdge(start, [s1, s2])
|
||||
.AddFanInEdge([s1, s2], t)
|
||||
.Build();
|
||||
|
||||
var mermaidContent = workflow.ToMermaidString();
|
||||
@@ -378,8 +378,8 @@ public class WorkflowVisualizerTests
|
||||
|
||||
var workflow = new WorkflowBuilder("start")
|
||||
.AddEdge<string>(start, a, Condition) // Conditional edge
|
||||
.AddFanOutEdge(a, b, c) // Fan-out
|
||||
.AddFanInEdge(end, b, c) // Fan-in
|
||||
.AddFanOutEdge(a, [b, c]) // Fan-out
|
||||
.AddFanInEdge([b, c], end) // Fan-in
|
||||
.Build();
|
||||
|
||||
var mermaidContent = workflow.ToMermaidString();
|
||||
|
||||
Reference in New Issue
Block a user