Skip to content

[Bug]: <thought> tags from Gemma 4 not stripped from response content #6148

@Unayung

Description

@Unayung

Bug Description

When using Gemma 4 models (26B / 31B) via the Gemini API, the model outputs reasoning blocks wrapped in <thought>...</thought> tags. These tags are not stripped from the final response shown to the user, so the raw thinking process leaks into the chat output.

Steps to Reproduce

  1. Configure Gemini API key with a Gemma 4 model (e.g. gemma-4-26b-a4b-it or gemma-4-31b-it)
  2. Send any message that triggers reasoning
  3. Observe <thought>...</thought> blocks appearing in the visible response

Expected Behavior

Reasoning blocks should be stripped (or separated) just like <think>, <thinking>, and <reasoning> tags are.

Actual Behavior

<thought>...</thought> content is rendered inline in the response.

Root Cause

_strip_think_blocks() in run_agent.py handles several tag variants but is missing <thought>:

# run_agent.py ~line 1548
content = re.sub(r'<think>.*?</think>', '', content, flags=re.DOTALL)
content = re.sub(r'<thinking>.*?</thinking>', '', content, flags=re.DOTALL | re.IGNORECASE)
content = re.sub(r'<reasoning>.*?</reasoning>', '', content, flags=re.DOTALL)
content = re.sub(r'<REASONING_SCRATCHPAD>.*?</REASONING_SCRATCHPAD>', '', content, flags=re.DOTALL)
# <thought> is missing here

Proposed Fix

Add one line to _strip_think_blocks():

content = re.sub(r'<thought>.*?</thought>', '', content, flags=re.DOTALL | re.IGNORECASE)

And include thought in the cleanup regex on the last line of the function:

content = re.sub(r'</?(?:think|thinking|reasoning|thought|REASONING_SCRATCHPAD)>\s*', '', content, flags=re.IGNORECASE)

Environment

  • Model: Gemma 4 26B / 31B via Gemini API
  • Tag format used by Gemma 4: <thought>...</thought>

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