.NET: feat: add context provider message merge hook#6303
Open
JarreNejatyab wants to merge 1 commit into
Open
Conversation
✨ - Generated by Copilot
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds an overridable message-merging hook so derived context providers can control how provided context messages are combined with user/input messages (e.g., prepend vs append), with unit tests validating prepend behavior.
Changes:
- Introduce
MergeMessages(...)as aprotected virtualextension point inAIContextProviderand route message merging through it. - Update
MessageAIContextProviderto useMergeMessages(...)during invocation. - Add unit tests demonstrating overriding
MergeMessages(...)to prepend provider messages.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs | Adds MergeMessages hook and uses it when combining input/provided messages. |
| dotnet/src/Microsoft.Agents.AI.Abstractions/MessageAIContextProvider.cs | Switches from direct Concat to MergeMessages for message combination. |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIContextProviderTests.cs | Adds test coverage for overriding merge behavior to prepend provided messages. |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/MessageAIContextProviderTests.cs | Adds test coverage for overriding merge behavior to prepend provided messages. |
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.
Adds a protected virtual
MergeMessageshook for AI context providers so implementations can customize where provided messages are placed relative to input messages without reimplementing filtering and source attribution.Summary:
AIContextProvider.MergeMessages(...)with the existing append behavior as the default.MessageAIContextProviderto use the inherited merge hook after source attribution.Validation:
dotnet build src/Microsoft.Agents.AI.Abstractions/Microsoft.Agents.AI.Abstractions.csprojdotnet test --project tests/Microsoft.Agents.AI.Abstractions.UnitTests/(net10.0 passed; net472 runner requires mono on Linux)dotnet test --project tests/Microsoft.Agents.AI.UnitTests/Microsoft.Agents.AI.UnitTests.csproj(net10.0 passed; net472 runner requires mono on Linux)