mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
* Rename AI Agent packages to use Microsoft.Agents.AI * Fix for build * Fix formatting * Fix formatting * Ignore in VSTHRD200 in migration samples * Ignore in VSTHRD200 in migration samples * Add some missing projects and run format * Fix build errors * Address code review feedback * Fix merge issues --------- Co-authored-by: Mark Wallace <markwallace@microsoft.com>
51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Agents.AI;
|
|
using Microsoft.Extensions.AI;
|
|
using Moq;
|
|
|
|
namespace Microsoft.Agents.Orchestration.UnitTest;
|
|
|
|
/// <summary>
|
|
/// Mock definition of <see cref="AIAgent"/>.
|
|
/// </summary>
|
|
internal sealed class MockAgent(int index) : AIAgent
|
|
{
|
|
public static MockAgent CreateWithResponse(int index, string response) => 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()
|
|
=> new Mock<AgentThread>().Object;
|
|
|
|
public override AgentThread DeserializeThread(System.Text.Json.JsonElement serializedThread, System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
|
|
=> new Mock<AgentThread>().Object;
|
|
|
|
public override Task<AgentRunResponse> RunAsync(IEnumerable<ChatMessage> messages, AgentThread? thread = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default)
|
|
{
|
|
this.InvokeCount++;
|
|
|
|
return Task.FromResult(new AgentRunResponse(messages: [.. this.Response]));
|
|
}
|
|
|
|
public override IAsyncEnumerable<AgentRunResponseUpdate> RunStreamingAsync(IEnumerable<ChatMessage> messages, AgentThread? thread = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default)
|
|
{
|
|
this.InvokeCount++;
|
|
|
|
return this.Response.Select(message => new AgentRunResponseUpdate(message.Role, message.Text)).ToAsyncEnumerable();
|
|
}
|
|
}
|