{"record":{"id":"4ea58959a8846310","repo":"huggingface/smolagents","slug":"error-executing-tool-tool-name-with-arguments-4ea589","errorCode":null,"errorMessage":"Error executing tool '{tool_name}' with arguments {str(arguments)}: {type(e).__name__}: {e}\nPlease try again or use another tool","messagePattern":"Error executing tool '(.+?)' with arguments (.+?): (.+?): (.+?)\nPlease try again or use another tool","errorType":"exception","errorClass":"AgentToolExecutionError","httpStatus":null,"severity":"error","filePath":"src/smolagents/agents.py","lineNumber":1502,"sourceCode":"            # Call tool with appropriate arguments\n            if isinstance(arguments, dict):\n                return tool(**arguments) if is_managed_agent else tool(**arguments, sanitize_inputs_outputs=True)\n            else:\n                return tool(arguments) if is_managed_agent else tool(arguments, sanitize_inputs_outputs=True)\n\n        except Exception as e:\n            # Handle execution errors\n            if is_managed_agent:\n                error_msg = (\n                    f\"Error executing request to team member '{tool_name}' with arguments {str(arguments)}: {e}\\n\"\n                    \"Please try again or request to another team member\"\n                )\n            else:\n                error_msg = (\n                    f\"Error executing tool '{tool_name}' with arguments {str(arguments)}: {type(e).__name__}: {e}\\n\"\n                    \"Please try again or use another tool\"\n                )\n            raise AgentToolExecutionError(error_msg, self.logger) from e\n\n\nclass CodeAgent(MultiStepAgent):\n    \"\"\"\n    In this agent, the tool calls will be formulated by the LLM in code format, then parsed and executed.\n\n    Args:\n        tools (`list[Tool]`): [`Tool`]s that the agent can use.\n        model (`Model`): Model that will generate the agent's actions.\n        prompt_templates ([`~agents.PromptTemplates`], *optional*): Prompt templates.\n        additional_authorized_imports (`list[str]`, *optional*): Additional authorized imports for the agent.\n        planning_interval (`int`, *optional*): Interval at which the agent will run a planning step.\n        executor ([`PythonExecutor`], *optional*): Custom Python code executor. If not provided, a default executor will be created based on `executor_type`.\n        executor_type (`Literal[\"local\", \"blaxel\", \"e2b\", \"modal\", \"docker\"]`, default `\"local\"`): Type of code executor.\n        executor_kwargs (`dict`, *optional*): Additional arguments to pass to initialize the executor.\n        max_print_outputs_length (`int`, *optional*): Maximum length of the print outputs.\n        stream_outputs (`bool`, *optional*, default `False`): Whether to stream outputs during execution.\n        use_structured_outputs_internally (`bool`, default `False`): Whether to use structured generation at each action step: improves performance for many models.","sourceCodeStart":1484,"sourceCodeEnd":1520,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/agents.py#L1484-L1520","documentation":"The general tool-failure path in execute_tool_call: when actually invoking the tool raises, the exception is wrapped in AgentToolExecutionError with a 'Please try again or use another tool' hint. smolagents appends this observation to the agent's memory so the model can retry with corrected arguments or a different tool.","triggerScenarios":"A tool's body raises at runtime — HTTP errors in a web_search wrapper, KeyError from unexpected arguments, file-not-found in a filesystem tool — during process_single_tool_call within agent.run.","commonSituations":"Third-party API tools hitting rate limits or auth errors; tools with unhandled edge cases; transient network failures while the agent is mid-run.","solutions":["Identify the underlying exception from the message (type and text) and fix the tool's own error handling.","Make the tool return a descriptive error string instead of raising, so the agent can adapt.","For transient failures (network, rate limits), retry agent.run or add internal retries/backoff in the tool."],"exampleFix":"# before\n@tool\ndef fetch_url(url: str) -> str:\n    return requests.get(url).text  # raises on non-200\n\n# after\n@tool\ndef fetch_url(url: str) -> str:\n    resp = requests.get(url, timeout=10)\n    if not resp.ok:\n        return f\"Error fetching {url}: HTTP {resp.status_code}\"\n    return resp.text","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"from smolagents.exceptions import AgentToolExecutionError\n\ntry:\n    result = agent.run(task)\nexcept AgentToolExecutionError:\n    # observation with 'Please try again or use another tool' is in agent memory;\n    # continue/retry the run so the model picks a different strategy\n    result = agent.run(task)","preventionTips":["Design tools to return error strings instead of raising.","Add timeouts and retries inside tools that call external APIs.","Handle expected edge cases (missing files, empty results) in tool code."],"tags":["smolagents","tool-execution","runtime-error","wrapper-exception"],"backgroundTag":"tool-execution-failed","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}