-
Notifications
You must be signed in to change notification settings - Fork 2k
.NET: [BREAKING] Add ability to mark the source of Agent request messages and use that for filtering #3540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
westey-m
merged 9 commits into
microsoft:main
from
westey-m:agent-request-message-source
Feb 9, 2026
Merged
.NET: [BREAKING] Add ability to mark the source of Agent request messages and use that for filtering #3540
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
06d6f88
Add ability to mark the source of Agent request messages and use that…
westey-m 0c02171
Merge branch 'main' into agent-request-message-source
westey-m 01f5243
Merge branch 'main' into agent-request-message-source
westey-m 8842acf
Add support for source, in addition to source type, and add unit test…
westey-m 2c64d21
Address PR comments.
westey-m bc8b2fc
Merge branch 'main' into agent-request-message-source
westey-m e63023f
Merge branch 'main' into agent-request-message-source
westey-m 8cfdc09
Add merge fixes
westey-m 460bd6c
Address PR comments
westey-m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
106 changes: 106 additions & 0 deletions
106
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRequestMessageSource.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System; | ||
| using Microsoft.Extensions.AI; | ||
|
westey-m marked this conversation as resolved.
|
||
| using Microsoft.Shared.Diagnostics; | ||
|
|
||
| namespace Microsoft.Agents.AI; | ||
|
|
||
| /// <summary> | ||
| /// An enumeration representing the source of an agent request message. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Input messages for a specific agent run can originate from various sources. | ||
| /// This enumeration helps to identify whether a message came from outside the agent pipeline, | ||
|
westey-m marked this conversation as resolved.
Outdated
|
||
| /// whether it was produced by middleware, or came from chat history. | ||
| /// </remarks> | ||
| public sealed class AgentRequestMessageSource : IEquatable<AgentRequestMessageSource> | ||
| { | ||
| /// <summary> | ||
| /// Provides the key used in <see cref="ChatMessage.AdditionalProperties"/> to store the source of the agent request message. | ||
| /// </summary> | ||
| public static readonly string AdditionalPropertiesKey = "Agent.RequestMessageSource"; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AgentRequestMessageSource"/> class. | ||
| /// </summary> | ||
| /// <param name="value">The string value representing the source of the agent request message.</param> | ||
| public AgentRequestMessageSource(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; } | ||
|
|
||
| /// <summary> | ||
| /// The message came from outside the agent pipeline (e.g., user input). | ||
| /// </summary> | ||
| public static AgentRequestMessageSource External { get; } = new AgentRequestMessageSource(nameof(External)); | ||
|
|
||
| /// <summary> | ||
| /// The message was produced by middleware. | ||
| /// </summary> | ||
| public static AgentRequestMessageSource AIContextProvider { get; } = new AgentRequestMessageSource(nameof(AIContextProvider)); | ||
|
|
||
| /// <summary> | ||
| /// The message came from chat history. | ||
| /// </summary> | ||
| public static AgentRequestMessageSource ChatHistory { get; } = new AgentRequestMessageSource(nameof(ChatHistory)); | ||
|
|
||
| /// <summary> | ||
| /// Determines whether this instance and another specified <see cref="AgentRequestMessageSource"/> object have the same value. | ||
| /// </summary> | ||
| /// <param name="other">The <see cref="AgentRequestMessageSource"/> to compare to this instance.</param> | ||
| /// <returns><see langword="true"/> if the value of the <paramref name="other"/> parameter is the same as the value of this instance; otherwise, <see langword="false"/>.</returns> | ||
| public bool Equals(AgentRequestMessageSource? other) | ||
| { | ||
| if (other is null) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (ReferenceEquals(this, other)) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| return string.Equals(this.Value, other.Value, StringComparison.Ordinal); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Determines whether this instance and a specified object have the same value. | ||
| /// </summary> | ||
| /// <param name="obj">The object to compare to this instance.</param> | ||
| /// <returns><see langword="true"/> if <paramref name="obj"/> is a <see cref="AgentRequestMessageSource"/> and its value is the same as this instance; otherwise, <see langword="false"/>.</returns> | ||
| public override bool Equals(object? obj) => this.Equals(obj as AgentRequestMessageSource); | ||
|
|
||
| /// <summary> | ||
| /// Returns the hash code for this instance. | ||
| /// </summary> | ||
| /// <returns>A 32-bit signed integer hash code.</returns> | ||
| public override int GetHashCode() => this.Value?.GetHashCode() ?? 0; | ||
|
|
||
| /// <summary> | ||
| /// Determines whether two specified <see cref="AgentRequestMessageSource"/> objects have the same value. | ||
| /// </summary> | ||
| /// <param name="left">The first <see cref="AgentRequestMessageSource"/> to compare.</param> | ||
| /// <param name="right">The second <see cref="AgentRequestMessageSource"/> to compare.</param> | ||
| /// <returns><see langword="true"/> if the value of <paramref name="left"/> is the same as the value of <paramref name="right"/>; otherwise, <see langword="false"/>.</returns> | ||
| public static bool operator ==(AgentRequestMessageSource? left, AgentRequestMessageSource? right) | ||
| { | ||
| if (left is null) | ||
| { | ||
| return right is null; | ||
| } | ||
|
|
||
| return left.Equals(right); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Determines whether two specified <see cref="AgentRequestMessageSource"/> objects have different values. | ||
| /// </summary> | ||
| /// <param name="left">The first <see cref="AgentRequestMessageSource"/> to compare.</param> | ||
| /// <param name="right">The second <see cref="AgentRequestMessageSource"/> to compare.</param> | ||
| /// <returns><see langword="true"/> if the value of <paramref name="left"/> is different from the value of <paramref name="right"/>; otherwise, <see langword="false"/>.</returns> | ||
| public static bool operator !=(AgentRequestMessageSource? left, AgentRequestMessageSource? right) => !(left == right); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.