Skip to content

Conversation

@westey-m
Copy link
Contributor

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

Motivation and Context

The NotifyThreadOfNewMessagesAsync helper is not required anymore, since all agents know their thread types and can call the internals of the thread to set messages directly. Previously this was not the case, but we have moved away from this, so removing the unnecessary code.

This is potentially breaking for AIAgent implementers.

Description

  • Remove NotifyThreadOfNewMessagesAsync helper method on AIAgent, and changing AIAgent implementations to update their threads directly if needed.

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.

Copy link
Member

@rogerbarreto rogerbarreto left a comment

Choose a reason for hiding this comment

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

Should this considered [Breaking] ?

Wonder which scenarios will stop working after this change.

@westey-m westey-m changed the title Remove NotifyThreadOfNewMessagesAsync AIAgent helper [BREAKING] Remove NotifyThreadOfNewMessagesAsync AIAgent helper Nov 25, 2025
@westey-m
Copy link
Contributor Author

Should this considered [Breaking] ?

Wonder which scenarios will stop working after this change.

It's only potentially breaking for AIAgent implementers. It really depends on their scenario though. You'll see that only two of our currently agent types actually use this, so impact should be low. I've updated it with [breaking] anyway. Thanks!

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 removes the NotifyThreadOfNewMessagesAsync helper method from the AIAgent base class and refactors agent implementations to directly update their thread message stores. This simplifies the architecture by eliminating an abstraction layer that is no longer needed now that all agents have typed knowledge of their threads.

Key Changes

  • Removed MessagesReceivedAsync virtual method from AgentThread base class and its overrides in ChatClientAgentThread, InMemoryAgentThread, and WorkflowThread
  • Removed NotifyThreadOfNewMessagesAsync protected helper method from AIAgent base class
  • Added new private NotifyMessageStoreOfNewMessagesAsync method in ChatClientAgent that directly calls AddMessagesAsync on the message store
  • Updated sample code to directly call MessageStore.AddMessagesAsync instead of using the removed helper

Reviewed changes

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

Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThread.cs Removed the MessagesReceivedAsync virtual method that threads used to override
dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.cs Removed the NotifyThreadOfNewMessagesAsync protected helper method
dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryAgentThread.cs Removed the MessagesReceivedAsync override that added messages to the store
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs Added new private NotifyMessageStoreOfNewMessagesAsync method and updated message store initialization to include default fallback
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentThread.cs Removed the MessagesReceivedAsync override that handled the three-case logic for message storage
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowThread.cs Removed the MessagesReceivedAsync override
dotnet/samples/GettingStarted/AgentProviders/Agent_With_CustomImplementation/Program.cs Updated to directly call MessageStore.AddMessagesAsync with added type validation
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentThreadTests.cs Removed tests for the removed OnNewMessagesAsync functionality
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentThreadTests.cs Removed test for the MessagesReceivedAsync method
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIAgentTests.cs Removed test for the NotifyThreadOfNewMessagesAsync helper method

@westey-m westey-m added this pull request to the merge queue Nov 25, 2025
Merged via the queue into microsoft:main with commit b6c3b8d Nov 25, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants