Skip to content

.NET: feat: add context provider message merge hook#6303

Open
JarreNejatyab wants to merge 1 commit into
microsoft:mainfrom
JarreNejatyab:feature/message-merge-mode
Open

.NET: feat: add context provider message merge hook#6303
JarreNejatyab wants to merge 1 commit into
microsoft:mainfrom
JarreNejatyab:feature/message-merge-mode

Conversation

@JarreNejatyab
Copy link
Copy Markdown

Adds a protected virtual MergeMessages hook for AI context providers so implementations can customize where provided messages are placed relative to input messages without reimplementing filtering and source attribution.

Summary:

  • Added AIContextProvider.MergeMessages(...) with the existing append behavior as the default.
  • Updated MessageAIContextProvider to use the inherited merge hook after source attribution.
  • Added unit coverage showing providers can prepend supplied context messages before user input.

Validation:

  • dotnet build src/Microsoft.Agents.AI.Abstractions/Microsoft.Agents.AI.Abstractions.csproj
  • dotnet 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)

Copilot AI review requested due to automatic review settings June 3, 2026 11:35
Copy link
Copy Markdown
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

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 a protected virtual extension point in AIContextProvider and route message merging through it.
  • Update MessageAIContextProvider to use MergeMessages(...) 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.

@moonbox3 moonbox3 added the .NET label Jun 3, 2026
@github-actions github-actions Bot changed the title feat: add context provider message merge hook .NET: feat: add context provider message merge hook Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants