From 400fe9b2a19f611d417a5fd85cebca3959cd298b Mon Sep 17 00:00:00 2001 From: Teknium Date: Sun, 12 Apr 2026 12:38:24 -0700 Subject: [PATCH] fix: add stripping to auxiliary_client + tests auxiliary_client.py had its own regex mirroring _strip_think_blocks but was missing the variant. Also adds test coverage for paired and orphaned tags. --- agent/auxiliary_client.py | 4 ++-- tests/run_agent/test_run_agent.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py index 3dcc78a98..6f2f64e9f 100644 --- a/agent/auxiliary_client.py +++ b/agent/auxiliary_client.py @@ -2454,9 +2454,9 @@ def extract_content_or_reasoning(response) -> str: if content: # Strip inline think/reasoning blocks (mirrors _strip_think_blocks) cleaned = re.sub( - r"<(?:think|thinking|reasoning|REASONING_SCRATCHPAD)>" + r"<(?:think|thinking|reasoning|thought|REASONING_SCRATCHPAD)>" r".*?" - r"", + r"", "", content, flags=re.DOTALL | re.IGNORECASE, ).strip() if cleaned: diff --git a/tests/run_agent/test_run_agent.py b/tests/run_agent/test_run_agent.py index d716b59b2..e4ae10f20 100644 --- a/tests/run_agent/test_run_agent.py +++ b/tests/run_agent/test_run_agent.py @@ -302,6 +302,17 @@ class TestStripThinkBlocks: assert "" not in result assert "visible" in result + def test_thought_block_removed(self, agent): + """Gemma 4 uses tags for inline reasoning.""" + result = agent._strip_think_blocks("internal reasoning answer") + assert "internal reasoning" not in result + assert "" not in result + assert "answer" in result + + def test_orphaned_thought_tag(self, agent): + result = agent._strip_think_blocks("orphaned reasoning without close") + assert "" not in result + class TestExtractReasoning: def test_reasoning_field(self, agent):