The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): hide MiniMax-M3 Chinese reasoning tags (#43827)
kshitijk4poor2ab2270b32ea
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex 6e644ce01ca..57fe9614a25 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -8082,13 +8082,12 @@ def extract_content_or_reasoning(response, *, max_reasoning_chars: int | None =raw = str(raw) if raw else ""content = raw.strip()if content:- # Mirrors _strip_think_blocks- cleaned = re.sub(- r"<(?:think|thinking|reasoning|thought|REASONING_SCRATCHPAD)>"- r".*?"- r"</(?:think|thinking|reasoning|thought|REASONING_SCRATCHPAD)>",- "", content, flags=re.DOTALL | re.IGNORECASE,- ).strip()+ # Same precompiled closed-pair patterns as strip_think_blocks.+ from agent.agent_runtime_helpers import _REASONING_BLOCK_PATTERNS+ cleaned = content+ for pattern in _REASONING_BLOCK_PATTERNS:+ cleaned = pattern.sub("", cleaned)+ cleaned = cleaned.strip()if cleaned:return cleaned# Content is empty or reasoning-only — try structured reasoning fieldsdiff --git a/agent/think_scrubber.py b/agent/think_scrubber.pyindex e2dc09103fc..6641685c826 100644--- a/agent/think_scrubber.py+++ b/agent/think_scrubber.py@@ -18,8 +18,12 @@ __all__ = ["StreamingThinkScrubber", "THINK_TAG_NAMES", "THINK_OPEN_TAGS", "THIN# The one list of model reasoning tag names. Every surface that hides reasoning (this scrubber,# the CLI stream filter, the gateway stream filter, the final-response regex stripper) binds to# these; a tag added here is covered everywhere. Consumers match case-insensitively, so the-# literal tags are lowercase.-THINK_TAG_NAMES: Tuple[str, ...] = ("think", "thinking", "reasoning", "thought", "REASONING_SCRATCHPAD")+# literal tags are lowercase. The CJK names cover models (MiniMax-M3) that emit Chinese reasoning+# tags: 思考 (think), 反思 (reflect), 推理 (reason), 推敲 (deliberate).+THINK_TAG_NAMES: Tuple[str, ...] = (+ "think", "thinking", "reasoning", "thought", "REASONING_SCRATCHPAD",+ "思考", "反思", "推理", "推敲",+)THINK_OPEN_TAGS: Tuple[str, ...] = tuple(f"<{name.lower()}>" for name in THINK_TAG_NAMES)THINK_CLOSE_TAGS: Tuple[str, ...] = tuple(f"</{name.lower()}>" for name in THINK_TAG_NAMES)diff --git a/hermes_cli/cli_render.py b/hermes_cli/cli_render.pyindex 0a0bf3b5ac4..b0fb98b312b 100644--- a/hermes_cli/cli_render.py+++ b/hermes_cli/cli_render.py@@ -16,6 +16,7 @@ import textwrapimport threadingimport timefrom contextlib import contextmanager, suppress+from agent.think_scrubber import THINK_TAG_NAMESfrom hermes_cli.banner import format_banner_version_labelfrom rich.console import Consolefrom rich.text import Text as _RichText@@ -28,7 +29,7 @@ def _cli():return cli-_REASONING_TAGS = ("REASONING_SCRATCHPAD", "think", "thinking", "reasoning", "thought")+_REASONING_TAGS = THINK_TAG_NAMES_TOOL_CALL_TAGS = ("tool_call", "tool_calls", "tool_result", "function_call", "function_calls")diff --git a/tests/agent/test_think_scrubber.py b/tests/agent/test_think_scrubber.pyindex 8c1a2d69d97..1b759b28d52 100644--- a/tests/agent/test_think_scrubber.py+++ b/tests/agent/test_think_scrubber.py@@ -182,3 +182,24 @@ class TestRealisticStreaming:s = StreamingThinkScrubber()deltas = ["Hello ", "world ", "how ", "are ", "you?"]assert _drive(s, deltas) == "Hello world how are you?"+++class TestChineseReasoningTags:+ """MiniMax-M3 emits Chinese reasoning tags (#43827); both surfaces must hide them."""++ def test_split_chinese_tag_scrubbed_in_stream(self) -> None:+ s = StreamingThinkScrubber()+ deltas = ["<思", "考>让我想想", "……</思考>", "\n答案是 42"]+ assert _drive(s, deltas) == "\n答案是 42"++ def test_final_response_strip_hides_chinese_tags(self) -> None:+ from agent.agent_runtime_helpers import strip_think_blocks++ out = strip_think_blocks(None, "<反思>内部推理</反思>最终答案\n<推理>未闭合的推理")+ assert "内部推理" not in out and "未闭合" not in out+ assert "最终答案" in out++ def test_cli_replay_strip_hides_chinese_tags(self) -> None:+ from cli import _strip_reasoning_tags++ assert _strip_reasoning_tags("<思考>secret</思考>答案") == "答案"