.NET: Sanitize agent name - #1368
Merged
SergeyMenshykh merged 12 commits intoOct 10, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds agent name sanitization functionality to ensure agent names are compatible when used as AI function names. The implementation replaces invalid characters with underscores to create valid function identifiers.
- Sanitizes agent names by replacing non-alphanumeric characters (except underscores) with underscores
- Uses source-generated regex for .NET and compiled regex for older frameworks for optimal performance
- Adds comprehensive test coverage for various agent name patterns and edge cases
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs | Implements agent name sanitization logic with regex-based character replacement |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentExtensionsTests.cs | Adds parameterized tests to verify sanitization behavior for different input patterns |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
SergeyMenshykh
had a problem deploying
to
integration
October 9, 2025 19:43 — with
GitHub Actions
Error
SergeyMenshykh
had a problem deploying
to
integration
October 9, 2025 19:43 — with
GitHub Actions
Error
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
SergeyMenshykh
temporarily deployed
to
integration
October 9, 2025 19:44 — with
GitHub Actions
Inactive
SergeyMenshykh
temporarily deployed
to
integration
October 9, 2025 19:44 — with
GitHub Actions
Inactive
stephentoub
reviewed
Oct 9, 2025
stephentoub
reviewed
Oct 9, 2025
stephentoub
reviewed
Oct 9, 2025
stephentoub
approved these changes
Oct 9, 2025
Co-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
…s.cs Co-authored-by: Stephen Toub <stoub@microsoft.com>
SergeyMenshykh
enabled auto-merge
October 9, 2025 20:24
SergeyMenshykh
had a problem deploying
to
integration
October 9, 2025 20:25 — with
GitHub Actions
Failure
SergeyMenshykh
had a problem deploying
to
integration
October 9, 2025 20:25 — with
GitHub Actions
Failure
stephentoub
approved these changes
Oct 9, 2025
stephentoub
reviewed
Oct 9, 2025
…laced with a single one.
SergeyMenshykh
had a problem deploying
to
integration
October 9, 2025 20:36 — with
GitHub Actions
Error
SergeyMenshykh
had a problem deploying
to
integration
October 9, 2025 20:36 — with
GitHub Actions
Error
SergeyMenshykh
temporarily deployed
to
integration
October 9, 2025 20:37 — with
GitHub Actions
Inactive
SergeyMenshykh
temporarily deployed
to
integration
October 9, 2025 20:37 — with
GitHub Actions
Inactive
SergeyMenshykh
temporarily deployed
to
integration
October 9, 2025 21:28 — with
GitHub Actions
Inactive
SergeyMenshykh
temporarily deployed
to
integration
October 9, 2025 21:28 — with
GitHub Actions
Inactive
SergeyMenshykh
temporarily deployed
to
integration
October 10, 2025 07:47 — with
GitHub Actions
Inactive
SergeyMenshykh
temporarily deployed
to
integration
October 10, 2025 07:47 — with
GitHub Actions
Inactive
SergeyMenshykh
temporarily deployed
to
integration
October 10, 2025 16:23 — with
GitHub Actions
Inactive
SergeyMenshykh
temporarily deployed
to
integration
October 10, 2025 16:23 — with
GitHub Actions
Inactive
westey-m
approved these changes
Oct 10, 2025
ReubenBond
pushed a commit
to ReubenBond/agent-framework
that referenced
this pull request
Oct 28, 2025
* sanitize agent name * simplify * Update dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * Update dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * Update dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentExtensionsTests.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * change regex to flag underscores as well so their sequence can be replaced with a single one. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Stephen Toub <stoub@microsoft.com>
arisng
pushed a commit
to arisng/agent-framework
that referenced
this pull request
Feb 2, 2026
* sanitize agent name * simplify * Update dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * Update dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * Update dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentExtensionsTests.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * change regex to flag underscores as well so their sequence can be replaced with a single one. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Stephen Toub <stoub@microsoft.com>
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.
Fixes #1351 for AF .NET.