.NET: [BREAKING] Update message source code to match python.#3805
Merged
westey-m merged 12 commits intomicrosoft:mainfrom Feb 10, 2026
Merged
.NET: [BREAKING] Update message source code to match python.#3805westey-m merged 12 commits intomicrosoft:mainfrom
westey-m merged 12 commits intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Aligns the .NET message “source” stamping schema with the Python implementation by moving from separate source keys to a single attribution object (source type + source id) stored in ChatMessage.AdditionalProperties.
Changes:
- Introduces
AgentRequestMessageSourceAttributionand updates providers to stamp messages with a single"attribution"entry (type + id). - Renames message source extension API to
GetAgentRequestMessageSourceType()and addsGetAgentRequestMessageSourceId(). - Updates all affected unit tests and message-filtering logic to use the new attribution model.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRequestMessageSourceAttribution.cs | Adds new attribution struct + key used for message stamping. |
| dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRequestMessageSourceType.cs | Converts source type to a struct and updates equality/default behavior. |
| dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRequestMessageSource.cs | Removes legacy source key constant. |
| dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageExtensions.cs | Renames source getter and adds source-id getter based on attribution. |
| dotnet/src/Microsoft.Agents.AI.Abstractions/ChatHistoryProvider.cs | Updates chat-history stamping to write/read attribution object. |
| dotnet/src/Microsoft.Agents.AI.Abstractions/ChatHistoryProviderExtensions.cs | Updates filters to use GetAgentRequestMessageSourceType(). |
| dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs | Updates AI-context stamping to write/read attribution object. |
| dotnet/src/Microsoft.Agents.AI/TextSearchProvider.cs | Updates filtering to use new source-type accessor. |
| dotnet/src/Microsoft.Agents.AI/Memory/ChatHistoryMemoryProvider.cs | Updates filtering to use new source-type accessor. |
| dotnet/src/Microsoft.Agents.AI.Mem0/Mem0Provider.cs | Updates filtering to use new source-type accessor. |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentRequestMessageSourceAttributionTests.cs | Adds coverage for attribution struct semantics. |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentRequestMessageSourceTypeTests.cs | Updates tests for struct/default semantics. |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatMessageExtensionsTests.cs | Updates tests and adds coverage for source-id accessor. |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIContextProviderTests.cs | Updates stamping assertions to validate attribution. |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatHistoryProviderTests.cs | Updates stamping assertions to validate attribution. |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/InMemoryChatHistoryProviderTests.cs | Updates request message setup to use attribution. |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatHistoryProviderMessageFilterTests.cs | Updates filter logic and message setup to use new accessor/attribution. |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatHistoryProviderExtensionsTests.cs | Updates message setup to use attribution. |
| dotnet/tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/CosmosChatHistoryProviderTests.cs | Updates message setup to use attribution. |
Comments suppressed due to low confidence (1)
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRequestMessageSourceType.cs:32
- Changing
AgentRequestMessageSourceTypefrom asealed classto areadonly struct(and removingAdditionalPropertiesKey) is a binary/source breaking change and also changes null/default semantics for consumers. If this is intentional, the PR/package should be treated as breaking; otherwise consider reintroducing compatibility shims (e.g., keep the old type/constant with[Obsolete], or provide a type-forwarding wrapper) so existing integrations continue to compile/run.
public readonly struct AgentRequestMessageSourceType : IEquatable<AgentRequestMessageSourceType>
{
/// <summary>
/// Initializes a new instance of the <see cref="AgentRequestMessageSourceType"/> struct.
/// </summary>
/// <param name="value">The string value representing the source of the agent request message.</param>
public AgentRequestMessageSourceType(string value) => this.Value = Throw.IfNullOrWhitespace(value);
/// <summary>
/// Get the string value representing the source of the agent request message.
/// </summary>
public string Value { get { return field ?? External.Value; } }
/// <summary>
/// The message came from outside the agent pipeline (e.g., user input).
/// </summary>
public static AgentRequestMessageSourceType External { get; } = new AgentRequestMessageSourceType(nameof(External));
...ests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentRequestMessageSourceAttributionTests.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRequestMessageSourceAttribution.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ey-m/agent-framework into message-source-python-match
markwallace-microsoft
approved these changes
Feb 10, 2026
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRequestMessageSourceAttribution.cs
Outdated
Show resolved
Hide resolved
SergeyMenshykh
approved these changes
Feb 10, 2026
SergeyMenshykh
approved these changes
Feb 10, 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
Updating the way in which source information are added for messages to match python.
Description
Contribution Checklist