Harden default handoff tool name normalization#123
Open
Mark Zhang (shuofengzhang) wants to merge 2 commits intolangchain-ai:mainfrom
Open
Harden default handoff tool name normalization#123Mark Zhang (shuofengzhang) wants to merge 2 commits intolangchain-ai:mainfrom
Mark Zhang (shuofengzhang) wants to merge 2 commits intolangchain-ai:mainfrom
Conversation
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.
What changed
_normalize_agent_nameinlanggraph_swarm/handoff.pyso default handoff tool names are safe for provider tool/function naming constraints:[a-z0-9_]characters with_agentwhen normalization would otherwise become emptytests/test_swarm.py:R&D Agent / v2now normalizes totransfer_to_r_d_agent_v2!!!) now normalize totransfer_to_agentWhy
create_handoff_toolbuilds a default tool name fromagent_name. Previously only whitespace was normalized, so punctuation was preserved. For real-world agent names (R&D Agent,ops/bot, etc.), this can generate tool names that are rejected by some model/tool providers, causing runtime failures during tool binding or invocation.Insight / Why this matters
Root cause: normalization handled spacing but not invalid symbols. That leaves a hidden integration edge case where swarm setup looks correct, but fails later when the LLM provider validates function names.
Why easy to miss: examples typically use simple names like
Alice/Bob, so this only appears with more realistic team-style names and specific providers.Tradeoff: this slightly changes generated default tool names for punctuation-heavy agent names, but only toward safer/portable identifiers. Explicitly provided
name=remains unchanged.Practical gain / Why this matters
Testing
.venv/bin/pytest -q6 passed