Skip to content

fix(core): keep derived sub-agent tool names collision-free across case and spacing - #4208

Merged
jujn merged 3 commits into
agentscope-ai:mainfrom
coderzhn:fix/subagent-name-collision
Nov 18, 2026
Merged

jujn merged 3 commits into
agentscope-ai:mainfrom
coderzhn:fix/subagent-name-collision

Conversation

@coderzhn

Copy link
Copy Markdown
Contributor

Summary

  • SubAgentTool.sanitizeName skipped its collision-avoidance hash based on a regex over the
    already lower-cased name that treated whitespace as safe. Because sanitization is lossy
    (case folding, whitespace/punctuation → _, underscore collapsing), "Researcher"/
    "researcher" and "data analyst"/"data_analyst" collapsed to the same tool name with no
    hash on either side, and fail-fast Toolkit registration then threw a duplicate-tool error.
  • Treat a name as collision-free only when sanitizing it lost nothing
    (originalName.equals(safePart)), so any lossy transform appends the existing deterministic
    hash. Already-canonical names keep their stable tool name.

Behavior note

Names that are not already canonical (uppercase, spaces, punctuation) now gain the hash suffix
even without a colliding sibling, because sanitizeName has no sibling context. Users who need
an exact tool name can pin it with SubAgentTool/SubAgentConfig.toolName. Open to switching to
registration-time collision detection instead if preferred.

Test plan

  • New SubAgentToolNameCollisionTest: case-only and space/underscore names must not collide;
    canonical researcher stays call_researcher; derived names remain OpenAI-compatible.
  • Fails with identical names before the fix; passes after.
  • SubAgent* suite: 29 tests, 0 failures. Spotless passes.

Closes #4207

coderzhn and others added 3 commits November 13, 2026 18:27
…se and spacing

SubAgentTool.sanitizeName decides whether to append a collision-avoidance hash
from a regex over the already lower-cased name that treats whitespace as a safe
character. Two distinct agent names can therefore sanitize to the same tool
name without either receiving a hash: "Researcher" and "researcher" both become
"call_researcher", and "data analyst" and "data_analyst" both become
"call_data_analyst". Toolkit registration is fail-fast on duplicate tool names,
so a legitimate configuration with such sub-agents fails to build with a
duplicate-tool error.

A derived name is collision-free only when sanitizing it lost nothing, i.e. the
original name already equals its sanitized form. Base the hash decision on that
equality instead of the "safe characters" regex, so case folding, whitespace or
punctuation replacement, and underscore collapsing all trigger the hash, while
an already-canonical lowercase name keeps its stable tool name.
@jujn jujn added the P0 重要紧急 label Nov 16, 2026
@jujn
jujn merged commit 13b9354 into agentscope-ai:main Nov 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P0 重要紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:SubAgentTool derives the same tool name for agent names that differ only by case or spacing — registration fails with a duplicate-tool error

2 participants