From b7fd35401bb1823c25bb304b3d7a85763e90f0b6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 22:07:32 +0000 Subject: [PATCH] Add MaxRoundLimit_Terminates_Workflow E2E test Agent-Logs-Url: https://github.com/microsoft/agent-framework/sessions/6e8bca46-448d-4f21-a7e9-240179571970 Co-authored-by: lokitoth <6936551+lokitoth@users.noreply.github.com> --- .../MagenticOrchestrationTests.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MagenticOrchestrationTests.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MagenticOrchestrationTests.cs index 8a0f697ee7..383eae9dc0 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MagenticOrchestrationTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MagenticOrchestrationTests.cs @@ -439,6 +439,46 @@ public class MagenticOrchestrationTests thirdResult.Result![0].Text.Should().Contain("Revised plan executed successfully"); } + [Fact] + public async Task MaxRoundLimit_Terminates_Workflow() + { + // Arrange: MaxRounds=1, so round 1 delegates to Worker, round 2 hits limit and terminates. + // Manager turns: facts1, plan1, ledger1(not satisfied→delegates), facts2, plan2 (re-entry), then limit hit before ledger. + List factsResponse1 = CreatePlanResponse("Facts"); + List planResponse1 = CreatePlanResponse("Plan"); + List round1Ledger = CreateProgressLedgerResponse( + isRequestSatisfied: false, + isInLoop: false, + isProgressBeingMade: true, + nextSpeaker: "Worker", + instructionOrQuestion: "Work on it"); + + // Round 2 re-entry: TakeTurnAsync calls UpdatePlanAndDelegateAsync → needs facts + plan + List factsResponse2 = CreatePlanResponse("Updated facts"); + List planResponse2 = CreatePlanResponse("Updated plan"); + // No more turns needed: RunCoordinationRoundAsync hits round limit before calling UpdateProgressLedgerAsync + + TestReplayAgent manager = new( + [factsResponse1, planResponse1, round1Ledger, factsResponse2, planResponse2], + name: "Manager"); + TestEchoAgent worker = new(name: "Worker"); + + Workflow workflow = new MagenticWorkflowBuilder(manager) + .AddParticipants(worker) + .RequirePlanSignoff(false) + .WithMaxRounds(1) + .Build(); + + // Act + WorkflowRunResult runResult = await RunMagenticWorkflowAsync( + workflow, + [new ChatMessage(ChatRole.User, "Do task")]); + + // Assert: Workflow terminates with round limit message + runResult.Result.Should().NotBeNull(); + runResult.Result![0].Text.Should().Contain("maximum round count limit"); + } + #region Helper Methods private sealed record WorkflowRunResult(