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: stop unsloth start openclaw cutting every reply at 8,192 tokens (#12573)
Nilay2e24fd5ef1e2
diff --git a/unsloth_cli/commands/start.py b/unsloth_cli/commands/start.pyindex 0b66ec886bf..9ab5035a6e0 100644--- a/unsloth_cli/commands/start.py+++ b/unsloth_cli/commands/start.py@@ -4643,6 +4643,7 @@ def write_openclaw_config(workspace_path: Optional[str] = None,embedding_model: Optional[str] = None,request_body: Optional[dict] = None,+ max_tokens: Optional[int] = None,) -> None:config = _read_json_object(path)if config is None:@@ -4657,7 +4658,12 @@ def write_openclaw_config(provider_model = {"id": model["id"], "name": model["id"]}window = model.get("context_length") or model.get("max_context_length")if window:- provider_model["contextWindow"] = int(window)+ window = int(window)+ provider_model["contextWindow"] = window+ # Unset, OpenClaw caps every reply at 8192 (DEFAULT_MODEL_MAX_TOKENS) whatever the window.+ provider_model["maxTokens"] = _agent_output_limit(window, max_tokens)+ elif max_tokens:+ provider_model["maxTokens"] = max_tokensmodels = _subdict(config, "models")models.setdefault("mode", "merge")_subdict(models, "providers")["unsloth"] = {@@ -5619,6 +5625,7 @@ def openclaw(launch: bool = _LAUNCH_OPTION,gguf_variant: Optional[str] = _GGUF_VARIANT_OPTION,max_seq_length: int = _CONTEXT_OPTION,+ max_tokens: Optional[int] = _MAX_TOKENS_OPTION,load_in_4bit: bool = _LOAD_4BIT_OPTION,tensor_parallel: bool = _TENSOR_PARALLEL_OPTION,gpu_memory_mode: Optional[Literal["auto", "manual"]] = _GPU_MEMORY_MODE_OPTION,@@ -5688,6 +5695,7 @@ def openclaw(workspace_path = "${OPENCLAW_WORKSPACE_DIR}",embedding_model = _studio_embedding_model(base, key),request_body = server_options.request_body(),+ max_tokens = max_tokens,)# Scope both config and state so OpenClaw never touches the user's ~/.openclaw.# Off, else OpenClaw re-imports any provider key it cannot see from a login shell.diff --git a/unsloth_cli/tests/test_start.py b/unsloth_cli/tests/test_start.pyindex 5c27aa11b96..4b7d114e9b1 100644--- a/unsloth_cli/tests/test_start.py+++ b/unsloth_cli/tests/test_start.py@@ -5345,7 +5345,12 @@ def test_write_openclaw_config_fresh(tmp_path):assert provider["apiKey"] == "sk-unsloth-abc"assert provider["api"] == "openai-completions"assert provider["models"] == [- {"id": MODEL["id"], "name": MODEL["id"], "contextWindow": MODEL["context_length"]}+ {+ "id": MODEL["id"],+ "name": MODEL["id"],+ "contextWindow": MODEL["context_length"],+ "maxTokens": 32000,+ }]# The default model must be pinned or OpenClaw has nothing active.assert config["agents"]["defaults"]["model"]["primary"] == f"unsloth/{MODEL['id']}"@@ -5357,6 +5362,25 @@ def test_write_openclaw_config_fresh(tmp_path):assert path.stat().st_mode & 0o777 == 0o600[email protected]("window, expected", [(32_768, 8_192), (131_072, 32_000)])+def test_openclaw_output_limit_follows_the_context(tmp_path, window, expected):+ path = tmp_path / "openclaw.json"+ start.write_openclaw_config(BASE, "sk-unsloth-abc", {**MODEL, "context_length": window}, path)+ model = json.loads(path.read_text())["models"]["providers"]["unsloth"]["models"][0]+ assert model["maxTokens"] == expected++[email protected]("max_tokens, expected", [("40000", 40000), ("200000", 65536)])+def test_connect_openclaw_max_tokens(fake_studio, tmp_path, max_tokens, expected):+ result = CliRunner().invoke(+ start.start_app, ["openclaw", "--no-launch", "--max-tokens", max_tokens]+ )+ assert result.exit_code == 0, result.output+ assert "--max-tokens" not in _launch_command(result.output)+ config = json.loads((tmp_path / "agents" / "openclaw" / "openclaw.json").read_text())+ assert config["models"]["providers"]["unsloth"]["models"][0]["maxTokens"] == expected++def test_write_openclaw_config_clears_per_agent_path_overrides(tmp_path):path = tmp_path / "openclaw.json"path.write_text(