Skip to content

[Bug] Ollama thinking models: think:false not sent in API request body #50712

@ai-nurmamat

Description

@ai-nurmamat

Bug

When using Ollama models with native thinking support (e.g. qwen3.5:9b), OpenClaw does not send think: false in the Ollama API request even when thinking: "off" is configured. Without think: false, the model puts its response in the thinking field instead of content. OpenClaw drops thinking blocks and users see empty responses.

Version

  • OpenClaw: 2026.3.13
  • Ollama: latest (March 2026)
  • Model: qwen3.5:9b (any thinking-capable model)

Root Cause Analysis

Location: src/agents/ollama-stream.tscreateOllamaStreamFn()

The root cause is in the run() async function where the Ollama API request body is constructed. Around lines 300-310, the ollamaOptions object is built but the think parameter is never included:

const ollamaOptions: Record<string, unknown> = { num_ctx: model.contextWindow ?? 65536 };
if (typeof options?.temperature === "number") {
  ollamaOptions.temperature = options.temperature;
}
if (typeof options?.maxTokens === "number") {
  ollamaOptions.num_predict = options.maxTokens;
}

const body: OllamaChatRequest = {
  model: model.id,
  messages: ollamaMessages,
  stream: true,
  ...(ollamaTools.length > 0 ? { tools: ollamaTools } : {}),
  options: ollamaOptions,
};

The problem: The think parameter is never added to ollamaOptions. Ollama thinking models interpret the absence of think as "use default behavior" — which means think=true (thinking enabled). When the user sets thinking: "off", this preference is never transmitted to the Ollama API.

The fallback in buildAssistantMessage() (which tries response.message.content || response.message.thinking || response.message.reasoning) is insufficient in streaming mode because Ollama sends intermediate chunks with thinking content that may not be properly accumulated.

Reproduction Steps

  1. Configure OpenClaw with Ollama provider using a thinking model (qwen3.5:9b) with thinking: "off"
  2. Send a message that does not trigger tool use
  3. Observe: response is empty
  4. Verify with curl that without think:false, Ollama returns content:"" and thinking:"actual answer"

Proposed Fix

In createOllamaStreamFn(), add think to ollamaOptions based on thinkingLevel:

// Determine if thinking should be disabled
const isThinkingModel = /qwen3|thinking|r1|reasoning/i.test(model.id);
const thinkingLevel = options?.thinkingLevel;
const shouldDisableThinking = !isThinkingModel || thinkingLevel === "off";

if (shouldDisableThinking) {
  ollamaOptions.think = false;
}

Note: The options parameter should include thinkingLevel from agent configuration.

Environment

  • OS: Linux/macOS/Windows
  • OpenClaw: 2026.3.13
  • Ollama: latest
  • Node.js: 22.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions