.NET: Fix message ordering inconsistency when using AIContextProvider#2659
Merged
.NET: Fix message ordering inconsistency when using AIContextProvider#2659
Conversation
Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix inconsistency of message ordering with AIContextProvider
Fix message ordering inconsistency when using AIContextProvider
Dec 5, 2025
westey-m
requested changes
Dec 5, 2025
Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com>
Copilot
AI
changed the title
Fix message ordering inconsistency when using AIContextProvider
Add tests to validate message ordering with AIContextProvider
Dec 5, 2025
… Input, AIContextProvider Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com>
Copilot
AI
changed the title
Add tests to validate message ordering with AIContextProvider
Fix message ordering inconsistency when using AIContextProvider
Dec 5, 2025
westey-m
reviewed
Dec 5, 2025
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs
Outdated
Show resolved
Hide resolved
…havior Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com>
This was referenced Feb 9, 2026
This was referenced Feb 16, 2026
This was referenced Feb 23, 2026
Open
This was referenced Mar 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.