{"record":{"id":"088fb6701e087343","repo":"huggingface/smolagents","slug":"each-tool-or-managed-agent-should-have-a-unique-na","errorCode":null,"errorMessage":"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]}","messagePattern":"Each tool or managed_agent should have a unique name! You passed these duplicate names: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/smolagents/agents.py","lineNumber":411,"sourceCode":"        self.tools = {tool.name: tool for tool in tools}\n        if add_base_tools:\n            self.tools.update(\n                {\n                    name: cls()\n                    for name, cls in TOOL_MAPPING.items()\n                    if name != \"python_interpreter\" or self.__class__.__name__ == \"ToolCallingAgent\"\n                }\n            )\n        self.tools.setdefault(\"final_answer\", FinalAnswerTool())\n\n    def _validate_tools_and_managed_agents(self, tools, managed_agents):\n        tool_and_managed_agent_names = [tool.name for tool in tools]\n        if managed_agents is not None:\n            tool_and_managed_agent_names += [agent.name for agent in managed_agents]\n        if self.name:\n            tool_and_managed_agent_names.append(self.name)\n        if len(tool_and_managed_agent_names) != len(set(tool_and_managed_agent_names)):\n            raise ValueError(\n                \"Each tool or managed_agent should have a unique name! You passed these duplicate names: \"\n                f\"{[name for name in tool_and_managed_agent_names if tool_and_managed_agent_names.count(name) > 1]}\"\n            )\n\n    def _setup_step_callbacks(self, step_callbacks):\n        # Initialize step callbacks registry\n        self.step_callbacks = CallbackRegistry()\n        if step_callbacks:\n            # Register callbacks list only for ActionStep for backward compatibility\n            if isinstance(step_callbacks, list):\n                for callback in step_callbacks:\n                    self.step_callbacks.register(ActionStep, callback)\n            # Register callbacks dict for specific step classes\n            elif isinstance(step_callbacks, dict):\n                for step_cls, callbacks in step_callbacks.items():\n                    if not isinstance(callbacks, list):\n                        callbacks = [callbacks]\n                    for callback in callbacks:","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/agents.py#L393-L429","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nsearch1 = DuckDuckGoSearchTool()\nsearch2 = DuckDuckGoSearchTool()  # both default to name='web_search'\nagent = CodeAgent(tools=[search1, search2], llm_engine=llm)\n\n# after\nsearch2 = DuckDuckGoSearchTool(name=\"web_search_backup\")\nagent = CodeAgent(tools=[search1, search2], llm_engine=llm)","handlingStrategy":"validation","validationCode":"names = [t.name for t in tools] + [a.name for a in managed_agents or []] + [agent_name]\nassert len(names) == len(set(names)), f\"duplicates: {[n for n in set(names) if names.count(n) > 1]}\"\nagent = CodeAgent(tools=tools, managed_agents=managed_agents, ...)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Name every tool instance explicitly instead of relying on class defaults","After building a ToolCollection, check for overlap with any individually passed tools"],"tags":["smolagents","duplicate-names","tools","valueerror"],"backgroundTag":"duplicate-tool-names","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}