What happened?
Summary
Fix the Qwen thinking format handling in the OpenAI completions provider to correctly toggle thinking mode for Qwen3.5 models.
Problem
When using mlx-community/Qwen3.5-9B-4bit with the pi coding-agent, toggling the thinking/reasoning mode does not work correctly. The previous implementation shared the same code path for Z.ai and Qwen, only sending a top-level enable_thinking parameter:
if ((compat.thinkingFormat === "zai" || compat.thinkingFormat === "qwen") && model.reasoning) {
(params as any).enable_thinking = !!options?.reasoningEffort;
}
Qwen3.5 models require enable_thinking to also be set inside chat_template_kwargs for the thinking toggle to take effect.
Fix
Separate Z.ai and Qwen into distinct code paths. Qwen now sends enable_thinking both at the top level and inside chat_template_kwargs:
if (compat.thinkingFormat === "zai" && model.reasoning) {
// Z.ai uses top-level enable_thinking: boolean
(params as any).enable_thinking = !!options?.reasoningEffort;
} else if (compat.thinkingFormat === "qwen" && model.reasoning) {
// Qwen uses both top-level and chat_template_kwargs for compatibility
const enableThinking = !!options?.reasoningEffort;
(params as any).enable_thinking = enableThinking;
(params as any).chat_template_kwargs = { enable_thinking: enableThinking };
}
Steps to reproduce
- Configure a custom model using
mlx-community/Qwen3.5-9B-4bit with thinkingFormat: "qwen"
- Start the pi coding-agent with this model
- Enable thinking/reasoning mode
- Send a message — thinking works as expected
- Toggle thinking mode off
- Send another message — the model still outputs thinking content, the toggle has no effect
"llama.local": {
"baseUrl": "http://127.0.0.1:8000/v1",
"apiKey": "sk-xxxxxxxxx",
"api": "openai-completions",
"models": [
{
"id": "Qwen3.5-9B-4bit",
"name": "Qwen3.5-9B-4bit",
"reasoning": true,
"input": ["text", "image"],
"compat": {
"supportsDeveloperRole": false,
"thinkingFormat": "qwen"
},
"contextWindow": 65536,
"maxTokens": 32768,
"cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 }
}
]
}
Expected behavior
No response
Version
0.57.1
What happened?
Summary
Fix the Qwen thinking format handling in the OpenAI completions provider to correctly toggle thinking mode for Qwen3.5 models.
Problem
When using
mlx-community/Qwen3.5-9B-4bitwith the pi coding-agent, toggling the thinking/reasoning mode does not work correctly. The previous implementation shared the same code path for Z.ai and Qwen, only sending a top-levelenable_thinkingparameter:Qwen3.5 models require
enable_thinkingto also be set insidechat_template_kwargsfor the thinking toggle to take effect.Fix
Separate Z.ai and Qwen into distinct code paths. Qwen now sends
enable_thinkingboth at the top level and insidechat_template_kwargs:Steps to reproduce
mlx-community/Qwen3.5-9B-4bitwiththinkingFormat: "qwen"Expected behavior
No response
Version
0.57.1