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
fix: do not default-on tool-call nudging on the external loop (#10685)
Apurv Guptaa514d837791e
diff --git a/studio/backend/tests/test_nudge_tool_calls_wiring.py b/studio/backend/tests/test_nudge_tool_calls_wiring.pyindex 61006c2a98d..daa66ac0b98 100644--- a/studio/backend/tests/test_nudge_tool_calls_wiring.py+++ b/studio/backend/tests/test_nudge_tool_calls_wiring.py@@ -12,9 +12,8 @@ Mechanism (verified here without loading a model):* the GGUF loop and external Unsloth loop use the same normalizer;* the external route forwards the request flag into ``ToolLoopPolicy``;* the API request models default the flag to ``None`` (opt-in / off);- * the Unsloth-facing routes forward the request's flag, and the Unsloth frontend- sends ``nudge_tool_calls: true`` -- exercised behaviourally in- ``test_safetensors_tool_loop.py`` and ``test_llama_cpp_tool_loop.py``.+ * the Unsloth-facing routes forward the request's flag;+ * the frontend sends the user setting locally and an explicit ``false`` externally."""import inspect@@ -107,9 +106,6 @@ def test_api_request_models_default_the_flag_off():def test_studio_routes_forward_the_request_flag():- # The Unsloth chat frontend posts to /v1/chat/completions and /v1/messages- # with nudge_tool_calls=true; the route handlers forward the request value- # (external API clients that omit it fall back to the opt-in default).from routes import inference as routes_inferencefor handler in (routes_inference.produce_openai_chat_completions,@@ -119,6 +115,32 @@ def test_studio_routes_forward_the_request_flag():assert "nudge_tool_calls = payload.nudge_tool_calls" in src, handler.__name__-def test_studio_external_adapter_forwards_the_nudge_flag():+def _external_request_body(src: str) -> str:+ """Brace-match the whole literal: carving only the spread let a re-added+ nudge_tool_calls elsewhere in the external body pass the guard."""+ anchor = src.find("run_tools_locally: true")+ assert anchor != -1, "external branch lost its run_tools_locally marker"+ start = src.rfind("return {", 0, anchor)+ assert start != -1+ depth, i = 0, src.index("{", start)+ for end in range(i, len(src)):+ if src[end] == "{":+ depth += 1+ elif src[end] == "}":+ depth -= 1+ if depth == 0:+ return src[start : end + 1]+ raise AssertionError("unbalanced braces in the external request body")+++def test_studio_external_adapter_disables_the_nudge_on_the_external_loop():src = _CHAT_ADAPTER_SOURCE.read_text(encoding = "utf-8")- assert "nudge_tool_calls: runtime.nudgeToolCalls" in src+ external_body = _external_request_body(src)++ # false, not omitted (#9686); chat-adapter.ts carries the why.+ assert "nudge_tool_calls: false" in external_body+ assert "nudge_tool_calls: runtime.nudgeToolCalls" not in external_body++ local_src = src.replace(external_body, "")+ assert "nudge_tool_calls: runtime.nudgeToolCalls" in local_src+ assert "run_tools_locally: true" not in local_srcdiff --git a/studio/backend/tests/test_studio_tool_loop.py b/studio/backend/tests/test_studio_tool_loop.pyindex 2a88e20d4de..3926934fd88 100644--- a/studio/backend/tests/test_studio_tool_loop.py+++ b/studio/backend/tests/test_studio_tool_loop.py@@ -17,6 +17,7 @@ import threadingimport pytest+from core.inference import passthrough_healingfrom core.inference import studio_tool_loop as loop_modfrom core.inference.studio_tool_loop import (ToolLoopPolicy,@@ -765,8 +766,11 @@ def test_a_stalled_model_is_nudged_to_act(executed):assert second[-1]["role"] == "user"-def test_a_stalled_model_is_not_nudged_by_default(executed):+def test_a_stalled_model_is_not_nudged_by_default(executed, monkeypatch):"""The external loop must not invent a retry for an omitted opt-in flag."""+ # Pin it: _NUDGE_DEFAULT is import-time, so otherwise this passes only where+ # UNSLOTH_TOOL_CALL_NUDGE happens to be unset.+ monkeypatch.setattr(passthrough_healing, "_NUDGE_DEFAULT", False)transport = FakeTransport([[_sse({"content": "I'll search for that now."}), _sse(finish = "stop"), _DONE],@@ -780,6 +784,53 @@ def test_a_stalled_model_is_not_nudged_by_default(executed):assert "SHOULD NOT APPEAR" not in _visible_text(lines)+def test_an_explicit_false_beats_a_process_default_of_on(executed, monkeypatch):+ """What chat-adapter.ts sends externally, and it must beat a default of on."""+ monkeypatch.setattr(passthrough_healing, "_NUDGE_DEFAULT", True)+ transport = FakeTransport(+ [+ [_sse({"content": "I'll search for that now."}), _sse(finish = "stop"), _DONE],+ [_sse({"content": "SHOULD NOT APPEAR"}), _sse(finish = "stop"), _DONE],+ ]+ )+ lines = _run(transport, nudge_tool_calls = False)++ assert executed == []+ assert len(transport.requests) == 1+ assert "SHOULD NOT APPEAR" not in _visible_text(lines)+++def test_an_omitted_flag_still_follows_a_process_default_of_on(executed, monkeypatch):+ """The contract the explicit false works around: if omission ever stops+ following the process default, this fails and the false can be reconsidered."""+ monkeypatch.setattr(passthrough_healing, "_NUDGE_DEFAULT", True)+ transport = FakeTransport(+ [+ [_sse({"content": "I'll search for that now."}), _sse(finish = "stop"), _DONE],+ [+ _sse(+ {+ "tool_calls": [+ {+ "index": 0,+ "id": "c1",+ "function": {"name": "web_search", "arguments": "{}"},+ }+ ]+ }+ ),+ _sse(finish = "tool_calls"),+ _DONE,+ ],+ [_sse({"content": "answer"}), _sse(finish = "stop"), _DONE],+ ]+ )+ _run(transport)++ assert [c["name"] for c in executed] == ["web_search"]+ assert len(transport.requests) == 3++def test_a_finished_answer_is_not_nudged(executed):"""A real answer must never be re-prompted into calling a tool."""answer = (diff --git a/studio/frontend/src/features/chat/api/chat-adapter.ts b/studio/frontend/src/features/chat/api/chat-adapter.tsindex 12c9030b675..eedb149eded 100644--- a/studio/frontend/src/features/chat/api/chat-adapter.ts+++ b/studio/frontend/src/features/chat/api/chat-adapter.ts@@ -5863,8 +5863,9 @@ export function createOpenAIStreamAdapter(// Self-hosted models often write a call as text rather than emitting structured tool_calls, so// the external loop heals like the local one; omitting this left the process default.auto_heal_tool_calls: runtime.autoHealToolCalls,- // Keep the external server-side loop under the same user setting as the local paths.- nudge_tool_calls: runtime.nudgeToolCalls,+ // false, not omitted: omission follows UNSLOTH_TOOL_CALL_NUDGE, which the+ // launchers set to 1 when unset, so this loop would keep nudging (#9686, #9125).+ nudge_tool_calls: false,// This branch runs the tools here, so say so by name: enabled_tools ["web_search"] is// byte-identical to an older bundle's hosted search.run_tools_locally: true,