Files
agent-framework/dotnet/tests/Microsoft.Extensions.AI.Agents.Abstractions.UnitTests/AIContextProviderTests.cs
T
westeyandGitHub 66fe1c957c .NET: Add AIContextProvider support (#691)
* Add AIContextProvider support

* Address feedback.

* Address PR comments.

* Switch to valuetask and remove parallel calls for AIContextProvider

* Remove Model from ModelInvokingAsync method name

* Remove agent thread id again and remove it from context provider interface

* Add AIContextProvider serialization support to AgentThread and update sample to show this feature

* Address PR comments

* Improve memory sample

* Update sample comment.

* Remove AggregateAIContextProvider for now since it makes too many assumptions.  We can include it later as a sample if needed.

* Update AIContextProviders to have an Invoked method instead of MessagesAddingAsync.

* Remove unused using.

* Address PR comments.

* Address PR comment.

* Update comment.

* Update comment

* Address PR comments.
2025-09-16 09:54:18 +00:00

57 lines
1.9 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System.Collections.Generic;
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>(new List<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);
}
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);
}
}
}