Skip to content

Bug: Ollama think parameter sent at top-level causes 400 for non-thinking models; should be inside options #80332

@velteyn

Description

@velteyn

Bug type

Behavior bug (incorrect output/state without crash)

Summary

OpenClaw sends think as a top-level parameter in Ollama /api/chat requests, but Ollama only accepts top-level think for models with native thinking support (e.g., Gemma 4, DeepSeek R1). For all other models, the top-level think field causes a 400 {"error":"\"<model>\" does not support thinking"} error.

However, sending think inside the options block (options: {think: "low"}) works correctly for ALL models and provides a reasoning token budget.

Root Cause

Two places in extensions/ollama/src/stream.ts set think at the request top level:

  1. createOllamaThinkingWrapper (line ~236): Sets payloadRecord.think = think — this handles runtime thinkingLevel from agent config
  2. resolveOllamaTopLevelParams (line ~355): Includes think from model.params as a top-level request param

Both should inject into options instead.

Steps to Reproduce

  1. Configure any Ollama model without native thinking support (e.g., mistral, llama3.2, qwen2.5) with thinkingDefault: "low"
  2. Send a request to OpenClaw gateway
  3. Observe 400 error: "<model>" does not support thinking

Direct Ollama API proof

# Top-level think — FAILS for non-thinking models
curl http://localhost:11434/api/chat -d '{
  "model": "llama3.2:1b",
  "messages": [{"role":"user","content":"hi"}],
  "think": "low"
}'
# → 400: "llama3.2:1b does not support thinking"

# think inside options — WORKS for all models
curl http://localhost:11434/api/chat -d '{
  "model": "llama3.2:1b",
  "messages": [{"role":"user","content":"hi"}],
  "options": {"think": "low"}
}'
# → 200, response works normally

Expected Behavior

The think parameter should be sent inside the options block for all Ollama models (or at minimum, top-level think should only be used for models that are heuristically detected as having native thinking support).

Suggested Fix

In extensions/ollama/src/stream.ts:

  1. In createOllamaThinkingWrapper, change:

    payloadRecord.think = think;

    to:

    (payloadRecord.options ??= {}).think = think;
  2. In resolveOllamaTopLevelParams, remove the think handling (or move it to resolveOllamaModelOptions so it goes into options instead).

Related

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