Skip to content

.NET: [BREAKING] Add GetNewThread overload for taking a ChatMessageStore at thread creation time - #2429

Merged
westey (westey-m) merged 7 commits into
microsoft:mainfrom
westey-m:chatclientagent-getnewthread-store-overload
Nov 25, 2025
Merged

.NET: [BREAKING] Add GetNewThread overload for taking a ChatMessageStore at thread creation time#2429
westey (westey-m) merged 7 commits into
microsoft:mainfrom
westey-m:chatclientagent-getnewthread-store-overload

Conversation

@westey-m

@westey-mwestey (westey-m) commented Nov 24, 2025

Copy link
Copy Markdown
Contributor

Motivation and Context

In some cases users may need to provide a custom ChatMessageStore to a ChatClientAgent when they create the thread, instead of via a factory. E.g. when users need to do some async processing to generate a custom thread id.
Users may also want to access the message store object from the thread before doing the first run, to update it for their specific scenario.

#2325

Description

  • Add GetNewThread overload for taking a ChatMessageStore at thread creation time
  • Move message store creation to thread creation time, so it can be accessed before the first run.

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.

…ation time and move message store creation to thread creation time.
CopilotAI review requested due to automatic review settings November 24, 2025 17:02
@markwallace-microsoftMark Wallace (markwallace-microsoft) added the .NET Usage: [Issues, PRs], Target: .Net label Nov 24, 2025
@github-actionsgithub-actionsBot changed the title Add GetNewThread overload for taking a ChatMessageStore at thread creation time.NET: Add GetNewThread overload for taking a ChatMessageStore at thread creation timeNov 24, 2025

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 adds a new GetNewThread(ChatMessageStore) overload that allows users to provide a custom ChatMessageStore instance at thread creation time, addressing scenarios where async processing is needed to generate a custom thread ID or where users need to access the message store before the first run.

Key Changes

  • Adds GetNewThread(ChatMessageStore) overload for directly providing a message store instance
  • Moves message store creation from lazy initialization (during first run) to eager initialization (at thread creation time) when using ChatMessageStoreFactory
  • Updates test coverage with new test files and modified existing tests to validate the new behavior

Reviewed changes

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

FileDescription
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.csAdds new GetNewThread(ChatMessageStore) overload with XML documentation and modifies parameterless GetNewThread() to eagerly create message store from factory
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_GetNewThreadTests.csNew test file covering GetNewThread() overloads with factory and parameter-based scenarios
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_DeserializeThreadTests.csNew test file covering DeserializeThread() with factory scenarios
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.csRefactors and adds tests for the new eager initialization behavior, including validation that exceptions are thrown when both ConversationId and MessageStore are used together

Comment threaddotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs Outdated
Comment threaddotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs
@westey-mwestey (westey-m) changed the title .NET: Add GetNewThread overload for taking a ChatMessageStore at thread creation time.NET: [BREAKING] Add GetNewThread overload for taking a ChatMessageStore at thread creation timeNov 24, 2025
Comment threaddotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs Outdated
Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Aris Nguyen (arisng) pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
…ore at thread creation time (microsoft#2429)
* Add GetNewThread overload for taking a ChatMessageStore at thread creation time and move message store creation to thread creation time.
* Fix formatting.
* Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Apply suggestion from @rogerbarreto
Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
@westey-m
westey (westey-m) deleted the chatclientagent-getnewthread-store-overload branch February 25, 2026 14:15
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NETUsage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@westey-m@rogerbarreto@SergeyMenshykh@markwallace-microsoft