-
Notifications
You must be signed in to change notification settings - Fork 945
[BREAKING] Remove NotifyThreadOfNewMessagesAsync AIAgent helper #2450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BREAKING] Remove NotifyThreadOfNewMessagesAsync AIAgent helper #2450
Conversation
rogerbarreto
left a comment
There was a problem hiding this 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.
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! |
There was a problem hiding this 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
MessagesReceivedAsyncvirtual method fromAgentThreadbase class and its overrides inChatClientAgentThread,InMemoryAgentThread, andWorkflowThread - Removed
NotifyThreadOfNewMessagesAsyncprotected helper method fromAIAgentbase class - Added new private
NotifyMessageStoreOfNewMessagesAsyncmethod inChatClientAgentthat directly callsAddMessagesAsyncon the message store - Updated sample code to directly call
MessageStore.AddMessagesAsyncinstead 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 |
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
Contribution Checklist