Skip to content

Commit d466f3a

Browse files
committed
refactor: Rename AddFanInEdge to AddFanInBarrierEdge
This will prevent a breaking change later when we introduce a programmable FanIn edge, analogous to the FanOut edge's EdgeSelector. The goal, in the long run is to support a number of different FanIn scenarios, with naive FanIn (no barrier) by default, similar to FanOut.
1 parent 4615d06 commit d466f3a

File tree

8 files changed

+22
-26
lines changed

8 files changed

+22
-26
lines changed

dotnet/samples/GettingStarted/Workflows/Agents/WorkflowAsAnAgent/WorkflowFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal static Workflow BuildWorkflow(IChatClient chatClient)
2424
// Build the workflow by adding executors and connecting them
2525
return new WorkflowBuilder(startExecutor)
2626
.AddFanOutEdge(startExecutor, [frenchAgent, englishAgent])
27-
.AddFanInEdge([frenchAgent, englishAgent], aggregationExecutor)
27+
.AddFanInBarrierEdge([frenchAgent, englishAgent], aggregationExecutor)
2828
.WithOutputFrom(aggregationExecutor)
2929
.Build();
3030
}

dotnet/samples/GettingStarted/Workflows/Concurrent/Concurrent/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private static async Task Main()
5656
// Build the workflow by adding executors and connecting them
5757
var workflow = new WorkflowBuilder(startExecutor)
5858
.AddFanOutEdge(startExecutor, [physicist, chemist])
59-
.AddFanInEdge([physicist, chemist], aggregationExecutor)
59+
.AddFanInBarrierEdge([physicist, chemist], aggregationExecutor)
6060
.WithOutputFrom(aggregationExecutor)
6161
.Build();
6262

dotnet/samples/GettingStarted/Workflows/Concurrent/MapReduce/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public static Workflow BuildWorkflow()
6363
// Step 4: Build the concurrent workflow with fan-out/fan-in pattern
6464
return new WorkflowBuilder(splitter)
6565
.AddFanOutEdge(splitter, [.. mappers]) // Split -> many mappers
66-
.AddFanInEdge([.. mappers], shuffler) // All mappers -> shuffle
66+
.AddFanInBarrierEdge([.. mappers], shuffler) // All mappers -> shuffle
6767
.AddFanOutEdge(shuffler, [.. reducers]) // Shuffle -> many reducers
68-
.AddFanInEdge([.. reducers], completion) // All reducers -> completion
68+
.AddFanInBarrierEdge([.. reducers], completion) // All reducers -> completion
6969
.WithOutputFrom(completion)
7070
.Build();
7171
}

dotnet/samples/GettingStarted/Workflows/Observability/WorkflowAsAnAgent/WorkflowHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal static Workflow GetWorkflow(IChatClient chatClient, string sourceName)
2525
// Build the workflow by adding executors and connecting them
2626
return new WorkflowBuilder(startExecutor)
2727
.AddFanOutEdge(startExecutor, [frenchAgent, englishAgent])
28-
.AddFanInEdge([frenchAgent, englishAgent], aggregationExecutor)
28+
.AddFanInBarrierEdge([frenchAgent, englishAgent], aggregationExecutor)
2929
.WithOutputFrom(aggregationExecutor)
3030
.Build();
3131
}

dotnet/samples/GettingStarted/Workflows/SharedStates/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private static async Task Main()
2727
// Build the workflow by connecting executors sequentially
2828
var workflow = new WorkflowBuilder(fileRead)
2929
.AddFanOutEdge(fileRead, [wordCount, paragraphCount])
30-
.AddFanInEdge([wordCount, paragraphCount], aggregate)
30+
.AddFanInBarrierEdge([wordCount, paragraphCount], aggregate)
3131
.WithOutputFrom(aggregate)
3232
.Build();
3333

dotnet/src/Microsoft.Agents.AI.Workflows/AgentWorkflowBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private static Workflow BuildConcurrentCore(
135135

136136
ExecutorBinding end = endFactory.BindExecutor(ConcurrentEndExecutor.ExecutorId);
137137

138-
builder.AddFanInEdge(accumulators, end);
138+
builder.AddFanInBarrierEdge(accumulators, end);
139139

140140
builder = builder.WithOutputFrom(end);
141141
if (workflowName is not null)

dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilder.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -422,30 +422,26 @@ public WorkflowBuilder AddFanOutEdge<T>(ExecutorBinding source, IEnumerable<Exec
422422
}
423423

424424
/// <summary>
425-
/// Adds a fan-in edge to the workflow, connecting multiple source executors to a single target executor with an
426-
/// optional trigger condition.
425+
/// Adds a fan-in "barrier" edge to the workflow, connecting multiple source executors to a single target executor. Messages
426+
/// will be held until every source executor has generated at least one message, then they will be streamed to the target
427+
/// executor in the following step.
427428
/// </summary>
428-
/// <remarks>This method establishes a fan-in relationship, allowing the target executor to be activated
429-
/// based on the completion or state of multiple sources. The trigger parameter can be used to customize activation
430-
/// behavior.</remarks>
431429
/// <param name="sources">One or more source executors that provide input to the target. Cannot be null or empty.</param>
432430
/// <param name="target">The target executor that receives input from the specified source executors. Cannot be null.</param>
433431
/// <returns>The current instance of <see cref="WorkflowBuilder"/>.</returns>
434-
public WorkflowBuilder AddFanInEdge(IEnumerable<ExecutorBinding> sources, ExecutorBinding target)
435-
=> this.AddFanInEdge(sources, target, label: null);
432+
public WorkflowBuilder AddFanInBarrierEdge(IEnumerable<ExecutorBinding> sources, ExecutorBinding target)
433+
=> this.AddFanInBarrierEdge(sources, target, label: null);
436434

437435
/// <summary>
438-
/// Adds a fan-in edge to the workflow, connecting multiple source executors to a single target executor with an
439-
/// optional trigger condition.
436+
/// Adds a fan-in "barrier" edge to the workflow, connecting multiple source executors to a single target executor. Messages
437+
/// will be held until every source executor has generated at least one message, then they will be streamed to the target
438+
/// executor in the following step.
440439
/// </summary>
441-
/// <remarks>This method establishes a fan-in relationship, allowing the target executor to be activated
442-
/// based on the completion or state of multiple sources. The trigger parameter can be used to customize activation
443-
/// behavior.</remarks>
444440
/// <param name="sources">One or more source executors that provide input to the target. Cannot be null or empty.</param>
445441
/// <param name="target">The target executor that receives input from the specified source executors. Cannot be null.</param>
446442
/// <param name="label">An optional label for the edge. Will be used in visualizations.</param>
447443
/// <returns>The current instance of <see cref="WorkflowBuilder"/>.</returns>
448-
public WorkflowBuilder AddFanInEdge(IEnumerable<ExecutorBinding> sources, ExecutorBinding target, string? label = null)
444+
public WorkflowBuilder AddFanInBarrierEdge(IEnumerable<ExecutorBinding> sources, ExecutorBinding target, string? label = null)
449445
{
450446
Throw.IfNull(target);
451447
Throw.IfNull(sources);
@@ -472,10 +468,10 @@ public WorkflowBuilder AddFanInEdge(IEnumerable<ExecutorBinding> sources, Execut
472468
return this;
473469
}
474470

475-
/// <inheritdoc cref="AddFanInEdge(IEnumerable{ExecutorBinding}, ExecutorBinding)"/>
471+
/// <inheritdoc cref="AddFanInBarrierEdge(IEnumerable{ExecutorBinding}, ExecutorBinding)"/>
476472
[Obsolete("Use AddFanInEdge(IEnumerable<ExecutorBinding>, ExecutorBinding) instead.")]
477473
public WorkflowBuilder AddFanInEdge(ExecutorBinding target, params IEnumerable<ExecutorBinding> sources)
478-
=> this.AddFanInEdge(sources, target);
474+
=> this.AddFanInBarrierEdge(sources, target);
479475

480476
private void Validate(bool validateOrphans)
481477
{

dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowVisualizerTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void Test_WorkflowViz_FanIn_EdgeGroup()
114114
// Build a connected workflow: start fans out to s1 and s2, which then fan-in to t
115115
var workflow = new WorkflowBuilder("start")
116116
.AddFanOutEdge(start, [s1, s2])
117-
.AddFanInEdge([s1, s2], t) // AddFanInEdge(target, sources)
117+
.AddFanInBarrierEdge([s1, s2], t) // AddFanInEdge(target, sources)
118118
.Build();
119119

120120
var dotContent = workflow.ToDotString();
@@ -202,7 +202,7 @@ public void Test_WorkflowViz_Mixed_EdgeTypes()
202202
var workflow = new WorkflowBuilder("start")
203203
.AddEdge<string>(start, a, Condition) // Conditional edge
204204
.AddFanOutEdge(a, [b, c]) // Fan-out
205-
.AddFanInEdge([b, c], end) // Fan-in - AddFanInEdge(target, sources)
205+
.AddFanInBarrierEdge([b, c], end) // Fan-in - AddFanInEdge(target, sources)
206206
.Build();
207207

208208
var dotContent = workflow.ToDotString();
@@ -310,7 +310,7 @@ public void Test_WorkflowViz_Mermaid_FanIn_EdgeGroup()
310310

311311
var workflow = new WorkflowBuilder("start")
312312
.AddFanOutEdge(start, [s1, s2])
313-
.AddFanInEdge([s1, s2], t)
313+
.AddFanInBarrierEdge([s1, s2], t)
314314
.Build();
315315

316316
var mermaidContent = workflow.ToMermaidString();
@@ -381,7 +381,7 @@ public void Test_WorkflowViz_Mermaid_Mixed_EdgeTypes()
381381
var workflow = new WorkflowBuilder("start")
382382
.AddEdge<string>(start, a, Condition) // Conditional edge
383383
.AddFanOutEdge(a, [b, c]) // Fan-out
384-
.AddFanInEdge([b, c], end) // Fan-in
384+
.AddFanInBarrierEdge([b, c], end) // Fan-in
385385
.Build();
386386

387387
var mermaidContent = workflow.ToMermaidString();

0 commit comments

Comments
 (0)