mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
03ef7f054f
* Add AgentWorkflowBuilder group chat
And fix a variety of issues along the way:
- Use DateTime{Offset}.UtcNow rather than Now
- AIAgentHostExecutor shouldn't be publishing empty messages
- Sequential workflows should be flowing all history and not just the output from the previous agent as the input into the next agent
- Renamed some of the new agent workflow methods... still not super happy with the shape, though
- Simplified handoffs builder, e.g. using a hashset with a custom comparer instead of a dictionary
- Improved multi-service use by trying to change assistant->user role for messages created by other agents
- Changed MessageMerger to rely on M.E.AI's coalescing more and to avoid empty contents / text
- Ensured that messages from ChatClientAgent include MessageId and CreatedAt timestamps
- Avoided including instructions for agents in a handoff workflow that don't have any handoffs
- Removed the unnecessary end function in handoffs
- Improved naming of executors to include agent name for debuggability
- Use "N" formatting with Guid.ToString everywhere, to avoid the unnecessary extra dash character which is also not valid in various places (like function tool names)
- Replace `params T[]` with `params IEnumerable<T>` to make public APIs more flexible in what they consume
* Address feedback
- Fix unintentional provider change in sample
90 lines
2.7 KiB
C#
90 lines
2.7 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text.Json;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Microsoft.Extensions.AI.Agents.Abstractions.UnitTests;
|
|
|
|
/// <summary>
|
|
/// Contains tests for the <see cref="ChatMessageStore"/> class.
|
|
/// </summary>
|
|
public class ChatMessageStoreTests
|
|
{
|
|
#region GetService Method Tests
|
|
|
|
[Fact]
|
|
public void GetService_RequestingExactStoreType_ReturnsStore()
|
|
{
|
|
var store = new TestChatMessageStore();
|
|
var result = store.GetService(typeof(TestChatMessageStore));
|
|
Assert.NotNull(result);
|
|
Assert.Same(store, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetService_RequestingBaseStoreType_ReturnsStore()
|
|
{
|
|
var store = new TestChatMessageStore();
|
|
var result = store.GetService(typeof(ChatMessageStore));
|
|
Assert.NotNull(result);
|
|
Assert.Same(store, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetService_RequestingUnrelatedType_ReturnsNull()
|
|
{
|
|
var store = new TestChatMessageStore();
|
|
var result = store.GetService(typeof(string));
|
|
Assert.Null(result);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetService_WithServiceKey_ReturnsNull()
|
|
{
|
|
var store = new TestChatMessageStore();
|
|
var result = store.GetService(typeof(TestChatMessageStore), "some-key");
|
|
Assert.Null(result);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetService_WithNullServiceType_ThrowsArgumentNullException()
|
|
{
|
|
var store = new TestChatMessageStore();
|
|
Assert.Throws<ArgumentNullException>(() => store.GetService(null!));
|
|
}
|
|
|
|
[Fact]
|
|
public void GetService_Generic_ReturnsCorrectType()
|
|
{
|
|
var store = new TestChatMessageStore();
|
|
var result = store.GetService<TestChatMessageStore>();
|
|
Assert.NotNull(result);
|
|
Assert.Same(store, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetService_Generic_ReturnsNullForUnrelatedType()
|
|
{
|
|
var store = new TestChatMessageStore();
|
|
var result = store.GetService<string>();
|
|
Assert.Null(result);
|
|
}
|
|
|
|
#endregion
|
|
|
|
private sealed class TestChatMessageStore : ChatMessageStore
|
|
{
|
|
public override Task<IEnumerable<ChatMessage>> GetMessagesAsync(CancellationToken cancellationToken = default)
|
|
=> Task.FromResult<IEnumerable<ChatMessage>>([]);
|
|
|
|
public override Task AddMessagesAsync(IEnumerable<ChatMessage> messages, CancellationToken cancellationToken = default)
|
|
=> Task.CompletedTask;
|
|
|
|
public override ValueTask<JsonElement?> SerializeStateAsync(JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
|
|
=> default;
|
|
}
|
|
}
|