-
Notifications
You must be signed in to change notification settings - Fork 892
.NET: Fix message ordering inconsistency when using AIContextProvider #2659
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: westey-m <[email protected]>
Co-authored-by: westey-m <[email protected]>
… Input, AIContextProvider Co-authored-by: westey-m <[email protected]>
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs
Outdated
Show resolved
Hide resolved
…havior Co-authored-by: westey-m <[email protected]>
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 fixes a message ordering inconsistency when using AIContextProvider in ChatClientAgent, ensuring that the order of messages sent to the chat client is consistent with the order of messages stored in the MessageStore.
Key Changes:
- Reordered message processing to place input messages before AIContextProvider messages in both the chat client request and message store
- Updated test assertions to reflect the new consistent ordering: [Existing, Input, AIContextProvider, Response]
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs | Moved the line that adds input messages to inputMessagesForChatClient before the AIContextProvider logic to ensure consistent ordering |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs | Updated test assertions and comments to reflect the new message ordering where user messages come before context provider messages |
Motivation and Context
This PR fixes a message ordering inconsistency when using AIContextProvider in ChatClientAgent. The original issue reported that messages sent to the chat client were in a different order than messages stored in the MessageStore, causing confusion and potential issues with message context.
Description
Fixed the message ordering to ensure consistency between messages sent to the chat client and messages stored in the MessageStore.
Before the fix:
[Existing, AIContextProvider, Input][Input, AIContextProvider, Response]After the fix:
[Existing, Input, AIContextProvider][Input, AIContextProvider, Response]Both now follow the same relative order where Input messages come before AIContextProvider messages.
Changes Made:
PrepareThreadAndMessagesAsyncmethod to add input messages before AIContextProvider messagesThe fix ensures that:
Contribution Checklist
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.