From d5bbf4ec9c7e3c2475758955da46bba416a84285 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 14 May 2026 01:32:44 +0000
Subject: [PATCH] Add empty-team validation to MagenticWorkflowBuilder.Build()
and E2E test
Agent-Logs-Url: https://github.com/microsoft/agent-framework/sessions/e490fdf7-f107-4fde-ba1f-efdfd9a729c6
Co-authored-by: lokitoth <6936551+lokitoth@users.noreply.github.com>
---
.../MagenticWorkflowBuilder.cs | 11 ++++++++++-
.../MagenticOrchestrationTests.cs | 18 ++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/MagenticWorkflowBuilder.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/MagenticWorkflowBuilder.cs
index 7c1e801ab1..ad620f6fc1 100644
--- a/dotnet/src/Microsoft.Agents.AI.Workflows/MagenticWorkflowBuilder.cs
+++ b/dotnet/src/Microsoft.Agents.AI.Workflows/MagenticWorkflowBuilder.cs
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
+using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
@@ -140,7 +141,15 @@ public class MagenticWorkflowBuilder(AIAgent managerAgent)
}
///
- public Workflow Build() => this.ReduceToWorkflowBuilder().Build();
+ public Workflow Build()
+ {
+ if (this._team.Count == 0)
+ {
+ throw new InvalidOperationException("At least one participant must be added before building a Magentic workflow.");
+ }
+
+ return this.ReduceToWorkflowBuilder().Build();
+ }
private TaskLimits Limits => new(
MaxRoundCount: this._maxRounds,
diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MagenticOrchestrationTests.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MagenticOrchestrationTests.cs
index d8d08bfe7e..86cd7236b6 100644
--- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MagenticOrchestrationTests.cs
+++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MagenticOrchestrationTests.cs
@@ -1165,6 +1165,24 @@ public class MagenticOrchestrationTests
fourthResult.Result![0].Text.Should().Contain("Completed after multiple revisions");
}
+ [Fact]
+ public void Empty_Team_Build_Throws()
+ {
+ // Arrange: No participants added to the builder.
+ TestReplayAgent manager = new(
+ [CreatePlanResponse("Facts"), CreatePlanResponse("Plan")],
+ name: "Manager");
+
+ MagenticWorkflowBuilder builder = new MagenticWorkflowBuilder(manager)
+ // No .AddParticipants() — empty team
+ .RequirePlanSignoff(false);
+
+ // Act & Assert: Build() should throw because the team is empty.
+ Action buildAction = () => builder.Build();
+ buildAction.Should().Throw()
+ .WithMessage("*participant*");
+ }
+
#region Helper Methods
private sealed record WorkflowRunResult(