Skip to content

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.

studio: align tool-call nudge defaults across loops (#9126)

Kenshia805c1d1a054
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py
index bc9d834ce58..6d4caa4b2f6 100644
--- a/studio/backend/core/inference/llama_cpp.py
+++ b/studio/backend/core/inference/llama_cpp.py
@@ -351,6 +351,7 @@ from core.inference.tool_call_parser import (
is_short_intent_without_action as _is_short_intent_without_action,
reprompt_to_act_message as _reprompt_to_act_message,
)
+from core.inference.passthrough_healing import nudge_enabled as _nudge_enabled
from core.inference.tool_loop_controller import (
ToolLoopController,
append_deferred_nudges,
@@ -25078,10 +25079,10 @@ class LlamaCppBackend:
_reprompt_used, _reprompt_cap = _post_tool_reprompts, 1
else:
_reprompt_used, _reprompt_cap = _reprompt_count, _MAX_REPROMPTS
- # None keeps the default-on re-prompt; False disables it.
+ # None follows the shared process default; explicit values win.
if (
auto_heal_tool_calls
- and (nudge_tool_calls is None or nudge_tool_calls)
+ and _nudge_enabled(nudge_tool_calls)
and active_tools
and not _render_html_already_done_intent
and _reprompt_used < _reprompt_cap
diff --git a/studio/backend/core/inference/openai_codex_tool_loop.py b/studio/backend/core/inference/openai_codex_tool_loop.py
index e247f546efb..6d19d45538e 100644
--- a/studio/backend/core/inference/openai_codex_tool_loop.py
+++ b/studio/backend/core/inference/openai_codex_tool_loop.py
@@ -47,6 +47,7 @@ class CodexToolPolicy:
confirm_calls: bool
bypass_permissions: bool
rag_scope: dict[str, Any] | None
+ nudge_tool_calls: bool | None = None
class CodexTransport:
@@ -117,6 +118,7 @@ def stream_codex_with_studio_tools(
bypass_permissions = policy.bypass_permissions,
rag_scope = policy.rag_scope,
auto_heal = False,
+ nudge_tool_calls = policy.nudge_tool_calls,
),
cancel_event = cancel_event,
)
diff --git a/studio/backend/core/inference/safetensors_agentic.py b/studio/backend/core/inference/safetensors_agentic.py
index 8cd93e138af..8eb31e1afa4 100644
--- a/studio/backend/core/inference/safetensors_agentic.py
+++ b/studio/backend/core/inference/safetensors_agentic.py
@@ -63,6 +63,7 @@ from core.inference.chat_template_helpers import (
append_assistant_turn,
trailing_assistant_text,
)
+from core.inference.passthrough_healing import nudge_enabled
from core.inference.tool_stream_exec import stream_tool_execution
from state.tool_approvals import (
TOOL_REJECTED_MESSAGE,
@@ -1022,16 +1023,15 @@ def run_safetensors_tool_loop(
)
if not safety_tc:
# Re-prompt once on plan-without-action, before any tool runs
- # (GGUF loop parity). The retry is gated on nudge_tool_calls so
- # Unsloth callers (which send True) always nudge, while API callers
- # who omit the flag keep today's no-reprompt behavior (opt-in).
+ # (GGUF loop parity). Omitted flags follow the shared process
+ # default, while explicit request values win.
intent_text = _reprompt_intent_text(
content_accum,
reasoning_prefilled = reasoning_prefilled,
)
if (
auto_heal_tool_calls
- and nudge_tool_calls
+ and nudge_enabled(nudge_tool_calls)
and active_tools
and reprompt_count < MAX_ACT_REPROMPTS
and not rag_autoinjected
diff --git a/studio/backend/core/inference/studio_tool_loop.py b/studio/backend/core/inference/studio_tool_loop.py
index 66524c94881..549d98419b1 100644
--- a/studio/backend/core/inference/studio_tool_loop.py
+++ b/studio/backend/core/inference/studio_tool_loop.py
@@ -55,7 +55,7 @@ from typing import Any, Protocol
from core.inference import tools as tools_module
from core.inference.chat_template_helpers import append_assistant_turn
-from core.inference.passthrough_healing import StreamToolCallHealer, heal_gate
+from core.inference.passthrough_healing import StreamToolCallHealer, heal_gate, nudge_enabled
from core.inference.sse_control_frames import sanitize_provider_sse_line
from core.inference.tool_call_parser import (
MAX_ACT_REPROMPTS,
@@ -347,6 +347,8 @@ class ToolLoopPolicy:
rag_scope: dict[str, Any] | None
# None means "follow the process default"; False disables text-form healing.
auto_heal: bool | None = None
+ # None follows UNSLOTH_TOOL_CALL_NUDGE; explicit booleans win.
+ nudge_tool_calls: bool | None = None
@dataclass
@@ -1043,6 +1045,7 @@ async def stream_with_studio_tools(
visible_answer = "".join(turn.text)
if (
tools_available
+ and nudge_enabled(policy.nudge_tool_calls)
and not controller.force_final_answer
and reprompts < max_reprompts
and is_short_intent_without_action(visible_answer)
diff --git a/studio/backend/models/inference.py b/studio/backend/models/inference.py
index 430fbfa82b6..be57f7d0212 100644
--- a/studio/backend/models/inference.py
+++ b/studio/backend/models/inference.py
@@ -1777,11 +1777,10 @@ class ChatCompletionRequest(BaseModel):
nudge_tool_calls: Optional[bool] = Field(
None,
description = (
- "[x-unsloth] Opt-in, non-streaming client-tool passthrough only: when the "
- "model emitted a tool signal that healing could not repair, retry ONCE with "
- "a short nudge appended (the retry shares the full prompt prefix, so the "
- "server's KV cache is reused). Default off; UNSLOTH_TOOL_CALL_NUDGE=1 flips "
- "the process default."
+ "[x-unsloth] Opt-in tool-call recovery: when a model stalls with a short "
+ "plan instead of calling an available tool, or passthrough healing cannot "
+ "repair a malformed call, retry with a short nudge. Default off; "
+ "UNSLOTH_TOOL_CALL_NUDGE=1 flips the process default."
),
)
context_overflow: Optional[Literal["error", "truncate_middle", "truncate_oldest"]] = Field(
@@ -2945,7 +2944,7 @@ class AnthropicMessagesRequest(BaseModel):
)
nudge_tool_calls: Optional[bool] = Field(
None,
- description = "[x-unsloth] Opt-in, non-streaming only: retry once with a nudge when the model emitted a tool signal healing could not repair (mirrors the Chat Completions field).",
+ description = "[x-unsloth] Opt-in tool-call recovery; mirrors the Chat Completions nudge_tool_calls field and defaults off.",
)
model_config = {"extra": "allow"}
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index 7efcdef055a..5f6a53b6c14 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -14236,6 +14236,7 @@ async def _proxy_to_external_provider(
confirm_calls = _permission_mode_confirm(payload),
bypass_permissions = bool(payload.bypass_permissions),
rag_scope = payload.rag_scope,
+ nudge_tool_calls = payload.nudge_tool_calls,
)
if studio_tool_payloads
else None
@@ -14559,6 +14560,7 @@ async def _proxy_to_external_provider(
bypass_permissions = bool(payload.bypass_permissions),
rag_scope = payload.rag_scope,
auto_heal = payload.auto_heal_tool_calls,
+ nudge_tool_calls = payload.nudge_tool_calls,
),
cancel_event = cancel_event,
)
diff --git a/studio/backend/tests/test_external_confirm_gate_and_saved_keys.py b/studio/backend/tests/test_external_confirm_gate_and_saved_keys.py
index f251ea30816..1db52fdf292 100644
--- a/studio/backend/tests/test_external_confirm_gate_and_saved_keys.py
+++ b/studio/backend/tests/test_external_confirm_gate_and_saved_keys.py
@@ -231,12 +231,14 @@ def test_the_external_loop_is_told_which_model_the_usage_belongs_to(monkeypatch)
assert entered["run"].model == "gpt-5.4"
-def test_the_codex_loop_keeps_reporting_its_own_model(monkeypatch):
- """A regression guard, not a new feature.
+def test_the_codex_loop_keeps_its_model_and_nudge_policy(monkeypatch):
+ """The Codex adapter must preserve shared-loop policy and accounting inputs.
Before the shared loop, the Codex path relayed the provider's usage chunks
untouched and they named the Codex model. The shared loop replaces them, so
- the model has to be carried across or Codex metadata moves.
+ the model has to be carried across or Codex metadata moves. The request's
+ nudge setting must likewise survive the adapter instead of reverting to the
+ process default.
"""
from core.inference import openai_codex_tool_loop as loop_mod
@@ -270,11 +272,13 @@ def test_the_codex_loop_keeps_reporting_its_own_model(monkeypatch):
confirm_calls = False,
bypass_permissions = False,
rag_scope = None,
+ nudge_tool_calls = False,
)
loop_mod.stream_codex_with_studio_tools(
object(), run = run, policy = policy, cancel_event = threading.Event()
)
assert entered["run"].model == "gpt-5.4-codex"
+ assert entered["policy"].nudge_tool_calls is False
def test_the_usage_chunk_falls_back_only_when_no_model_is_known():
diff --git a/studio/backend/tests/test_external_hosted_tool_passthrough.py b/studio/backend/tests/test_external_hosted_tool_passthrough.py
index ed2faf44df5..366374ebf8f 100644
--- a/studio/backend/tests/test_external_hosted_tool_passthrough.py
+++ b/studio/backend/tests/test_external_hosted_tool_passthrough.py
@@ -308,8 +308,30 @@ def test_b_an_omitted_permission_mode_arms_the_auto_gate(monkeypatch):
assert policy.confirm_calls is True
+ "nudge_tool_calls", [None, False, True], ids = ["omitted", "disabled", "enabled"]
+)
+def test_b_external_tool_loop_receives_requested_nudge_setting(monkeypatch, nudge_tool_calls):
+ """The external Studio loop must receive the request-level nudge policy."""
+ monkeypatch.setattr(
+ "core.inference.tools.get_enabled_mcp_tools",
+ lambda: _noop_mcp(),
+ )
+ inf = _install(monkeypatch, "openai")
+ payload = _payload(
+ enable_tools = True,
+ enabled_tools = ["python"],
+ nudge_tool_calls = nudge_tool_calls,
+ )
+
+ with pytest.raises(LoopEntered) as excinfo:
+ _run(inf, payload)
+
+ assert excinfo.value.args[0].nudge_tool_calls is nudge_tool_calls
+
+
def test_b_the_external_and_codex_paths_derive_the_gate_identically():
- """Both policy constructions must read the same two expressions off the
+ """Both policy constructions must read the same policy expressions off the
payload; a divergence would make one path quietly more permissive."""
tree = ast.parse(_ROUTE_SOURCE.read_text(encoding = "utf-8"))
modes: set[str] = set()
@@ -324,6 +346,19 @@ def test_b_the_external_and_codex_paths_derive_the_gate_identically():
assert modes == {"payload.permission_mode or 'auto'"}
assert confirms == {"_permission_mode_confirm(payload)"}
+ nudge_values = []
+ for node in ast.walk(tree):
+ if not isinstance(node, ast.Call) or not isinstance(node.func, ast.Name):
+ continue
+ if node.func.id not in {"CodexToolPolicy", "ToolLoopPolicy"}:
+ continue
+ nudge_values.extend(
+ ast.unparse(keyword.value)
+ for keyword in node.keywords
+ if keyword.arg == "nudge_tool_calls"
+ )
+ assert nudge_values == ["payload.nudge_tool_calls", "payload.nudge_tool_calls"]
+
@pytest.mark.parametrize(
"name, arguments, high_risk",
diff --git a/studio/backend/tests/test_hosted_result_replay.py b/studio/backend/tests/test_hosted_result_replay.py
index dd58fe535e4..d7e46912f4c 100644
--- a/studio/backend/tests/test_hosted_result_replay.py
+++ b/studio/backend/tests/test_hosted_result_replay.py
@@ -132,7 +132,7 @@ def executed(monkeypatch):
return calls
-def _run(transport):
+def _run(transport, *, nudge_tool_calls: bool | None = None):
async def _collect():
out: list[str] = []
agen = stream_with_studio_tools(
@@ -150,6 +150,7 @@ def _run(transport):
confirm_calls = False,
bypass_permissions = False,
rag_scope = None,
+ nudge_tool_calls = nudge_tool_calls,
),
cancel_event = threading.Event(),
)
@@ -567,7 +568,7 @@ def test_a_stalled_turn_keeps_its_hosted_result(executed):
[_DONE],
]
)
- _run(transport)
+ _run(transport, nudge_tool_calls = True)
assert len(transport.requests) > 1, "the stall reprompt never happened"
assert "gradient checkpointing lands" in json.dumps(transport.requests[1]["messages"])
@@ -618,6 +619,7 @@ def test_a_stalled_continuation_stays_one_assistant_turn(executed):
confirm_calls = False,
bypass_permissions = False,
rag_scope = None,
+ nudge_tool_calls = True,
),
cancel_event = threading.Event(),
)
@@ -975,7 +977,7 @@ def test_a_stalled_turn_keeps_its_thought_signature(executed):
[_DONE],
]
)
- _run(transport)
+ _run(transport, nudge_tool_calls = True)
reprompted = transport.requests[1]["messages"]
stalled = [
m
diff --git a/studio/backend/tests/test_llama_cpp_tool_loop.py b/studio/backend/tests/test_llama_cpp_tool_loop.py
index 5359738791d..47396badb23 100644
--- a/studio/backend/tests/test_llama_cpp_tool_loop.py
+++ b/studio/backend/tests/test_llama_cpp_tool_loop.py
@@ -2141,6 +2141,7 @@ def test_internal_reprompt_attempts_do_not_duplicate_visible_text(monkeypatch):
messages = [{"role": "user", "content": "Make a red square."}],
tools = tools,
max_tool_iterations = 1,
+ nudge_tool_calls = True,
)
)
@@ -2207,6 +2208,7 @@ def test_post_tool_stall_still_nudged_after_a_pre_tool_reprompt(monkeypatch):
messages = [{"role": "user", "content": "Make a red square."}],
tools = tools,
max_tool_iterations = 2,
+ nudge_tool_calls = True,
)
)
@@ -2275,6 +2277,7 @@ def test_post_tool_reprompt_budget_is_one(monkeypatch):
messages = [{"role": "user", "content": "Make a red square."}],
tools = tools,
max_tool_iterations = 2,
+ nudge_tool_calls = True,
)
)
@@ -2340,6 +2343,7 @@ def test_repeat_guard_resets_after_a_tool_runs(monkeypatch):
messages = [{"role": "user", "content": "Make a red square."}],
tools = tools,
max_tool_iterations = 2,
+ nudge_tool_calls = True,
)
)
@@ -2502,6 +2506,7 @@ def test_forced_turn_answer_with_an_intent_lead_in_survives_after_a_tool(monkeyp
messages = [{"role": "user", "content": "What is the capital of Japan?"}],
tools = tools,
max_tool_iterations = 2,
+ nudge_tool_calls = True,
)
)
@@ -2551,6 +2556,7 @@ def test_forced_turn_answer_with_an_intent_lead_in_survives_pre_tool(monkeypatch
messages = [{"role": "user", "content": "What is the capital of Japan?"}],
tools = tools,
max_tool_iterations = 2,
+ nudge_tool_calls = True,
)
)
@@ -2597,6 +2603,7 @@ def test_forced_reprompt_plain_final_answer_is_visible(monkeypatch):
}
],
max_tool_iterations = 1,
+ nudge_tool_calls = True,
)
)
@@ -2902,6 +2909,7 @@ def test_reprompted_tool_call_still_streams_final_answer(monkeypatch):
messages = [{"role": "user", "content": "Make a red square."}],
tools = tools,
max_tool_iterations = 1,
+ nudge_tool_calls = True,
)
)
@@ -2972,6 +2980,7 @@ def test_plan_without_action_nudge_is_announced_on_the_status_channel(monkeypatc
messages = [{"role": "user", "content": "What colour is the square?"}],
tools = [_WEB_SEARCH_TOOL],
max_tool_iterations = 2,
+ nudge_tool_calls = True,
)
)
@@ -2998,6 +3007,7 @@ def test_plan_without_action_nudge_status_clears_when_the_retry_just_answers(mon
messages = [{"role": "user", "content": "What colour is the square?"}],
tools = [_WEB_SEARCH_TOOL],
max_tool_iterations = 2,
+ nudge_tool_calls = True,
)
)
@@ -3081,6 +3091,22 @@ def test_nudge_status_absent_when_nudging_is_disabled(monkeypatch):
assert len(payloads) == 1
+def test_nudge_is_off_when_the_request_flag_is_omitted(monkeypatch):
+ payloads: list[dict] = []
+ backend = _make_backend(monkeypatch, _nudge_then_search_streams(), payloads)
+
+ events = list(
+ backend.generate_chat_completion_with_tools(
+ messages = [{"role": "user", "content": "What colour is the square?"}],
+ tools = [_WEB_SEARCH_TOOL],
+ max_tool_iterations = 2,
+ )
+ )
+
+ assert NUDGE_TOOL_CALLS_STATUS not in _status_texts(events)
+ assert len(payloads) == 1
+
+
def test_confirm_tool_calls_allow_executes_gguf_tool(monkeypatch):
streams = [
_structured_tool_call("python", {"code": "print(1)"}, "call_py"),
@@ -3218,6 +3244,7 @@ def test_rag_autoinject_counts_as_a_prior_tool_execution(monkeypatch):
messages = [{"role": "user", "content": "summarize the docs"}],
tools = [{"type": "function", "function": {"name": "search_knowledge_base"}}],
max_tool_iterations = 2,
+ nudge_tool_calls = True,
rag_scope = {"thread_id": "t1"},
)
)
diff --git a/studio/backend/tests/test_nudge_tool_calls_wiring.py b/studio/backend/tests/test_nudge_tool_calls_wiring.py
index 82a6543aebe..ddb5752262d 100644
--- a/studio/backend/tests/test_nudge_tool_calls_wiring.py
+++ b/studio/backend/tests/test_nudge_tool_calls_wiring.py
@@ -3,18 +3,14 @@
"""Wiring guard for the plan-without-action ``nudge_tool_calls`` policy.
-Decided policy: the re-prompt is ALWAYS ON for the Unsloth inference paths
-(safetensors, GGUF/llama_cpp, MLX) and OPT-IN for the API (/v1 OpenAI-compat +
-Anthropic-compat, controlled by the request's ``nudge_tool_calls``, default off).
+The request flag is explicit at every boundary. ``None`` follows the shared
+process default from ``passthrough_healing.nudge_enabled`` (off unless
+``UNSLOTH_TOOL_CALL_NUDGE=1``), while Studio may opt in by sending ``True``.
Mechanism (verified here without loading a model):
- * every backend tool-loop entry point accepts and forwards ``nudge_tool_calls``
- (safetensors -> ``InferenceBackend``; MLX -> ``InferenceOrchestrator``; both
- call the shared ``run_safetensors_tool_loop``; GGUF -> ``LlamaCppBackend``);
- * the safetensors/MLX loop gates the retry on a truthy flag (new retry ->
- opt-in), while the GGUF loop keeps its pre-existing default-on behaviour
- (``None`` keeps nudging) so an omitted flag never disables GGUF;
+ * the GGUF loop and external Studio 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
@@ -22,10 +18,24 @@ Mechanism (verified here without loading a model):
"""
import inspect
+import pathlib
from core.inference.llama_cpp import LlamaCppBackend
from core.inference.orchestrator import InferenceOrchestrator
+from core.inference.passthrough_healing import nudge_enabled
from core.inference.safetensors_agentic import run_safetensors_tool_loop
+from core.inference.studio_tool_loop import ToolLoopPolicy, stream_with_studio_tools
+
+
+_CHAT_ADAPTER_SOURCE = (
+ pathlib.Path(__file__).resolve().parents[2]
+ / "frontend"
+ / "src"
+ / "features"
+ / "chat"
+ / "api"
+ / "chat-adapter.ts"
+)
try:
# core.inference.inference imports unsloth at module scope, which requires
@@ -69,14 +79,24 @@ def test_delegating_backends_forward_the_flag_to_the_shared_loop():
assert "nudge_tool_calls = nudge_tool_calls" in src, method.__qualname__
-def test_safetensors_loop_is_opt_in_while_gguf_stays_default_on():
- # Safetensors/MLX: the retry is new here, so it requires a truthy flag.
- sf_src = inspect.getsource(run_safetensors_tool_loop)
- assert "and nudge_tool_calls" in sf_src
- # GGUF: pre-existing nudge must not be accidentally disabled -- an omitted
- # (None) flag keeps nudging; only an explicit False turns it off.
+def test_gguf_and_external_loops_use_the_shared_nudge_normalizer():
gguf_src = inspect.getsource(LlamaCppBackend.generate_chat_completion_with_tools)
- assert "nudge_tool_calls is None or nudge_tool_calls" in gguf_src
+ assert "_nudge_enabled(nudge_tool_calls)" in gguf_src
+ external_src = inspect.getsource(stream_with_studio_tools)
+ assert "nudge_enabled(policy.nudge_tool_calls)" in external_src
+ assert "nudge_tool_calls" in ToolLoopPolicy.__dataclass_fields__
+
+
+def test_nudge_normalizer_uses_the_process_default_and_explicit_values(monkeypatch):
+ from core.inference import passthrough_healing
+
+ monkeypatch.setattr(passthrough_healing, "_NUDGE_DEFAULT", False)
+ assert nudge_enabled(None) is False
+ assert nudge_enabled(False) is False
+ assert nudge_enabled(True) is True
+
+ monkeypatch.setattr(passthrough_healing, "_NUDGE_DEFAULT", True)
+ assert nudge_enabled(None) is True
def test_api_request_models_default_the_flag_off():
@@ -97,3 +117,8 @@ def test_studio_routes_forward_the_request_flag():
):
src = inspect.getsource(handler)
assert "nudge_tool_calls = payload.nudge_tool_calls" in src, handler.__name__
+
+
+def test_studio_external_adapter_forwards_the_nudge_flag():
+ src = _CHAT_ADAPTER_SOURCE.read_text(encoding = "utf-8")
+ assert "nudge_tool_calls: runtime.nudgeToolCalls" in src
diff --git a/studio/backend/tests/test_safetensors_tool_loop.py b/studio/backend/tests/test_safetensors_tool_loop.py
index 14a8d89cc5c..99c18814038 100644
--- a/studio/backend/tests/test_safetensors_tool_loop.py
+++ b/studio/backend/tests/test_safetensors_tool_loop.py
@@ -4401,7 +4401,10 @@ class TestPlanWithoutActionReprompt:
assert any("I'll search the web for that." in t for t in texts)
assert not any("SHOULD NOT APPEAR" in t for t in texts)
- def test_explicit_nudge_off_is_not_reprompted(self):
+ def test_explicit_nudge_off_is_not_reprompted(self, monkeypatch):
+ from core.inference import passthrough_healing
+
+ monkeypatch.setattr(passthrough_healing, "_NUDGE_DEFAULT", True)
loop, exec_fn = _make_loop(
turns = [
["I'll search the web for that."],
@@ -4415,9 +4418,10 @@ class TestPlanWithoutActionReprompt:
assert any("I'll search the web for that." in t for t in texts)
assert not any("SHOULD NOT APPEAR" in t for t in texts)
- def test_omitted_nudge_flag_is_not_reprompted(self):
- # The retry is new on this loop: API callers who do not send the flag
- # must keep today's behavior. Unsloth opts in explicitly.
+ def test_omitted_nudge_flag_follows_disabled_process_default(self, monkeypatch):
+ from core.inference import passthrough_healing
+
+ monkeypatch.setattr(passthrough_healing, "_NUDGE_DEFAULT", False)
loop, exec_fn = _make_loop(
turns = [
["I'll search the web for that."],
@@ -4430,6 +4434,21 @@ class TestPlanWithoutActionReprompt:
assert any("I'll search the web for that." in t for t in texts)
assert not any("SHOULD NOT APPEAR" in t for t in texts)
+ def test_omitted_nudge_flag_follows_enabled_process_default(self, monkeypatch):
+ from core.inference import passthrough_healing
+
+ monkeypatch.setattr(passthrough_healing, "_NUDGE_DEFAULT", True)
+ loop, exec_fn = _make_loop(
+ turns = [
+ ["I'll search the web for that."],
+ ["SECOND TURN"],
+ ],
+ )
+ events = _collect_events(loop)
+ assert exec_fn.calls == []
+ texts = [e["text"] for e in events if e["type"] == "content"]
+ assert any("SECOND TURN" in t for t in texts)
+
def test_rag_autoinject_counts_as_executed_tool(self, monkeypatch):
# Autoinject already ran a KB search outside the controller; a short
# post-retrieval intent must not trigger a spurious re-prompt.
diff --git a/studio/backend/tests/test_studio_tool_loop.py b/studio/backend/tests/test_studio_tool_loop.py
index 9af299cb6a1..69ae9bd9fb7 100644
--- a/studio/backend/tests/test_studio_tool_loop.py
+++ b/studio/backend/tests/test_studio_tool_loop.py
@@ -771,7 +771,7 @@ def test_a_stalled_model_is_nudged_to_act(executed):
[_sse({"content": "answer"}), _sse(finish = "stop"), _DONE],
]
)
- _run(transport)
+ _run(transport, nudge_tool_calls = True)
assert [c["name"] for c in executed] == ["web_search"]
# The nudge is a user turn appended after the stall.
@@ -779,6 +779,21 @@ 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):
+ """The external loop must not invent a retry for an omitted opt-in flag."""
+ 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)
+
+ assert executed == []
+ assert len(transport.requests) == 1
+ assert "SHOULD NOT APPEAR" not in _visible_text(lines)
+
+
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.ts
index 2ecdde01639..15af820b605 100644
--- a/studio/frontend/src/features/chat/api/chat-adapter.ts
+++ b/studio/frontend/src/features/chat/api/chat-adapter.ts
@@ -5596,10 +5596,10 @@ export function createOpenAIStreamAdapter(
// emitting structured tool_calls, so the external loop heals
// like the local one. Omitting this left the backend on its
// process default, which is not what the user set in Settings.
- // nudge_tool_calls is deliberately absent: it is the
- // non-streaming client-tool passthrough retry, which this
- // streaming server-side loop does not perform.
auto_heal_tool_calls: runtime.autoHealToolCalls,
+ // Keep the external server-side loop under the same user
+ // setting as the local inference paths.
+ nudge_tool_calls: runtime.nudgeToolCalls,
// This branch runs the tools here, so say so by name:
// enabled_tools ["web_search"] is byte-identical to what an
// older bundle sent meaning hosted search, so without this