Skip to content

.NET: [BREAKING] Move AgentSession.Serialize to AIAgent - #3650

Merged
westey (westey-m) merged 7 commits into
microsoft:mainfrom
westey-m:serialize-move
Feb 4, 2026
Merged

.NET: [BREAKING] Move AgentSession.Serialize to AIAgent#3650
westey (westey-m) merged 7 commits into
microsoft:mainfrom
westey-m:serialize-move

Conversation

@westey-m

Copy link
Copy Markdown
Contributor

Motivation and Context

#3646

Description

  • Move AgentSession.Serialize to AIAgent

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.

CopilotAI review requested due to automatic review settings February 3, 2026 18:07
@markwallace-microsoftMark Wallace (markwallace-microsoft) added .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows labels Feb 3, 2026
@github-actionsgithub-actionsBot changed the title Move AgentSession.Serialize to AIAgent.NET: Move AgentSession.Serialize to AIAgentFeb 3, 2026

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the serialization API by moving the Serialize method from AgentSession to AIAgent as SerializeSession. This change makes the API more consistent by centralizing session lifecycle management (creation, serialization, and deserialization) on the AIAgent class rather than splitting it between agent and session.

Changes:

  • Removed public virtual Serialize method from AgentSession base class
  • Added public abstract SerializeSession method to AIAgent that takes a session parameter
  • Updated all concrete agent implementations to implement SerializeSession with type checking
  • Changed session-level Serialize methods to internal or protected internal virtual visibility
  • Updated all usages in samples, tests, and production code to call agent.SerializeSession(session) instead of session.Serialize()

Reviewed changes

Copilot reviewed 51 out of 51 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentSession.csRemoved public Serialize method and updated documentation
dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.csAdded public abstract SerializeSession method
dotnet/src/Microsoft.Agents.AI.Abstractions/DelegatingAIAgent.csAdded delegation of SerializeSession to inner agent
dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryAgentSession.csChanged Serialize to protected internal virtual
dotnet/src/Microsoft.Agents.AI.Abstractions/ServiceIdAgentSession.csChanged Serialize to protected internal virtual
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.csImplemented SerializeSession with type validation
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentSession.csChanged Serialize to internal
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowHostAgent.csImplemented SerializeSession with type validation
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowSession.csChanged Serialize to internal
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.csUpdated to use agent.SerializeSession instead of session.Serialize
dotnet/src/Microsoft.Agents.AI.Purview/PurviewAgent.csAdded delegation of SerializeSession to inner agent
dotnet/src/Microsoft.Agents.AI.Hosting/Local/InMemoryAgentSessionStore.csUpdated to use agent.SerializeSession
dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.csImplemented SerializeSession with type validation
dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgentSession.csChanged Serialize to internal
dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgent.csImplemented SerializeSession with type validation
dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgentProxy.csImplemented SerializeSession with type validation
dotnet/src/Microsoft.Agents.AI.DurableTask/DurableAgentSession.csChanged Serialize to internal
dotnet/src/Microsoft.Agents.AI.CopilotStudio/CopilotStudioAgent.csImplemented SerializeSession with type validation
dotnet/src/Microsoft.Agents.AI.CopilotStudio/CopilotStudioAgentSession.csAdded internal new Serialize method
dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.csImplemented SerializeSession with type validation
dotnet/src/Microsoft.Agents.AI.A2A/A2AAgentSession.csChanged Serialize to internal
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentSessionTests.csRemoved obsolete test for old Serialize method
dotnet/tests/Microsoft.Agents.AI.AGUI.UnitTests/AGUIChatClientTests.csUpdated test to use agent.SerializeSession
dotnet/tests/Microsoft.Agents.AI.DurableTask.UnitTests/DurableAgentSessionTests.csTest calls internal Serialize directly (valid for internal testing)
dotnet/tests/**/*.cs (multiple test files)Added NotImplementedException stubs for SerializeSession in test agents
dotnet/samples/**/*.cs (multiple sample files)Updated to use agent.SerializeSession pattern

Comment threaddotnet/src/Microsoft.Agents.AI.DurableTask/DurableAIAgent.cs
Comment threaddotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.cs
@westey-mwestey (westey-m) changed the title .NET: Move AgentSession.Serialize to AIAgent.NET: [BREAKING] Move AgentSession.Serialize to AIAgentFeb 4, 2026
@markwallace-microsoftMark Wallace (markwallace-microsoft) added the documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs label Feb 4, 2026
…ng where the the result of the serialization is never used.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentationUsage: [Issues, PRs], Target: documentation in the code base and learn docs.NETUsage: [Issues, PRs], Target: .NetworkflowsUsage: [Issues, PRs], Target: Workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@westey-m@rogerbarreto@markwallace-microsoft