diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs index 7f1245a0e3..ee902f00c3 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs @@ -30,7 +30,7 @@ AgentThread thread = agent.GetNewThread(); Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.", thread)); // Serialize the thread state to a JsonElement, so it can be stored for later use. -JsonElement serializedThread = await thread.SerializeAsync(); +JsonElement serializedThread = thread.Serialize(); // Save the serialized thread to a temporary file (for demonstration purposes). string tempFilePath = Path.GetTempFileName(); diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs index a1dd2e7e35..ff4744bd08 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs @@ -56,7 +56,7 @@ Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate.", thread) // Serialize the thread state, so it can be stored for later use. // Since the chat history is stored in the vector store, the serialized thread // only contains the guid that the messages are stored under in the vector store. -JsonElement serializedThread = await thread.SerializeAsync(); +JsonElement serializedThread = thread.Serialize(); Console.WriteLine("\n--- Serialized thread ---\n"); Console.WriteLine(JsonSerializer.Serialize(serializedThread, new JsonSerializerOptions { WriteIndented = true })); @@ -131,9 +131,9 @@ namespace SampleApp return messages; } - public override ValueTask SerializeStateAsync(JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) => + public override JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptions = null) => // We have to serialize the thread id, so that on deserialization we can retrieve the messages using the same thread id. - new(JsonSerializer.SerializeToElement(this.ThreadDbKey)); + JsonSerializer.SerializeToElement(this.ThreadDbKey); /// /// The data structure used to store chat history items in the vector store. diff --git a/dotnet/samples/GettingStarted/Agents/Agent_Step13_Memory/Program.cs b/dotnet/samples/GettingStarted/Agents/Agent_Step13_Memory/Program.cs index 94a58e4e22..6eedd2ba91 100644 --- a/dotnet/samples/GettingStarted/Agents/Agent_Step13_Memory/Program.cs +++ b/dotnet/samples/GettingStarted/Agents/Agent_Step13_Memory/Program.cs @@ -52,7 +52,7 @@ Console.WriteLine(await agent.RunAsync("My name is RuaidhrĂ­", thread)); Console.WriteLine(await agent.RunAsync("I am 20 years old", thread)); // We can serialize the thread. The serialized state will include the state of the memory component. -var threadElement = await thread.SerializeAsync(); +var threadElement = thread.Serialize(); Console.WriteLine("\n>> Use deserialized thread with previously created memories\n"); @@ -148,9 +148,9 @@ namespace SampleApp }); } - public override ValueTask SerializeAsync(JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) + public override JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptions = null) { - return new ValueTask(JsonSerializer.SerializeToElement(this.UserInfo, jsonSerializerOptions)); + return JsonSerializer.SerializeToElement(this.UserInfo, jsonSerializerOptions); } } diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs index 51446cbe43..020d7a033c 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs @@ -39,20 +39,15 @@ public abstract class AIContextProvider /// The to monitor for cancellation requests. The default is . /// A task that completes when the context has been rendered and returned. public virtual ValueTask InvokedAsync(InvokedContext context, CancellationToken cancellationToken = default) - { - return default; - } + => default; /// /// Serializes the current object's state to a using the specified serialization options. /// /// The JSON serialization options to use. - /// The to monitor for cancellation requests. The default is . /// A representation of the object's state. - public virtual ValueTask SerializeAsync(JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) - { - return default; - } + public virtual JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptions = null) + => default; /// Asks the for an object of the specified type . /// The type of object being requested. diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThread.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThread.cs index 30d9f96f19..74a9383d24 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThread.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThread.cs @@ -27,10 +27,9 @@ public abstract class AgentThread /// Serializes the current object's state to a using the specified serialization options. /// /// The JSON serialization options to use. - /// The to monitor for cancellation requests. The default is . /// A representation of the object's state. - public virtual Task SerializeAsync(JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) - => Task.FromResult(default(JsonElement)); + public virtual JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptions = null) + => default; /// /// This method is called when new messages have been contributed to the chat by any participant. diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs index a63bd0f334..ae79eb5460 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs @@ -51,9 +51,8 @@ public abstract class ChatMessageStore /// Serializes the current object's state to a using the specified serialization options. /// /// The JSON serialization options to use. - /// The to monitor for cancellation requests. The default is . /// A representation of the object's state. - public abstract ValueTask SerializeStateAsync(JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default); + public abstract JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptions = null); /// Asks the for an object of the specified type . /// The type of object being requested. diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryAgentThread.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryAgentThread.cs index 042a9a67c4..8affd74da6 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryAgentThread.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryAgentThread.cs @@ -67,11 +67,10 @@ public abstract class InMemoryAgentThread : AgentThread /// Serializes the current object's state to a using the specified serialization options. /// /// The JSON serialization options to use. - /// The to monitor for cancellation requests. The default is . /// A representation of the object's state. - public override async Task SerializeAsync(JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) + public override JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptions = null) { - var storeState = await this.MessageStore.SerializeStateAsync(jsonSerializerOptions, cancellationToken).ConfigureAwait(false); + var storeState = this.MessageStore.Serialize(jsonSerializerOptions); var state = new InMemoryAgentThreadState { diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryChatMessageStore.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryChatMessageStore.cs index 726de61ac3..7bb92e85ac 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryChatMessageStore.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryChatMessageStore.cs @@ -121,14 +121,14 @@ public sealed class InMemoryChatMessageStore : ChatMessageStore, IList - public override ValueTask SerializeStateAsync(JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) + public override JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptions = null) { StoreState state = new() { Messages = this._messages, }; - return new ValueTask(JsonSerializer.SerializeToElement(state, AgentAbstractionsJsonUtilities.DefaultOptions.GetTypeInfo(typeof(StoreState)))); + return JsonSerializer.SerializeToElement(state, AgentAbstractionsJsonUtilities.DefaultOptions.GetTypeInfo(typeof(StoreState))); } /// diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/ServiceIdAgentThread.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/ServiceIdAgentThread.cs index 0da69debc4..4d322ec33f 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/ServiceIdAgentThread.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/ServiceIdAgentThread.cs @@ -2,8 +2,6 @@ using System; using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; using Microsoft.Shared.Diagnostics; namespace Microsoft.Agents.AI; @@ -63,9 +61,8 @@ public abstract class ServiceIdAgentThread : AgentThread /// Serializes the current object's state to a using the specified serialization options. /// /// The JSON serialization options to use. - /// The to monitor for cancellation requests. The default is . /// A representation of the object's state. - public override async Task SerializeAsync(JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) + public override JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptions = null) { var state = new ServiceIdAgentThreadState { diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting/AgentActor.cs b/dotnet/src/Microsoft.Agents.AI.Hosting/AgentActor.cs index 393f796157..f8d9902c6b 100644 --- a/dotnet/src/Microsoft.Agents.AI.Hosting/AgentActor.cs +++ b/dotnet/src/Microsoft.Agents.AI.Hosting/AgentActor.cs @@ -121,7 +121,7 @@ internal sealed class AgentActor( } var serializedRunResponse = JsonSerializer.SerializeToElement(updates.ToAgentRunResponse(), AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(AgentRunResponse))); - var updatedThread = await this._thread.SerializeAsync(AgentHostingJsonUtilities.DefaultOptions, cancellationToken).ConfigureAwait(false); + var updatedThread = this._thread.Serialize(AgentHostingJsonUtilities.DefaultOptions); var writeResponse = await context.WriteAsync( new(this._etag, diff --git a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentThread.cs b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentThread.cs index 735391569f..4a44862497 100644 --- a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentThread.cs +++ b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentThread.cs @@ -149,21 +149,16 @@ public class ChatClientAgentThread : AgentThread /// public AIContextProvider? AIContextProvider { get; internal set; } - /// - /// Serializes the current object's state to a using the specified serialization options. - /// - /// The JSON serialization options to use. - /// The to monitor for cancellation requests. The default is . - /// A representation of the object's state. - public override async Task SerializeAsync(JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) + /// + public override JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptions = null) { - var storeState = this._messageStore is null ? + JsonElement? storeState = this._messageStore is null ? null : - await this._messageStore.SerializeStateAsync(jsonSerializerOptions, cancellationToken).ConfigureAwait(false); + this._messageStore.Serialize(jsonSerializerOptions); - var aiContextProviderState = this.AIContextProvider is null ? + JsonElement? aiContextProviderState = this.AIContextProvider is null ? null : - await this.AIContextProvider.SerializeAsync(jsonSerializerOptions, cancellationToken).ConfigureAwait(false); + this.AIContextProvider.Serialize(jsonSerializerOptions); var state = new ThreadState { diff --git a/dotnet/src/Microsoft.Agents.Workflows/Specialized/AIAgentHostExecutor.cs b/dotnet/src/Microsoft.Agents.Workflows/Specialized/AIAgentHostExecutor.cs index 7f98c8e7e0..a3831aab8c 100644 --- a/dotnet/src/Microsoft.Agents.Workflows/Specialized/AIAgentHostExecutor.cs +++ b/dotnet/src/Microsoft.Agents.Workflows/Specialized/AIAgentHostExecutor.cs @@ -30,7 +30,7 @@ internal sealed class AIAgentHostExecutor : ChatProtocolExecutor Task threadTask = Task.CompletedTask; if (this._thread is not null) { - JsonElement threadValue = await this._thread.SerializeAsync(cancellationToken: cancellation).ConfigureAwait(false); + JsonElement threadValue = this._thread.Serialize(); threadTask = context.QueueStateUpdateAsync(ThreadStateKey, threadValue).AsTask(); } diff --git a/dotnet/src/Microsoft.Agents.Workflows/WorkflowMessageStore.cs b/dotnet/src/Microsoft.Agents.Workflows/WorkflowMessageStore.cs index d8fbb8909c..fd07c5a8bc 100644 --- a/dotnet/src/Microsoft.Agents.Workflows/WorkflowMessageStore.cs +++ b/dotnet/src/Microsoft.Agents.Workflows/WorkflowMessageStore.cs @@ -65,7 +65,7 @@ internal sealed class WorkflowMessageStore : ChatMessageStore public void UpdateBookmark() => this._bookmark = this._chatMessages.Count; - public override ValueTask SerializeStateAsync(JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) + public override JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptions = null) { StoreState state = new() { @@ -73,8 +73,7 @@ internal sealed class WorkflowMessageStore : ChatMessageStore Messages = this._chatMessages, }; - return new ValueTask - (JsonSerializer.SerializeToElement(state, - WorkflowsJsonUtilities.DefaultOptions.GetTypeInfo(typeof(StoreState)))); + return JsonSerializer.SerializeToElement(state, + WorkflowsJsonUtilities.DefaultOptions.GetTypeInfo(typeof(StoreState))); } } diff --git a/dotnet/src/Microsoft.Agents.Workflows/WorkflowThread.cs b/dotnet/src/Microsoft.Agents.Workflows/WorkflowThread.cs index d6fe919cdc..54e5ba2835 100644 --- a/dotnet/src/Microsoft.Agents.Workflows/WorkflowThread.cs +++ b/dotnet/src/Microsoft.Agents.Workflows/WorkflowThread.cs @@ -2,8 +2,6 @@ using System; using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; using Microsoft.Shared.Diagnostics; @@ -28,7 +26,8 @@ internal sealed class WorkflowThread : AgentThread public string ResponseId => $"{this.RunId}@{this.Halts}"; - public override Task SerializeAsync(JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) => throw new NotImplementedException("Pending Checkpointing work."); + public override JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptions = null) + => throw new NotImplementedException("Pending Checkpointing work."); public AgentRunResponseUpdate CreateUpdate(params AIContent[] parts) { diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIContextProviderTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIContextProviderTests.cs index 1414a398a4..666f1ec95c 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIContextProviderTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIContextProviderTests.cs @@ -21,10 +21,10 @@ public class AIContextProviderTests } [Fact] - public async Task SerializeAsync_ReturnsEmptyElementAsync() + public void Serialize_ReturnsEmptyElement() { var provider = new TestAIContextProvider(); - var actual = await provider.SerializeAsync(); + var actual = provider.Serialize(); Assert.Equal(default, actual); } @@ -163,9 +163,9 @@ public class AIContextProviderTests return default; } - public override async ValueTask SerializeAsync(JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) + public override JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptions = null) { - return await base.SerializeAsync(jsonSerializerOptions, cancellationToken); + return base.Serialize(jsonSerializerOptions); } } } diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentThreadTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentThreadTests.cs index a1bf57201d..4d7c4ad219 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentThreadTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentThreadTests.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Threading.Tasks; using Microsoft.Extensions.AI; #pragma warning disable CA1861 // Avoid constant arrays as arguments @@ -15,10 +14,10 @@ namespace Microsoft.Agents.AI.Abstractions.UnitTests; public class AgentThreadTests { [Fact] - public async Task SerializeAsync_ReturnsDefaultJsonElementAsync() + public void Serialize_ReturnsDefaultJsonElement() { var thread = new TestAgentThread(); - var result = await thread.SerializeAsync(); + var result = thread.Serialize(); Assert.Equal(default, result); } diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatMessageStoreTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatMessageStoreTests.cs index e96d497c8c..4100b20f5a 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatMessageStoreTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatMessageStoreTests.cs @@ -84,7 +84,7 @@ public class ChatMessageStoreTests public override Task AddMessagesAsync(IEnumerable messages, CancellationToken cancellationToken = default) => Task.CompletedTask; - public override ValueTask SerializeStateAsync(JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) + public override JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptions = null) => default; } } diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/InMemoryAgentThreadTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/InMemoryAgentThreadTests.cs index 60947c8ebc..f0fde6fc61 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/InMemoryAgentThreadTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/InMemoryAgentThreadTests.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text.Json; -using System.Threading.Tasks; using Microsoft.Extensions.AI; namespace Microsoft.Agents.AI.Abstractions.UnitTests; @@ -58,11 +57,11 @@ public class InMemoryAgentThreadTests } [Fact] - public async Task Constructor_WithSerializedState_SetsPropertyAsync() + public void Constructor_WithSerializedState_SetsProperty() { // Arrange InMemoryChatMessageStore store = [new(ChatRole.User, "TestMsg")]; - var storeState = await store.SerializeStateAsync(); + var storeState = store.Serialize(); var json = JsonSerializer.SerializeToElement(new { storeState }); // Act @@ -89,13 +88,13 @@ public class InMemoryAgentThreadTests #region SerializeAsync Tests [Fact] - public async Task SerializeAsync_ReturnsCorrectJson_WhenMessagesExistAsync() + public void Serialize_ReturnsCorrectJson_WhenMessagesExist() { // Arrange var thread = new TestInMemoryAgentThread([new(ChatRole.User, "TestContent")]); // Act - var json = await thread.SerializeAsync(); + var json = thread.Serialize(); // Assert Assert.Equal(JsonValueKind.Object, json.ValueKind); @@ -108,13 +107,13 @@ public class InMemoryAgentThreadTests } [Fact] - public async Task SerializeAsync_ReturnsEmptyMessages_WhenNoMessagesAsync() + public void Serialize_ReturnsEmptyMessages_WhenNoMessages() { // Arrange var thread = new TestInMemoryAgentThread(); // Act - var json = await thread.SerializeAsync(); + var json = thread.Serialize(); // Assert Assert.Equal(JsonValueKind.Object, json.ValueKind); diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/InMemoryChatMessageStoreTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/InMemoryChatMessageStoreTests.cs index 5bb5071056..fedd0ce591 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/InMemoryChatMessageStoreTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/InMemoryChatMessageStoreTests.cs @@ -106,8 +106,8 @@ public class InMemoryChatMessageStoreTests new ChatMessage(ChatRole.Assistant, "B") }; - var jsonElement = await store.SerializeStateAsync(); - var newStore = new InMemoryChatMessageStore(jsonElement.Value); + var jsonElement = store.Serialize(); + var newStore = new InMemoryChatMessageStore(jsonElement); Assert.Equal(2, newStore.Count); Assert.Equal("A", newStore[0].Text); diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ServiceIdAgentThreadTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ServiceIdAgentThreadTests.cs index 169843d57c..8999b0abe4 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ServiceIdAgentThreadTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ServiceIdAgentThreadTests.cs @@ -2,7 +2,6 @@ using System; using System.Text.Json; -using System.Threading.Tasks; namespace Microsoft.Agents.AI.Abstractions.UnitTests; @@ -74,13 +73,13 @@ public class ServiceIdAgentThreadTests #region SerializeAsync Tests [Fact] - public async Task SerializeAsync_ReturnsCorrectJson_WhenServiceThreadIdIsSetAsync() + public void Serialize_ReturnsCorrectJson_WhenServiceThreadIdIsSet() { // Arrange var thread = new TestServiceIdAgentThread("service-id-789"); // Act - var json = await thread.SerializeAsync(); + var json = thread.Serialize(); // Assert Assert.Equal(JsonValueKind.Object, json.ValueKind); @@ -89,13 +88,13 @@ public class ServiceIdAgentThreadTests } [Fact] - public async Task SerializeAsync_ReturnsUndefinedServiceThreadId_WhenNotSetAsync() + public void Serialize_ReturnsUndefinedServiceThreadId_WhenNotSet() { // Arrange var thread = new TestServiceIdAgentThread(); // Act - var json = await thread.SerializeAsync(); + var json = thread.Serialize(); // Assert Assert.Equal(JsonValueKind.Object, json.ValueKind); diff --git a/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentThreadTests.cs b/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentThreadTests.cs index 7906b3a096..8226e697ca 100644 --- a/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentThreadTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentThreadTests.cs @@ -216,13 +216,13 @@ public class ChatClientAgentThreadTests /// Verify thread serialization to JSON when the thread has an id. /// [Fact] - public async Task VerifyThreadSerializationWithIdAsync() + public void VerifyThreadSerializationWithId() { // Arrange var thread = new ChatClientAgentThread { ConversationId = "TestConvId" }; // Act - var json = await thread.SerializeAsync(); + var json = thread.Serialize(); // Assert Assert.Equal(JsonValueKind.Object, json.ValueKind); @@ -237,14 +237,14 @@ public class ChatClientAgentThreadTests /// Verify thread serialization to JSON when the thread has messages. /// [Fact] - public async Task VerifyThreadSerializationWithMessagesAsync() + public void VerifyThreadSerializationWithMessages() { // Arrange InMemoryChatMessageStore store = [new(ChatRole.User, "TestContent") { AuthorName = "TestAuthor" }]; var thread = new ChatClientAgentThread { MessageStore = store }; // Act - var json = await thread.SerializeAsync(); + var json = thread.Serialize(); // Assert Assert.Equal(JsonValueKind.Object, json.ValueKind); @@ -269,14 +269,13 @@ public class ChatClientAgentThreadTests } [Fact] - public async Task VerifyThreadSerializationWithWithAIContextProviderAsync() + public void VerifyThreadSerializationWithWithAIContextProvider() { // Arrange Mock mockProvider = new(); - var providerStateElement = JsonSerializer.SerializeToElement(["CP1"], TestJsonSerializerContext.Default.StringArray); mockProvider - .Setup(m => m.SerializeAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(providerStateElement); + .Setup(m => m.Serialize(It.IsAny())) + .Returns(JsonSerializer.SerializeToElement(["CP1"], TestJsonSerializerContext.Default.StringArray)); var thread = new ChatClientAgentThread { @@ -284,7 +283,7 @@ public class ChatClientAgentThreadTests }; // Act - var json = await thread.SerializeAsync(); + var json = thread.Serialize(); // Assert Assert.Equal(JsonValueKind.Object, json.ValueKind); @@ -292,14 +291,14 @@ public class ChatClientAgentThreadTests Assert.Equal(JsonValueKind.Array, providerStateProperty.ValueKind); Assert.Single(providerStateProperty.EnumerateArray()); Assert.Equal("CP1", providerStateProperty.EnumerateArray().First().GetString()); - mockProvider.Verify(m => m.SerializeAsync(It.IsAny(), It.IsAny()), Times.Once); + mockProvider.Verify(m => m.Serialize(It.IsAny()), Times.Once); } /// /// Verify thread serialization to JSON with custom options. /// [Fact] - public async Task VerifyThreadSerializationWithCustomOptionsAsync() + public void VerifyThreadSerializationWithCustomOptions() { // Arrange var thread = new ChatClientAgentThread(); @@ -312,12 +311,12 @@ public class ChatClientAgentThreadTests var messageStoreMock = new Mock(); messageStoreMock - .Setup(m => m.SerializeStateAsync(options, It.IsAny())) - .ReturnsAsync(storeStateElement); + .Setup(m => m.Serialize(options)) + .Returns(storeStateElement); thread.MessageStore = messageStoreMock.Object; // Act - var json = await thread.SerializeAsync(options); + var json = thread.Serialize(options); // Assert Assert.Equal(JsonValueKind.Object, json.ValueKind); @@ -330,7 +329,7 @@ public class ChatClientAgentThreadTests Assert.True(storeStateProperty.TryGetProperty("Key", out var keyProperty)); Assert.Equal("TestValue", keyProperty.GetString()); - messageStoreMock.Verify(m => m.SerializeStateAsync(options, It.IsAny()), Times.Once); + messageStoreMock.Verify(m => m.Serialize(options), Times.Once); } #endregion Serialize Tests