Skip to content

.Net: Add support for 3rd party thread storage and thread serialization#203

Merged
westey-m merged 42 commits intomicrosoft:mainfrom
westey-m:threadstorageandserialization
Aug 5, 2025
Merged

.Net: Add support for 3rd party thread storage and thread serialization#203
westey-m merged 42 commits intomicrosoft:mainfrom
westey-m:threadstorageandserialization

Conversation

@westey-m
Copy link
Contributor

@westey-m westey-m commented Jul 18, 2025

Motivation and Context

We need to be able to store thread messages in 3rd party storage.
We also need to be able to serialize/deserialize threads regardless of where the 3rd party storage is located.

Description

This PR adds thread storage and serialization in a way that the abstraction user doesn't have to know anything about the thread type or storage that it uses

  • It changes the ChatClientAgentThread into a MessageStoringAgentThread, that is more general, and can be used by any agent that wants to store messages locally, remotely via id, or in a 3rd party service. E.g. Custom agents can reuse this without needing to create their own thread type.
  • It introduces the IChatMessageStore interface that can be used with MessageStoringAgentThread to store messages in a database.
  • It shows how we can construct and deserialize a MessageStoringAgentThread that relies on a IChatMessageStore for storage.
  • It introduces Deserializing constructors on AgentThread and MessageStoringAgentThread.
  • It adds a DeseralizeThreadAsync abstract method on Agent that can recreate the right thread type with the right store (where needed) and deserialize the deserialized state into it.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the SK Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • I didn't break anyone 😄

@westey-m westey-m marked this pull request as ready for review July 21, 2025 17:39
Copilot AI review requested due to automatic review settings July 21, 2025 17:39
@westey-m westey-m changed the title Add thread storage and serialization POC Add support for 3rd party thread storage and thread serialization Jul 21, 2025
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

This PR implements a proof-of-concept for thread storage and serialization capabilities in the agent framework. It refactors the existing ChatClientAgentThread into a more general MessageStoringAgentThread that supports multiple storage locations and adds serialization/deserialization functionality to the agent thread system.

Key changes:

  • Replaces ChatClientAgentThread with MessageStoringAgentThread for more flexible message storage
  • Introduces serialization/deserialization capabilities for agent threads
  • Adds abstract DeserializeThread method to the base Agent class

Reviewed Changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
MessageStoringAgentThread.cs New implementation replacing ChatClientAgentThread with serialization support and flexible storage options
MessageStoringThreadStorageLocation.cs New enum defining storage location types (Unknown, AgentThreadManaged, ConversationId)
IChatMessageStore.cs New interface for custom message storage implementations
ChatClientAgent.cs Updated to use MessageStoringAgentThread and implement DeserializeThread method
AgentThread.cs Added serialization support and deserialization constructor
AIAgent.cs Added abstract DeserializeThread method
Various test files Updated type references and added comprehensive serialization tests

westey-m added 2 commits July 31, 2025 19:14
Make Thread Deserialize internal.
Make AgentThread type switching fobidden.
@westey-m westey-m added this pull request to the merge queue Aug 5, 2025
Merged via the queue into microsoft:main with commit ff3e13c Aug 5, 2025
14 checks passed
ReubenBond pushed a commit to ReubenBond/agent-framework that referenced this pull request Oct 28, 2025
…on (microsoft#203)

* Add thread storage and serialization POC

* Switch to using JsonElement and add unit tests

* Add additional unit tests.

* Exclude private debugger properties from CodeCoverage.

* Rename IChatMessagesStorable to IChatMessageStore

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Improve xml doc.

* Update the message storing thread to always use external store for both local and remote storage.

* Remove threadid from the IChatMessageStore interface, since the store should own the thread id itself, if it requires one.

* Switch GetMessages to IEnumerable

* Address pr comments.

* Make jsonserializer options default consistent on DeserializeThreadAsync

* Move message storing thread functionality into AgentThread and simplify AgentThread behavior.

* Remove embedding generation from VectorStore chat history sample.

* Remove unecessary code and fix formatting.

* Make GetNewThread and DeserializeThread virtual with default implementations.
Remove unsued json utilities.

* Fix formatting

* Remove problem test.

* Add more unit tests

* Remove unused using clause.

* Address pr feedback.

* Address PR comments.

* Make InMemory store internal

* Switch InMemoryChatMessageStore to implement IList instead of inheriting from List.

* Rename store deserialize param.

* Update serialization based on PR comments.

* Remove confusing comment.

* Address Deserialization PR comments in the same way as Serialization

* Add State to IChatMessageStore Serialize and Deserialize names.
Make Thread Deserialize internal.
Make AgentThread type switching fobidden.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
Arturo-Quiroga-MSFT pushed a commit to Arturo-Quiroga-MSFT/agent-framework-public that referenced this pull request Nov 23, 2025
…on (microsoft#203)

* Add thread storage and serialization POC

* Switch to using JsonElement and add unit tests

* Add additional unit tests.

* Exclude private debugger properties from CodeCoverage.

* Rename IChatMessagesStorable to IChatMessageStore

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Improve xml doc.

* Update the message storing thread to always use external store for both local and remote storage.

* Remove threadid from the IChatMessageStore interface, since the store should own the thread id itself, if it requires one.

* Switch GetMessages to IEnumerable

* Address pr comments.

* Make jsonserializer options default consistent on DeserializeThreadAsync

* Move message storing thread functionality into AgentThread and simplify AgentThread behavior.

* Remove embedding generation from VectorStore chat history sample.

* Remove unecessary code and fix formatting.

* Make GetNewThread and DeserializeThread virtual with default implementations.
Remove unsued json utilities.

* Fix formatting

* Remove problem test.

* Add more unit tests

* Remove unused using clause.

* Address pr feedback.

* Address PR comments.

* Make InMemory store internal

* Switch InMemoryChatMessageStore to implement IList instead of inheriting from List.

* Rename store deserialize param.

* Update serialization based on PR comments.

* Remove confusing comment.

* Address Deserialization PR comments in the same way as Serialization

* Add State to IChatMessageStore Serialize and Deserialize names.
Make Thread Deserialize internal.
Make AgentThread type switching fobidden.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

9 participants