From 1ff632d365b865b7e4628d3e5250c63038fcf137 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 22:28:42 +0000 Subject: [PATCH] Add Instruction_Message_Sent_When_Present E2E test Agent-Logs-Url: https://github.com/microsoft/agent-framework/sessions/aba19507-7c7e-40dd-850d-d1fabb5dfa65 Co-authored-by: lokitoth <6936551+lokitoth@users.noreply.github.com> --- .../MagenticOrchestrationTests.cs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MagenticOrchestrationTests.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MagenticOrchestrationTests.cs index 17f9cb1c8c..f1d0f248d9 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MagenticOrchestrationTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MagenticOrchestrationTests.cs @@ -532,6 +532,59 @@ public class MagenticOrchestrationTests runResult.Result![0].Text.Should().Contain("Recovered after stall reset"); } + [Fact] + public async Task Instruction_Message_Sent_When_Present() + { + // Arrange: Progress ledger has a non-empty instruction_or_question. + // The orchestrator should send the instruction as a ChatMessage before delegating to the next agent. + // After Worker echoes, the second round completes. + List factsResponse1 = CreatePlanResponse("Facts about the task"); + List planResponse1 = CreatePlanResponse("Step 1: Instruct the worker"); + List ledgerWithInstruction = CreateProgressLedgerResponse( + isRequestSatisfied: false, + isInLoop: false, + isProgressBeingMade: true, + nextSpeaker: "Worker", + instructionOrQuestion: "Please analyze the data carefully"); + + // Round 2 after Worker responds + List factsResponse2 = CreatePlanResponse("Updated facts"); + List planResponse2 = CreatePlanResponse("Updated plan"); + List satisfiedLedger = CreateProgressLedgerResponse( + isRequestSatisfied: true, + isInLoop: false, + isProgressBeingMade: true, + nextSpeaker: "Worker", + instructionOrQuestion: "Done"); + List finalAnswerResponse = CreateFinalAnswerResponse("Task completed with instruction"); + + TestReplayAgent manager = new( + [factsResponse1, planResponse1, ledgerWithInstruction, + factsResponse2, planResponse2, satisfiedLedger, finalAnswerResponse], + name: "Manager"); + TestEchoAgent worker = new(name: "Worker"); + + List collectedEvents = []; + + Workflow workflow = new MagenticWorkflowBuilder(manager) + .AddParticipants(worker) + .RequirePlanSignoff(false) + .Build(); + + // Act + WorkflowRunResult runResult = await RunMagenticWorkflowAsync( + workflow, + [new ChatMessage(ChatRole.User, "Analyze data")], + eventCollector: collectedEvents); + + // Assert: The workflow completed successfully, proving the instruction path executed without error. + // The update text should contain the instruction text since it is sent to participants as a ChatMessage. + runResult.Result.Should().NotBeNull(); + runResult.Result![0].Text.Should().Contain("Task completed with instruction"); + // Verify the delegation happened (two progress ledger events for two rounds) + collectedEvents.OfType().Should().HaveCount(2); + } + [Fact] public async Task PlanReview_On_Stall_Replan() {