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
- Configure Gemini API key with a Gemma 4 model (e.g.
gemma-4-26b-a4b-it or gemma-4-31b-it)
- Send any message that triggers reasoning
- 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>
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
gemma-4-26b-a4b-itorgemma-4-31b-it)<thought>...</thought>blocks appearing in the visible responseExpected 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()inrun_agent.pyhandles several tag variants but is missing<thought>:Proposed Fix
Add one line to
_strip_think_blocks():And include
thoughtin the cleanup regex on the last line of the function:Environment
<thought>...</thought>