// Copyright (c) Microsoft. All rights reserved. using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using AgentConversation.IntegrationTests; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; using Moq; namespace Microsoft.Agents.AI.Abstractions.IntegrationTests; /// /// An example that uses an in-memory mock /// so the harness can be exercised without live AI service credentials. /// /// /// In a real integration test against a live AI service (e.g., OpenAI Chat Completion), this class /// would be replaced with an implementation that constructs instances /// backed by the real . The compaction contract can similarly be wired up /// to an of your choice. /// public sealed class InMemoryConversationTestSystem : IConversationTestSystem { /// /// A deterministic response suffix appended by the mock chat client to every assistant reply. /// Test validations can assert on this value to confirm the mock was invoked. /// public const string MockResponseSuffix = "[mock-response]"; /// public Task CreateAgentAsync( ConversationAgentDefinition definition, CancellationToken cancellationToken = default) { // Create a mock IChatClient that returns a deterministic response. var mockClient = new Mock(); mockClient .Setup(c => c.GetResponseAsync( It.IsAny>(), It.IsAny(), It.IsAny())) .ReturnsAsync(() => new ChatResponse( new ChatMessage(ChatRole.Assistant, $"Here are today's specials: Clam Chowder, Cobb Salad, Chai Tea. {MockResponseSuffix}"))); // GetService is called internally by the harness for metadata; return null for unknown types. mockClient .Setup(c => c.GetService(It.IsAny(), It.IsAny())) .Returns((System.Type _, object? _) => null); AIAgent agent = new ChatClientAgent( mockClient.Object, options: new ChatClientAgentOptions { Name = definition.Name, ChatOptions = new ChatOptions { Instructions = definition.Instructions, Tools = definition.Tools is not null ? new System.Collections.Generic.List(definition.Tools) : null, } }); return Task.FromResult(agent); } /// public Task?> CompactAsync( IList messages, CancellationToken cancellationToken = default) { // No compaction in this example system. return Task.FromResult?>(null); } }