huggingface/smolagents · error · ValueError
Each tool or managed_agent should have a unique name! You pa
Error message
Each tool or managed_agent should have a unique name! You passed these duplicate names: {[name for name in tool_and_managed_agent_names if tool_and_managed_agent_names.count(name) > 1]} What it means
Every tool and managed agent attached to an agent (plus the agent's own name) must have a unique name, because the framework dispatches tool calls and generates code referencing them by name. _validate_tools_and_managed_agents raises ValueError listing the duplicates found.
Source
Thrown at src/smolagents/agents.py:411
self.tools = {tool.name: tool for tool in tools}
if add_base_tools:
self.tools.update(
{
name: cls()
for name, cls in TOOL_MAPPING.items()
if name != "python_interpreter" or self.__class__.__name__ == "ToolCallingAgent"
}
)
self.tools.setdefault("final_answer", FinalAnswerTool())
def _validate_tools_and_managed_agents(self, tools, managed_agents):
tool_and_managed_agent_names = [tool.name for tool in tools]
if managed_agents is not None:
tool_and_managed_agent_names += [agent.name for agent in managed_agents]
if self.name:
tool_and_managed_agent_names.append(self.name)
if len(tool_and_managed_agent_names) != len(set(tool_and_managed_agent_names)):
raise ValueError(
"Each tool or managed_agent should have a unique name! You passed these duplicate names: "
f"{[name for name in tool_and_managed_agent_names if tool_and_managed_agent_names.count(name) > 1]}"
)
def _setup_step_callbacks(self, step_callbacks):
# Initialize step callbacks registry
self.step_callbacks = CallbackRegistry()
if step_callbacks:
# Register callbacks list only for ActionStep for backward compatibility
if isinstance(step_callbacks, list):
for callback in step_callbacks:
self.step_callbacks.register(ActionStep, callback)
# Register callbacks dict for specific step classes
elif isinstance(step_callbacks, dict):
for step_cls, callbacks in step_callbacks.items():
if not isinstance(callbacks, list):
callbacks = [callbacks]
for callback in callbacks:View on GitHub (pinned to 30bb116109)
Solutions
- Give each tool/agent a distinct .name (subclass or set instance attribute before passing)
- Remove duplicated tools from the list; if using ToolCollection, don't also pass the same tools individually
- Rename the managed agent or the parent agent if they collide
Example fix
# before search1 = DuckDuckGoSearchTool() search2 = DuckDuckGoSearchTool() # both default to name='web_search' agent = CodeAgent(tools=[search1, search2], llm_engine=llm) # after search2 = DuckDuckGoSearchTool(name="web_search_backup") agent = CodeAgent(tools=[search1, search2], llm_engine=llm)
Defensive patterns
Strategy: validation
Validate before calling
names = [t.name for t in tools] + [a.name for a in managed_agents or []] + [agent_name]
assert len(names) == len(set(names)), f"duplicates: {[n for n in set(names) if names.count(n) > 1]}"
agent = CodeAgent(tools=tools, managed_agents=managed_agents, ...) Prevention
- Name every tool instance explicitly instead of relying on class defaults
- After building a ToolCollection, check for overlap with any individually passed tools
When it happens
Trigger: Passing tools=[t1, t2] where t1.name == t2.name; adding a managed agent whose name matches a tool name; a managed agent sharing the parent agent's self.name.
Common situations: Instantiating two tools of the same class without overriding .name (e.g. two DuckDuckGoSearchTool() instances); wrapping the same tool in ToolCollection and also passing it directly; giving a managed agent the same name as the orchestrating agent.
Related errors
- Cannot specify both 'messages' and 'steps' parameters. Use '
- Agent name '{name}' must be a valid Python identifier and no
- step_callbacks must be a list or a dict
- Tool {tool_name} is not recognized either as a default tool
- Error during jinja template rendering: {type(e).__name__}: {
AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28).
Data as JSON: /api/errors/088fb6701e087343.
Report an issue: GitHub.