mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
ff3e13c2aa
* Add thread storage and serialization POC * Switch to using JsonElement and add unit tests * Add additional unit tests. * Exclude private debugger properties from CodeCoverage. * Rename IChatMessagesStorable to IChatMessageStore * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Improve xml doc. * Update the message storing thread to always use external store for both local and remote storage. * Remove threadid from the IChatMessageStore interface, since the store should own the thread id itself, if it requires one. * Switch GetMessages to IEnumerable * Address pr comments. * Make jsonserializer options default consistent on DeserializeThreadAsync * Move message storing thread functionality into AgentThread and simplify AgentThread behavior. * Remove embedding generation from VectorStore chat history sample. * Remove unecessary code and fix formatting. * Make GetNewThread and DeserializeThread virtual with default implementations. Remove unsued json utilities. * Fix formatting * Remove problem test. * Add more unit tests * Remove unused using clause. * Address pr feedback. * Address PR comments. * Make InMemory store internal * Switch InMemoryChatMessageStore to implement IList instead of inheriting from List. * Rename store deserialize param. * Update serialization based on PR comments. * Remove confusing comment. * Address Deserialization PR comments in the same way as Serialization * Add State to IChatMessageStore Serialize and Deserialize names. Make Thread Deserialize internal. Make AgentThread type switching fobidden. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
77 lines
2.6 KiB
C#
77 lines
2.6 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using AgentConformance.IntegrationTests;
|
|
using AgentConformance.IntegrationTests.Support;
|
|
using Microsoft.Extensions.AI;
|
|
using Microsoft.Extensions.AI.Agents;
|
|
using OpenAI;
|
|
using Shared.IntegrationTests;
|
|
|
|
namespace OpenAIChatCompletion.IntegrationTests;
|
|
|
|
public class OpenAIChatCompletionFixture : IChatClientAgentFixture
|
|
{
|
|
private static readonly OpenAIConfiguration s_config = TestConfiguration.LoadSection<OpenAIConfiguration>();
|
|
private readonly bool _useReasoningModel;
|
|
|
|
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
|
|
private ChatClientAgent _agent;
|
|
|
|
public OpenAIChatCompletionFixture(bool useReasoningChatModel)
|
|
{
|
|
this._useReasoningModel = useReasoningChatModel;
|
|
}
|
|
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
|
|
|
|
public AIAgent Agent => this._agent;
|
|
|
|
public IChatClient ChatClient => this._agent.ChatClient;
|
|
|
|
public async Task<List<ChatMessage>> GetChatHistoryAsync(AgentThread thread)
|
|
{
|
|
return await thread.GetMessagesAsync().ToListAsync();
|
|
}
|
|
|
|
public Task<ChatClientAgent> CreateChatClientAgentAsync(
|
|
string name = "HelpfulAssistant",
|
|
string instructions = "You are a helpful assistant.",
|
|
IList<AITool>? aiTools = null)
|
|
{
|
|
var chatClient = new OpenAIClient(s_config.ApiKey)
|
|
.GetChatClient(this._useReasoningModel ? s_config.ChatReasoningModelId : s_config.ChatModelId)
|
|
.AsIChatClient();
|
|
|
|
return Task.FromResult(new ChatClientAgent(chatClient, options: new()
|
|
{
|
|
Name = name,
|
|
Instructions = instructions,
|
|
ChatOptions = new() { Tools = aiTools }
|
|
}));
|
|
}
|
|
|
|
public Task DeleteAgentAsync(ChatClientAgent agent)
|
|
{
|
|
// Chat Completion does not require/support deleting agents, so this is a no-op.
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task DeleteThreadAsync(AgentThread thread)
|
|
{
|
|
// Chat Completion does not require/support deleting threads, so this is a no-op.
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public async Task InitializeAsync()
|
|
{
|
|
this._agent = await this.CreateChatClientAgentAsync();
|
|
}
|
|
|
|
public Task DisposeAsync()
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|