Skip to content

.NET: [BREAKING] Change SerializeSession to be Async#3879

Merged
westey-m merged 3 commits intomicrosoft:mainfrom
westey-m:serializesession-async
Feb 12, 2026
Merged

.NET: [BREAKING] Change SerializeSession to be Async#3879
westey-m merged 3 commits intomicrosoft:mainfrom
westey-m:serializesession-async

Conversation

@westey-m
Copy link
Contributor

Motivation and Context

#3725

Description

  • Update AIAgent.SerializeSession to be async, to match DeserializeSession and CreateSession

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings February 12, 2026 10:48
@markwallace-microsoft markwallace-microsoft added .NET workflows Related to Workflows in agent-framework labels Feb 12, 2026
@github-actions github-actions bot changed the title Change SerializeSession to be Async .NET: Change SerializeSession to be Async Feb 12, 2026
@westey-m westey-m changed the title .NET: Change SerializeSession to be Async .NET: [BREAKING] Change SerializeSession to be Async Feb 12, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the .NET AIAgent session serialization API to be asynchronous, aligning it with the existing async session creation/deserialization patterns and propagating the change through implementations, tests, and samples.

Changes:

  • Replaced AIAgent.SerializeSession/SerializeSessionCore with SerializeSessionAsync/SerializeSessionCoreAsync (ValueTask-based, supports CancellationToken).
  • Updated all AIAgent implementations and call sites (workflows, hosting/session store, wrappers).
  • Updated unit/integration tests and samples to use the async API.

Reviewed changes

Copilot reviewed 42 out of 42 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.cs Introduces async session serialization API + new abstract core async method.
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentSession.cs Updates XML docs to reference SerializeSessionAsync.
dotnet/src/Microsoft.Agents.AI.Abstractions/DelegatingAIAgent.cs Forwards serialization via async API to inner agent.
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs Updates core serialization override to async ValueTask form.
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowHostAgent.cs Updates core serialization override to async ValueTask form.
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs Uses SerializeSessionAsync during checkpointing.
dotnet/src/Microsoft.Agents.AI.Hosting/Local/InMemoryAgentSessionStore.cs Awaits SerializeSessionAsync when persisting session state.
dotnet/src/Microsoft.Agents.AI.Purview/PurviewAgent.cs Wraps inner agent serialization via async API.
dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs Updates core serialization override to async ValueTask form.
dotnet/src/Microsoft.Agents.AI.CopilotStudio/CopilotStudioAgent.cs Updates core serialization override to async ValueTask form.
dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs Updates core serialization override to async ValueTask form.
dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgent.cs Updates core serialization override to async ValueTask form (Durable Task agent).
dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgentProxy.cs Updates core serialization override to async ValueTask form (proxy).
dotnet/tests/Microsoft.Agents.AI.AGUI.UnitTests/AGUIChatClientTests.cs Updates test to await SerializeSessionAsync.
dotnet/tests/Microsoft.Agents.AI.UnitTests/TestAIAgent.cs Updates test agent override signature to async core method.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentExtensionsTests.cs Updates nested test agent override signature to async core method.
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIAgentTests.cs Updates mock agent overrides to async core method signature.
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentRunContextTests.cs Updates nested test agent override signature to async core method.
dotnet/tests/Microsoft.Agents.AI.Hosting.AzureFunctions.UnitTests/TestAgent.cs Updates test agent override signature to async core method.
dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests/AGUIEndpointRouteBuilderExtensionsTests.cs Updates test agents to use async session serialization core override.
dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/SharedStateTests.cs Updates fake agent core serialization override + wraps returned JsonElement in ValueTask.
dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/ForwardedPropertiesTests.cs Updates fake agent core serialization override + wraps returned JsonElement in ValueTask.
dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/BasicStreamingTests.cs Updates fake agent core serialization override(s) to async signature.
dotnet/tests/Microsoft.Agents.AI.Declarative.UnitTests/AggregatorPromptAgentFactoryTests.cs Updates nested agent core serialization override signature.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs Updates test agent core serialization override signature.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestRequestAgent.cs Updates test agent core serialization override signature.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestReplayAgent.cs Updates test agent core serialization override signature.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestEchoAgent.cs Wraps serialized JsonElement in ValueTask for async core override.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/06_GroupChat_Workflow.cs Updates test agent core serialization override signature.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/RoleCheckAgent.cs Updates test agent core serialization override signature.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/RepresentationTests.cs Updates test agent core serialization override signature.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/InProcessExecutionTests.cs Updates nested test agent core serialization override signature.
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AgentWorkflowBuilderTests.cs Updates nested agent core serialization override signature.
dotnet/samples/M365Agent/AFAgentApplication.cs Updates sample to await SerializeSessionAsync.
dotnet/samples/GettingStarted/FoundryAgents/FoundryAgents_Step06_PersistedConversations/Program.cs Updates sample to await SerializeSessionAsync.
dotnet/samples/GettingStarted/Agents/Agent_Step20_AdditionalAIContext/Program.cs Updates sample to await SerializeSessionAsync.
dotnet/samples/GettingStarted/Agents/Agent_Step13_BackgroundResponsesWithToolsAndPersistence/Program.cs Updates helper to async and awaits SerializeSessionAsync.
dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyChatHistoryStorage/Program.cs Updates sample to await SerializeSessionAsync.
dotnet/samples/GettingStarted/Agents/Agent_Step06_PersistedConversations/Program.cs Updates sample to await SerializeSessionAsync.
dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step03_CustomMemory/Program.cs Updates sample to await SerializeSessionAsync.
dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step02_MemoryUsingMem0/Program.cs Updates sample to await SerializeSessionAsync.
dotnet/samples/GettingStarted/AgentProviders/Agent_With_CustomImplementation/Program.cs Updates custom agent example to async core serialization override.
Comments suppressed due to low confidence (1)

dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step03_CustomMemory/Program.cs:55

  • Variable name sesionElement looks like a typo; consider renaming to sessionElement (and updating its uses below) to keep the sample code clear.
JsonElement sesionElement = await agent.SerializeSessionAsync(session);

Console.WriteLine("\n>> Use deserialized session with previously created memories\n");

// Later we can deserialize the session and continue the conversation with the previous memory component state.
var deserializedSession = await agent.DeserializeSessionAsync(sesionElement);

@markwallace-microsoft markwallace-microsoft added the documentation Improvements or additions to documentation label Feb 12, 2026
@westey-m westey-m added this pull request to the merge queue Feb 12, 2026
Merged via the queue into microsoft:main with commit 6a88c7b Feb 12, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation .NET workflows Related to Workflows in agent-framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants