Skip to content

feat(ollama): pass think=false to custom providers when reasoning_effort is none#3197

Closed
Mibayy wants to merge 1 commit into
NousResearch:mainfrom
Mibayy:feat/ollama-think-false-3191
Closed

feat(ollama): pass think=false to custom providers when reasoning_effort is none#3197
Mibayy wants to merge 1 commit into
NousResearch:mainfrom
Mibayy:feat/ollama-think-false-3191

Conversation

@Mibayy

@Mibayy Mibayy commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #3191

When a custom/Ollama provider is used with reasoning_effort: none (or enabled: false), inject "think": false into the request extra_body.

Root Cause

Ollama does not recognise the OpenRouter-style reasoning extra_body field. Thinking-capable models (Qwen3, etc.) therefore generate <think> blocks regardless of the reasoning_effort setting. This produces empty-response errors that corrupt session state.

The existing _supports_reasoning_extra_body() guard correctly blocks the reasoning field from being sent to custom endpoints — but there was no mechanism to affirmatively disable thinking on Ollama's side.

Fix

One block added in _build_api_kwargs(), after the extra_body assembly:

if self.provider == "custom" and self.reasoning_config and isinstance(self.reasoning_config, dict):
    _effort = (self.reasoning_config.get("effort") or "").strip().lower()
    _enabled = self.reasoning_config.get("enabled", True)
    if _effort == "none" or _enabled is False:
        extra_body["think"] = False

This covers both config shapes users might use:

  • reasoning_effort: none{"effort": "none"}
  • reasoning: {enabled: false}{"enabled": false}

Non-custom providers and Ollama with reasoning enabled are unaffected.

Tests

4 new tests in TestBuildApiKwargs:

  • test_ollama_think_false_on_effort_none — effort=none triggers think=false
  • test_ollama_think_false_on_enabled_false — enabled=false triggers think=false
  • test_ollama_no_think_param_when_reasoning_enabled — enabled provider → no think param
  • test_non_custom_provider_unaffected — OpenRouter with effort=none is not affected

Scope

Single file change (run_agent.py), 12 lines added.

…ort is none

When a custom/Ollama provider is used and reasoning_effort is set to 'none'
(or enabled: false), inject 'think': false into the request extra_body.

Ollama does not recognise the OpenRouter-style 'reasoning' extra_body field,
so thinking-capable models (Qwen3, etc.) generate <think> blocks regardless
of the reasoning_effort setting. This produces empty-response errors that
corrupt session state.

The fix adds a provider-specific block in _build_api_kwargs() that sets
think=false in extra_body whenever self.provider == 'custom' and reasoning
is explicitly disabled.

Closes NousResearch#3191
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #10782. Your think=false fix was cherry-picked onto current main with your authorship preserved in git log. Prevents Qwen3 think blocks on Ollama when reasoning is disabled. Closes #3191.

@teknium1 teknium1 closed this Apr 16, 2026
@Cat0x00

Cat0x00 commented Apr 21, 2026

Copy link
Copy Markdown

@teknium1 @Mibayy this is wrong. this solves nothing to the raised issue. Thinking still happens.

"POST /v1/chat/completions" endpoint, that is used by hermes agent for OpenAI compatible endpoints for Ollama interaction does not support "think":False. The correct injection should be "reasoning_effort":"none" which works. I tested it by patching hermes agent (run_agent.py) v0.10.0 like this:

        if self.provider == "custom" and self.reasoning_config and isinstance(self.reasoning_config, dict):
            _effort = (self.reasoning_config.get("effort") or "").strip().lower()
            _enabled = self.reasoning_config.get("enabled", True)
            if _effort == "none" or _enabled is False:
                extra_body["reasoning_effort"] = "none"

Please fix this with a new pull request and proper testing. My ollama version is 0.20.6.

Also ping me if you need more proof.

Some proof with debugging messages (injected by me).

  1. Current approach with "think":False:
image
  1. My local patch with "reasoning_effort":"none"
image
  1. However, there is some other bug along the way then. if i switch between the reasoning modes, then it starts echoing the last reasoning message appended to the output of a non reasoning prompt. I believe this is a separate bug of hermes.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Pass Ollama think: false parameter when reasoning_effort: none is set for custom/Ollama providers

3 participants