Skip to content

Conversation

@westey-m
Copy link
Contributor

@westey-m westey-m commented Nov 24, 2025

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.
Copilot AI review requested due to automatic review settings November 24, 2025 17:02
@github-actions github-actions bot 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 time Nov 24, 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 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.

File Description
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs Adds 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.cs New test file covering GetNewThread() overloads with factory and parameter-based scenarios
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_DeserializeThreadTests.cs New test file covering DeserializeThread() with factory scenarios
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs Refactors and adds tests for the new eager initialization behavior, including validation that exceptions are thrown when both ConversationId and MessageStore are used together

@westey-m 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 time Nov 24, 2025
@westey-m westey-m enabled auto-merge November 25, 2025 10:37
@westey-m westey-m added this pull request to the merge queue Nov 25, 2025
Merged via the queue into microsoft:main with commit 112410e Nov 25, 2025
14 checks passed
This was referenced Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants