Skip to content

.NET: [BREAKING] Update message source code to match python.#3805

Merged
westey-m merged 12 commits intomicrosoft:mainfrom
westey-m:message-source-python-match
Feb 10, 2026
Merged

.NET: [BREAKING] Update message source code to match python.#3805
westey-m merged 12 commits intomicrosoft:mainfrom
westey-m:message-source-python-match

Conversation

@westey-m
Copy link
Contributor

Motivation and Context

Updating the way in which source information are added for messages to match python.

Description

  • Update message source code to match python.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings February 10, 2026 11:47
@github-actions github-actions bot changed the title Update message source code to match python. .NET: Update message source code to match python. Feb 10, 2026
@westey-m westey-m changed the title .NET: Update message source code to match python. .NET: [BREAKING] Update message source code to match python. Feb 10, 2026
Copy link
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

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 AgentRequestMessageSourceAttribution and updates providers to stamp messages with a single "attribution" entry (type + id).
  • Renames message source extension API to GetAgentRequestMessageSourceType() and adds GetAgentRequestMessageSourceId().
  • 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 AgentRequestMessageSourceType from a sealed class to a readonly struct (and removing AdditionalPropertiesKey) 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));

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@westey-m westey-m added this pull request to the merge queue Feb 10, 2026
Merged via the queue into microsoft:main with commit 7dccf3a Feb 10, 2026
14 checks passed
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.

4 participants