mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
2a345e5d3b
* Fix Magentic to share agent replies across team The per-round instruction was sent untargeted (fan-out delivered it to every participant) and replies were never relayed, so a later speaker saw the prior speaker's instruction but not its response - inverted from GroupChatHost and the Python reference. - Target the instruction at the selected speaker only. - Broadcast each reply to the other participants (buffered, no TurnToken), excluding the responder via _currentSpeakerExecutorId, mirroring GroupChatHost. - Persist _currentSpeakerExecutorId across checkpoints. - Add a regression test. * Address review feedback: null-guard, explicit checkpoint key, drop vacuous assertion * Address review feedback: centralize checkpoint keys, clear current speaker - Move CurrentSpeakerStateKey into MagenticConstants as nameof(CurrentSpeakerStateKey) - Clear _currentSpeakerExecutorId in ResetAndReplanAsync and PrepareFinalAnswerAsync so a checkpoint taken in those windows does not persist a stale speaker - Add UTF-8 BOM to RecordingEchoAgent.cs to satisfy the format check.
38 lines
1.5 KiB
C#
38 lines
1.5 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Threading;
|
|
using Microsoft.Extensions.AI;
|
|
|
|
namespace Microsoft.Agents.AI.Workflows.UnitTests;
|
|
|
|
/// <summary>
|
|
/// A <see cref="TestEchoAgent"/> that records the input messages it receives on each call.
|
|
/// Used by tests that need to assert what context a participant was actually handed - for example,
|
|
/// that a later speaker sees prior participants' <em>responses</em> (the running conversation) rather
|
|
/// than their <em>instructions</em>.
|
|
/// </summary>
|
|
internal sealed class RecordingEchoAgent(string? id = null, string? name = null, string? prefix = null)
|
|
: TestEchoAgent(id, name, prefix)
|
|
{
|
|
public List<List<ChatMessage>> RecordedInputs { get; } = [];
|
|
|
|
protected override async IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingAsync(
|
|
IEnumerable<ChatMessage> messages,
|
|
AgentSession? session = null,
|
|
AgentRunOptions? options = null,
|
|
[EnumeratorCancellation] CancellationToken cancellationToken = default)
|
|
{
|
|
// Materialize once so the deferred input is recorded and replayed identically.
|
|
List<ChatMessage> recorded = messages.ToList();
|
|
this.RecordedInputs.Add(recorded);
|
|
|
|
await foreach (AgentResponseUpdate update in base.RunCoreStreamingAsync(recorded, session, options, cancellationToken))
|
|
{
|
|
yield return update;
|
|
}
|
|
}
|
|
}
|