Skip to content

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

Closed

Description

@coderzhn

Describe the bug

SubAgentTool.sanitizeName decides whether to append the collision-avoidance hash from a
regex evaluated on the already lower-cased name, and that regex treats whitespace as a
safe character:

// SubAgentTool.java
String lowerOriginal = originalName.toLowerCase(Locale.ROOT);
String safePart = lowerOriginal
        .replaceAll("[^a-z0-9_-]+", "_")
        .replaceAll("_+", "_")
        .replaceAll("^_+|_+$", "");

boolean isInformationLost = lowerOriginal.matches("^[a-z0-9_\-\s]+$");
boolean needsHash = !isInformationLost || resolvedName.length() > 64;

The sanitization itself is lossy (case folding, whitespace/punctuation → _, collapsing _),
but the "did we lose information?" check does not see that. Two distinct agent names therefore
sanitize to the same tool name and both skip the hash:

image

Registering two sub-agents with such names fails hard. subAgent() goes through
Toolkit.registerAgentTool(..., allowReplace=false) → ToolRegistry.registerTool, which
throws on a duplicate name:

IllegalStateException: Tool 'call_researcher' is already registered and will not be silently replaced.

So a legitimate configuration cannot be built, and the error does not explain that two distinct
agent names were folded together.

To Reproduce (unit test, no model / network)

Agent a = mock(Agent.class);
when(a.getName()).thenReturn("Researcher");
Agent b = mock(Agent.class);
when(b.getName()).thenReturn("researcher");

String nameA = new SubAgentTool(() -> a, SubAgentConfig.defaults()).getName();
String nameB = new SubAgentTool(() -> b, SubAgentConfig.defaults()).getName();

assertEquals("call_researcher", nameA);
assertEquals("call_researcher", nameB); // collision: both are identical

The same holds for "data analyst" vs "data_analyst".

Expected behavior

Distinct agent names must not silently collapse to the same tool name. Either derive
collision-free names (append the existing deterministic hash whenever sanitization is lossy —
case folding, whitespace/punctuation replacement, or underscore collapsing), or reject the
configuration with an actionable error that names both conflicting agents. A name that is
already canonical (^[a-z0-9_-]+$, no extra spacing) should keep its stable tool name.

Environment

  • AgentScope-Java: main (2.1.0-SNAPSHOT)
  • Java: 17
  • Module: agentscope-core (io.agentscope.core.tool.subagent)

Activity

  1. added
    bug
    on Nov 16, 2026
  2. added a commit that references this issue on Nov 18, 2026
    13b9354
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions