mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
* Checkpoint * Checkpoint * Namespaces * Namespace * Cleanup * Namespace order * Fix sync * Formatting * Formatting * Namespace * Namespace order * Code convention * Naming * Naming * Text handling * Text handling * Namespace * Namespace order * Namespace ordering * Test * ValueTask * net472 * Test fix * Fix namespace (net472) * Namespace * Fix conditional namespace * Fix type expression * Compatibility and cleanup * Sample compatibility * Sample compat * Test compat * modifier order * Simply http-stub * Formating fix for unit-test * Fix test * Real fix * Test clean-up * Update dotnet/src/Microsoft.Agents.Orchestration/Handoff/HandoffOrchestration.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix build errors after merging --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Stephen Toub <stoub@microsoft.com>
65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.AI;
|
|
using Microsoft.Extensions.AI.Agents;
|
|
using Moq;
|
|
|
|
namespace Microsoft.Agents.Orchestration.UnitTest;
|
|
|
|
/// <summary>
|
|
/// Mock definition of <see cref="Agent"/>.
|
|
/// </summary>
|
|
internal sealed class MockAgent(int index) : Agent
|
|
{
|
|
public static MockAgent CreateWithResponse(int index, string response)
|
|
{
|
|
return new(index)
|
|
{
|
|
Response = [new(ChatRole.Assistant, response)]
|
|
};
|
|
}
|
|
|
|
public int InvokeCount { get; private set; }
|
|
|
|
public IReadOnlyList<ChatMessage> Response { get; set; } = [];
|
|
|
|
public override string? Name => $"testagent{index}";
|
|
|
|
public override string? Description => $"test {index}";
|
|
|
|
public override AgentThread GetNewThread()
|
|
{
|
|
return new AgentThread() { Id = Guid.NewGuid().ToString() };
|
|
}
|
|
|
|
public override async Task<ChatResponse> RunAsync(IReadOnlyCollection<ChatMessage> messages, AgentThread? thread = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default)
|
|
{
|
|
this.InvokeCount++;
|
|
if (thread == null)
|
|
{
|
|
Mock<AgentThread> mockThread = new(MockBehavior.Strict);
|
|
thread = mockThread.Object;
|
|
}
|
|
|
|
await (options?.OnIntermediateMessages?.Invoke(this.Response) ?? Task.CompletedTask);
|
|
|
|
return new ChatResponse(messages: [.. this.Response]);
|
|
}
|
|
|
|
public override async IAsyncEnumerable<ChatResponseUpdate> RunStreamingAsync(IReadOnlyCollection<ChatMessage> messages, AgentThread? thread = null, AgentRunOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
|
|
{
|
|
this.InvokeCount++;
|
|
|
|
await (options?.OnIntermediateMessages?.Invoke(this.Response) ?? Task.CompletedTask);
|
|
|
|
foreach (ChatMessage message in this.Response)
|
|
{
|
|
yield return new ChatResponseUpdate(message.Role, message.Text);
|
|
}
|
|
}
|
|
}
|