agentscope-ai/agentscope · error · ValueError
Cannot find group '{group_name}' in toolkit, only {[_.name f
Error message
Cannot find group '{group_name}' in toolkit, only {[_.name for _ in self.tool_groups]} are available. What it means
Toolkit.add_tool raises ValueError when the group_name argument does not match any registered tool group. The error lists the available group names so you can see what the toolkit actually knows about.
Source
Thrown at src/agentscope/tool/_toolkit.py:673
for new_tool in new_tools:
if new_tool.name in existing_tools:
logger.warning(
"Duplicate tool name '%s' found in group '%s', "
"overwriting it.",
new_tool.name,
group.name,
)
# override the existing tool
group.tools = [
t for t in group.tools if t.name != new_tool.name
] + [new_tool]
else:
group.tools.append(new_tool)
existing_tools.add(new_tool.name)
return
raise ValueError(
f"Cannot find group '{group_name}' in toolkit, only "
f"{[_.name for _ in self.tool_groups]} are available.",
)
async def remove_tool(self, tool_name: str | list[str]) -> None:
"""Remove tool from the toolkit on-the-fly.
Args:
tool_name (`str | list[str]`):
The name of the tool to be removed.
"""
if isinstance(tool_name, str):
tool_name = [tool_name]
for group in self.tool_groups:
group.tools = [
tool for tool in group.tools if tool.name not in tool_name
]View on GitHub (pinned to e90f1c7592)
Solutions
- Use one of the group names printed in the error message
- Create the group first: add a ToolGroup(name='X', tools=[]) to the Toolkit before add_tool
- Guard by checking `[g.name for g in toolkit.tool_groups]` before calling add_tool
Example fix
# before await toolkit.add_tool(mem_tool, group_name='memory') # group doesn't exist # after toolkit = Toolkit(tool_groups=[ToolGroup(name='memory', tools=[]), ...]) await toolkit.add_tool(mem_tool, group_name='memory')
Defensive patterns
Strategy: validation
Validate before calling
available = [g.name for g in toolkit.tool_groups]
if group_name not in available:
group_name = available[0] # or raise with a clear message
await toolkit.add_tool(tool, group_name=group_name) Try / catch
try:
await toolkit.add_tool(tool, group_name=group_name)
except ValueError as e:
# parse available names from e and retry with a valid group Prevention
- Define group-name constants used both when creating groups and when calling add_tool
- Create empty target groups up-front in toolkit construction
When it happens
Trigger: Calling await toolkit.add_tool(tool, group_name='X') where 'X' is not among [g.name for g in toolkit.tool_groups]; e.g. 'search' when only a 'default' group exists.
Common situations: Agents adding tools on the fly (e.g. memory tools in ReAct flows) targeting a group name that was never created; typos or case mismatches in group names; assuming a default group name exists when a custom set was passed.
Related errors
- Tool groups must not contain duplicate tool groups.
- The injection template must contain the '{runtime_state}' pl
- MCP {card.name!r} produced an invalid client: {e}
- DimensionPolicy: kind=ANY requires dimension=None, got dimen
- DimensionPolicy: kind={self.kind.value} requires a positive
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/ed83411e7acfad2a.
Report an issue: GitHub.