mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
* Subclass AgentThread so that different agents have their own threads with their own typed settings. * Address PR comment. * Add unit tests for base abstract threads * Fix style warning * Fix stlying * FIx and suppress warnings as needed. * Remove covariant thread response types and fix some styling. * Remove unecessary json property name attributes and make OrchestratingAgentThread private * Fix break from merge from main. * Fix formatting * Fix deserialization bug in Memory sample * Remove thread deletion from basic samples. * Remove public constructors for thread subclasses and add more factory methods to concrete agent types. * Update AgentProxy thread constructors to be internal as well. * Revert AgentProxyThread to internal * Change AIContextProvider to internal set * Change conversation id and message store properties to internal set * Update styling. * Seal various thread types. * Add thread type check for thread deletion * Fix tests after latest merge from main * Add thread type checks for thread deletion. --------- Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
69 lines
2.3 KiB
C#
69 lines
2.3 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.Text.Json;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Microsoft.Extensions.AI.Agents.Abstractions.UnitTests;
|
|
|
|
public class AIContextProviderTests
|
|
{
|
|
[Fact]
|
|
public async Task InvokedAsync_ReturnsCompletedTaskAsync()
|
|
{
|
|
var provider = new TestAIContextProvider();
|
|
var messages = new ReadOnlyCollection<ChatMessage>([]);
|
|
var task = provider.InvokedAsync(new(messages));
|
|
Assert.Equal(default, task);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SerializeAsync_ReturnsEmptyElementAsync()
|
|
{
|
|
var provider = new TestAIContextProvider();
|
|
var actual = await provider.SerializeAsync();
|
|
Assert.Equal(default, actual);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task DeserializeAsync_ReturnsCompletedTaskAsync()
|
|
{
|
|
var provider = new TestAIContextProvider();
|
|
var element = default(JsonElement);
|
|
var actual = provider.DeserializeAsync(element);
|
|
Assert.Equal(default, actual);
|
|
}
|
|
|
|
[Fact]
|
|
public void InvokingContext_Constructor_ThrowsForNullMessages()
|
|
{
|
|
Assert.Throws<ArgumentNullException>(() => new AIContextProvider.InvokingContext(null!));
|
|
}
|
|
|
|
[Fact]
|
|
public void InvokedContext_Constructor_ThrowsForNullMessages()
|
|
{
|
|
Assert.Throws<ArgumentNullException>(() => new AIContextProvider.InvokedContext(null!));
|
|
}
|
|
|
|
private sealed class TestAIContextProvider : AIContextProvider
|
|
{
|
|
public override ValueTask<AIContext> InvokingAsync(InvokingContext context, CancellationToken cancellationToken = default)
|
|
{
|
|
return default;
|
|
}
|
|
|
|
public override async ValueTask<JsonElement?> SerializeAsync(JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
|
|
{
|
|
return await base.SerializeAsync(jsonSerializerOptions, cancellationToken);
|
|
}
|
|
|
|
public override async ValueTask DeserializeAsync(JsonElement serializedState, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
|
|
{
|
|
await base.DeserializeAsync(serializedState, jsonSerializerOptions, cancellationToken);
|
|
}
|
|
}
|
|
}
|