Skip to content

.NET: Sanitize agent name - #1368

Merged
SergeyMenshykh merged 12 commits into
microsoft:mainfrom
SergeyMenshykh:sanitize-agent-name
Oct 10, 2025
Merged

.NET: Sanitize agent name#1368
SergeyMenshykh merged 12 commits into
microsoft:mainfrom
SergeyMenshykh:sanitize-agent-name

Conversation

@SergeyMenshykh

@SergeyMenshykh SergeyMenshykh commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

Fixes #1351 for AF .NET.

@SergeyMenshykh SergeyMenshykh self-assigned this Oct 9, 2025
Copilot AI review requested due to automatic review settings October 9, 2025 19:42
@markwallace-microsoft markwallace-microsoft added the .NET Usage: [Issues, PRs], Target: .Net label Oct 9, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs Outdated
SergeyMenshykh and others added 2 commits October 9, 2025 20:44
Comment thread dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs Outdated
Comment thread dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentExtensionsTests.cs
SergeyMenshykh and others added 3 commits October 9, 2025 21:24
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>
Comment thread dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs Outdated
@SergeyMenshykh
SergeyMenshykh added this pull request to the merge queue Oct 10, 2025
Merged via the queue into microsoft:main with commit 3730db3 Oct 10, 2025
14 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in Agent Framework 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Python: A2A Agent as a Tool (replacing any space or special characters)

5 participants