[dotnet-code] Extract agent tool name sanitizer - #926
Conversation
Align the Go agent-tool internals with the .NET SanitizeAgentName helper shape while preserving existing naming behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR extracts the agent tool-name sanitization logic in tool/agenttool into an unexported sanitizeAgentName helper, aligning the Go internal shape with the referenced .NET SanitizeAgentName helper while preserving existing behavior.
Changes:
- Refactored
functool.Name()to callsanitizeAgentName(name)instead of inlining the regex replacement. - Added a private
sanitizeAgentNamehelper that centralizes theinvalidNameCharsreplacement logic.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
API Consistency ReviewScope: internal-only This is an internal-only refactor. No public API review (
|
Summary
Extracted agent-tool name sanitization into an unexported
sanitizeAgentNamehelper. This keeps existing behavior while making the Go internals structurally closer to the .NETSanitizeAgentNamehelper used when exposing agents as function tools..NET Reference
dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs-SanitizeAgentNamehelper used byAsAIFunctionmetadata generation.dotnet/src/Microsoft.Agents.AI/FunctionInvocationDelegatingAgent.cs- sampled agent/function invocation area; rejected because Go already has separate tool auto-call middleware and this PR focuses on the safer agent-tool metadata shape.dotnet/src/Microsoft.Agents.AI.Workflows/AgentResponseUpdateEvent.cs- sampled workflow response-update event area; rejected because the Go workflow event model does not have a similarly narrow internal cleanup.dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/ChatCompletionRequestMessage.cs- sampled provider message conversion area; rejected to avoid provider serialization churn.dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsSourceContext.cs- sampled skills context area; rejected because the Go skills source shape is already minimal and changing it would risk API surface changes.Public API and Behavior
No public Go API changed. No intentional behavior change was made.
Tests
go test ./tool/agenttoolExisting agent-tool tests continue to cover sanitized names, fallback-to-ID behavior, default descriptions, and invocation behavior.
Notes
Checked for open
[dotnet-code]PRs before editing. Exact searches foragenttoolandSanitizeAgentNamefound no candidate-specific open PR; one broader low-integrity result was filtered by policy and could not be inspected, so the change was kept narrowly scoped to the exact helper extraction.Closes #918