Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: run a tool call whose name differs only in case or hyphens (#16007)
Daniel Han99c79ae047aa
diff --git a/studio/backend/core/inference/tool_loop_controller.py b/studio/backend/core/inference/tool_loop_controller.pyindex d0737f96f88..2e6c5ced71f 100644--- a/studio/backend/core/inference/tool_loop_controller.py+++ b/studio/backend/core/inference/tool_loop_controller.py@@ -648,6 +648,32 @@ def _mcp_tool_search_specs(arguments: Any) -> list:return []+def _tool_name_key(name: str) -> str:+ return name.lower().replace("-", "_")+++def _canonical_tool_name(name: str, allowed: Collection[str]) -> "str | None":+ """The one enabled tool a sampled name means when only its case or ``-``/``_`` differ (WEB_SEARCH,+ web-search). Never an execution-class or MCP tool: those run only under their exact name, so a bare+ call cannot reach them by a near spelling. None when no tool, or more than one, matches."""+ # ASCII only: Unicode case folding maps other letters onto ASCII ones (``ſ`` -> ``s``, Kelvin sign -> ``k``).+ if not name or not name.isascii():+ return None+ key = _tool_name_key(name)+ matches = [tool for tool in allowed if _tool_name_key(tool) == key]+ if len(matches) != 1:+ return None+ match = matches[0]+ if match in _tool_healing_exec_names() or match.startswith(MCP_TOOL_PREFIX):+ return None+ return match+++def _tool_healing_exec_names() -> "frozenset[str]":+ from core.tool_healing import EXECUTION_CLASS_TOOL_NAMES # noqa: PLC0415 -- cycle at import time+ return EXECUTION_CLASS_TOOL_NAMES++def coerce_tool_arguments(raw_args: Any,*,@@ -1217,6 +1243,11 @@ class ToolLoopController:function = tool_call.get("function")function = function if isinstance(function, Mapping) else {}tool_name = str(function.get("name") or "").strip()+ name_healed = False+ if self._auto_heal_tool_calls and tool_name not in self._allowed_tool_names:+ canonical = _canonical_tool_name(tool_name, self._allowed_tool_names)+ if canonical is not None:+ tool_name, name_healed = canonical, Trueif (self._mcp_searchand tool_name.startswith(MCP_TOOL_PREFIX)@@ -1236,7 +1267,7 @@ class ToolLoopController:key = canonical_tool_call_key(tool_name, arguments)mcp = mcp_display_parts(tool_name)provenance = tool_event_provenance(- healed = coerced.healed,+ healed = coerced.healed or name_healed,forced = forced,provisional = provisional,mcp_server = mcp[0] if mcp else None,diff --git a/studio/backend/tests/test_tool_call_name_healing.py b/studio/backend/tests/test_tool_call_name_healing.pynew file mode 100644index 00000000000..7b9d2e799bc--- /dev/null+++ b/studio/backend/tests/test_tool_call_name_healing.py@@ -0,0 +1,86 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""A sampled tool name that differs from an enabled tool only in case or ``-``/``_`` runs that tool. Never an+execution-class or MCP tool, never an ambiguous match, and only with auto-heal on."""++from __future__ import annotations++import json++import pytest++from core.inference.tool_loop_controller import ToolLoopController+++def _tool(name: str, prop: str = "query") -> dict:+ return {+ "type": "function",+ "function": {+ "name": name,+ "parameters": {"type": "object", "properties": {prop: {"type": "string"}}},+ },+ }+++TOOLS = [+ _tool("web_search"),+ _tool("search_docs"),+ _tool("python", "code"),+ _tool("mcp__fs__read_file", "path"),+]+++def _decide(+ name: str,+ tools = TOOLS,+ heal: bool = True,+):+ controller = ToolLoopController(tools = tools, auto_heal_tool_calls = heal)+ call = {"id": "c1", "function": {"name": name, "arguments": json.dumps({"query": "x"})}}+ return controller.prepare_call(call)+++ "sampled, canonical",+ [+ ("WEB_SEARCH", "web_search"),+ ("Web_Search", "web_search"),+ ("web-search", "web_search"),+ ("Search-Docs", "search_docs"),+ ],+)+def test_near_spelling_runs_the_enabled_tool(sampled, canonical):+ decision = _decide(sampled)+ assert decision.action == "execute"+ assert decision.tool_name == canonical+ assert decision.provenance.get("healed") is True+ assert decision.as_assistant_tool_call()["function"]["name"] == canonical+++ "sampled", ["PYTHON", "Python", "MCP__FS__READ_FILE", "mcp--fs--read-file"]+)+def test_execution_class_and_mcp_tools_need_their_exact_name(sampled):+ assert _decide(sampled).action == "disabled"+++def test_ambiguous_spelling_is_not_guessed():+ tools = [_tool("web_search"), _tool("Web_Search")]+ assert _decide("WEB_SEARCH", tools).action == "disabled"+++def test_unknown_name_and_heal_off_are_unchanged():+ assert _decide("search_the_web").action == "disabled"+ assert _decide("WEB_SEARCH", heal = False).action == "disabled"+++def test_exact_name_is_untouched():+ decision = _decide("web_search")+ assert decision.action == "execute" and decision.tool_name == "web_search"+ assert not decision.provenance.get("healed")++[email protected]("sampled", ["web_ſearch", "WEB_ſEARCH", "search_docѕ"])+def test_non_ascii_spelling_is_not_folded_onto_a_tool(sampled):+ assert _decide(sampled).action == "disabled"