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>
This commit is contained in:
copilot-swe-agent[bot]
2026-05-14 01:32:44 +00:00
committed by GitHub
Unverified
parent 9cd4f2dc49
commit d5bbf4ec9c
2 changed files with 28 additions and 1 deletions
@@ -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)
}
/// <inheritdoc cref="WorkflowBuilder.Build"/>
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,
@@ -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<InvalidOperationException>()
.WithMessage("*participant*");
}
#region Helper Methods
private sealed record WorkflowRunResult(