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: expose tool settings for external models (#13251)

Hal9999ce69bf95cdec
diff --git a/studio/frontend/src/features/chat/chat-settings-sheet.tsx b/studio/frontend/src/features/chat/chat-settings-sheet.tsx
index 48840e7e355..3898f15c60c 100644
--- a/studio/frontend/src/features/chat/chat-settings-sheet.tsx
+++ b/studio/frontend/src/features/chat/chat-settings-sheet.tsx
@@ -86,6 +86,7 @@ import {
parseExternalModelId,
promptCacheTtlAppliesToModel,
promptCachingAppliesToModel,
+ providerModelSupportsStudioTools,
} from "./external-providers";
import {
BUILTIN_PRESETS,
@@ -825,6 +826,15 @@ export function ChatSettingsPanel({
const externalSelection = currentCheckpoint
? parseExternalModelId(currentCheckpoint)
: null;
+ // Budget, duration and dedupe are knobs of Unsloth's own tool loop, which external turns run
+ // only when the provider supports Unsloth tools (`=== true`, the same test the request uses).
+ const showStudioToolLoopControls =
+ !isExternalModel ||
+ providerModelSupportsStudioTools(
+ externalProviderType,
+ externalSelection?.modelId,
+ ) === true;
+
const showPromptCacheTtlControl = Boolean(
activeExternalProvider &&
promptCacheTtlAppliesToModel(
@@ -1697,19 +1707,27 @@ export function ChatSettingsPanel({
</div>
</CollapsibleSection>
- {isExternalModel ? null : (
+ {showStudioToolLoopControls ? (
<CollapsibleSection label="Tools">
<div className="flex flex-col gap-5">
- <AutoHealToolCallsToggle />
- <NudgeToolCallsToggle />
+ {isExternalModel ? null : (
+ <>
+ <AutoHealToolCallsToggle />
+ <NudgeToolCallsToggle />
+ </>
+ )}
<DeduplicateToolCallsToggle />
- <ConfirmToolCallsToggle />
- <BypassPermissionsToggle />
+ {isExternalModel ? null : (
+ <>
+ <ConfirmToolCallsToggle />
+ <BypassPermissionsToggle />
+ </>
+ )}
<MaxToolCallsSlider />
<ToolCallTimeoutSlider />
</div>
</CollapsibleSection>
- )}
+ ) : null}
{isExternalModel ? null : (
<CollapsibleSection label="Retrieval">
diff --git a/studio/frontend/tests/external-tool-loop-settings.test.ts b/studio/frontend/tests/external-tool-loop-settings.test.ts
new file mode 100644
index 00000000000..646461d74fa
--- /dev/null
+++ b/studio/frontend/tests/external-tool-loop-settings.test.ts
@@ -0,0 +1,156 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+// The Tools section was hidden for external models while Unsloth's tool loop still applied
+// its 25-call budget to them (#13243). The section is too large to render here, so its JSX is
+// walked with isExternalModel / the capability gate fixed to each side.
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import ts from "typescript";
+
+import { readSrc } from "./helpers/kit.ts";
+
+const SHEET = ts.createSourceFile(
+ "chat-settings-sheet.tsx",
+ readSrc("features/chat/chat-settings-sheet.tsx"),
+ ts.ScriptTarget.Latest,
+ true,
+ ts.ScriptKind.TSX,
+);
+
+type Gates = { isExternalModel: boolean; showStudioToolLoopControls: boolean };
+
+function find<T extends ts.Node>(
+ root: ts.Node,
+ pick: (node: ts.Node) => node is T,
+): T | null {
+ let found: T | null = null;
+ const visit = (node: ts.Node): void => {
+ if (found) return;
+ if (pick(node)) {
+ found = node;
+ return;
+ }
+ ts.forEachChild(node, visit);
+ };
+ visit(root);
+ return found;
+}
+
+function toolsSection(): ts.JsxElement {
+ const section = find(
+ SHEET,
+ (node): node is ts.JsxElement =>
+ ts.isJsxElement(node) &&
+ node.openingElement.tagName.getText() === "CollapsibleSection" &&
+ node.openingElement.attributes.properties.some(
+ (a) =>
+ ts.isJsxAttribute(a) &&
+ a.name.getText() === "label" &&
+ a.initializer?.getText() === '"Tools"',
+ ),
+ );
+ assert.ok(section, "Tools section not found");
+ return section;
+}
+
+function evalGate(expr: ts.Expression, gates: Gates): boolean {
+ const name = expr.getText();
+ if (name in gates) return gates[name as keyof Gates];
+ if (
+ ts.isPrefixUnaryExpression(expr) &&
+ expr.operator === ts.SyntaxKind.ExclamationToken
+ ) {
+ return !evalGate(expr.operand, gates);
+ }
+ throw new Error(`unexpected gate in Tools section: ${name}`);
+}
+
+// Component names rendered under the given gates, following ternaries around and inside the section.
+function rendered(gates: Gates): string[] {
+ const out: string[] = [];
+ const visit = (node: ts.Node): void => {
+ if (ts.isConditionalExpression(node)) {
+ visit(evalGate(node.condition, gates) ? node.whenTrue : node.whenFalse);
+ return;
+ }
+ if (ts.isJsxSelfClosingElement(node)) out.push(node.tagName.getText());
+ ts.forEachChild(node, visit);
+ };
+ let outer: ts.Node = toolsSection();
+ while (
+ outer.parent &&
+ (ts.isParenthesizedExpression(outer.parent) ||
+ ts.isConditionalExpression(outer.parent))
+ ) {
+ outer = outer.parent;
+ }
+ if (ts.isConditionalExpression(outer)) visit(outer);
+ else visit(toolsSection());
+ return out.filter((name) => /Toggle$|Slider$/.test(name));
+}
+
+test("external models with Unsloth tools see the tool loop's budget, duration and dedupe", () => {
+ const external = rendered({
+ isExternalModel: true,
+ showStudioToolLoopControls: true,
+ });
+ for (const control of [
+ "MaxToolCallsSlider",
+ "ToolCallTimeoutSlider",
+ "DeduplicateToolCallsToggle",
+ ]) {
+ assert.ok(external.includes(control), `${control} hidden for external`);
+ }
+ // Nudge is forced off on external turns, so its toggle would do nothing there.
+ assert.ok(!external.includes("NudgeToolCallsToggle"));
+});
+
+test("external providers without Unsloth tools get no Tools section", () => {
+ assert.deepEqual(
+ rendered({ isExternalModel: true, showStudioToolLoopControls: false }),
+ [],
+ );
+});
+
+test("local models keep every tool control", () => {
+ assert.deepEqual(
+ rendered({ isExternalModel: false, showStudioToolLoopControls: true }),
+ [
+ "AutoHealToolCallsToggle",
+ "NudgeToolCallsToggle",
+ "DeduplicateToolCallsToggle",
+ "ConfirmToolCallsToggle",
+ "BypassPermissionsToggle",
+ "MaxToolCallsSlider",
+ "ToolCallTimeoutSlider",
+ ],
+ );
+});
+
+test("the gate matches the external request's own Unsloth-tools test", () => {
+ const sheet = SHEET.getFullText();
+ assert.match(
+ sheet,
+ /showStudioToolLoopControls =\s*!isExternalModel \|\|\s*providerModelSupportsStudioTools\([^)]*\) === true;/,
+ );
+ const adapter = readSrc("features/chat/api/chat-adapter.ts");
+ assert.match(
+ adapter,
+ /externalUsesStudioTools =\s*providerModelSupportsStudioTools\([^)]*\) === true;/,
+ );
+ // Every knob shown for external is one the external tool-loop body sends.
+ const loopBody = adapter.slice(
+ adapter.indexOf("run_tools_locally: true") - 2500,
+ adapter.indexOf("run_tools_locally: true"),
+ );
+ for (const field of [
+ "max_tool_calls_per_message: runtime.maxToolCallsPerMessage",
+ "tool_call_timeout:",
+ "deduplicate_tool_calls: runtime.deduplicateToolCalls",
+ ]) {
+ assert.ok(loopBody.includes(field), `external body lacks ${field}`);
+ }
+});