Repository navigation
Description
Bug Description
When using MiniMax-M3 via the minimax-tokenplan provider (or any MiniMax deployment serving the M3 model) the gateway / CLI / agent emit raw Chinese-language reasoning tokens to the user-visible output. Tags such as 思考, 反思, 推理, and 推敲 (which MiniMax M3 uses in place of / alongside the English <think> family) are not stripped, so end users in Telegram/Discord see fragments like:
让我 思考
…right in the middle of the assistant's response. The English-tag filtering path (<think>, <thinking>, <reasoning>, <REASONING_SCRATCHPAD>, <thought>) works correctly — only the Chinese / non-Latin variants are missing from the filter lists.
This is a direct sibling of #17924 (which fixed the English inline-tag leak on the CLI) and an extension of the filter-completeness issue tracked in #27288 (mixed-case tag variants in streaming). The Chinese tag families were simply never added to the three hard-coded tag tuples that all consumer code paths consult.
Environment
- Hermes Agent: v0.16.0 (local checkout at
a8f404b29onmain) - Provider:
minimax-tokenplan(custom provider,https://api.minimax.io/v1,api_mode: chat_completions, API key fromMINIMAX_API_KEY) - Model:
MiniMax-M3(1M context, displayed as "MiniMax M3" — the new M3 reasoning model, not M2.7) - Gateway platform: Telegram (group topic), streaming mode enabled by default
- Config that reproduces:
model: default: minimax-tokenplan/MiniMax-M3 provider: minimax-tokenplan providers: minimax-tokenplan: api: https://api.minimax.io/v1 api_key: ${MINIMAX_API_KEY} api_mode: chat_completions default_model: MiniMax-M3 models: MiniMax-M3: context_length: 1000000
Steps to Reproduce
- Configure a custom
minimax-tokenplanprovider pointed athttps://api.minimax.io/v1withMiniMax-M3registered (see config above). - Start the gateway and chat with the model via Telegram, or run
hermes chat -m MiniMax-M3 --provider minimax-tokenplaninteractively. - Send any prompt that triggers a reasoning response (basically any non-trivial question — M3 reasons by default).
- Watch the streaming response.
- Observe: Chinese reasoning tokens (
思考,反思,推理,推敲, etc.) are streamed verbatim to the user and also land in the final stored message. The English<think>family, by contrast, is filtered correctly.
Expected Behavior
All inline reasoning content — English or Chinese — should be silently filtered before it reaches the user, matching the behavior already in place for the English tag set.
Actual Behavior
The Chinese tag open/close pairs are passed straight through. Example observed in agent.log for a Telegram topic:
2026-06-10 19:12:10,048 INFO run_agent: OpenAI client created
provider=minimax-tokenplan base_url=https://api.minimax.io/v1 model=MiniMax-M3
2026-06-10 19:12:20,378 INFO agent.conversation_loop: API call #1
model=MiniMax-M3 provider=minimax-tokenplan in=64539 out=523 total=65062 latency=10.3s
The 523 output tokens include the raw Chinese tag payloads, which are then sent to Telegram as part of the response (and persisted in the session transcript).
Root Cause
The three filter sites that all consumer code paths consult are hard-coded to the English reasoning-tag family only. None of them include the Chinese variants that MiniMax M3 emits. A comment at the top of each list explicitly says they "must stay in sync" — meaning any fix has to be applied in all three places.
| # | File | Lines | Symbol | What's stored |
|---|---|---|---|---|
| 1 | gateway/stream_consumer.py |
101–108 | GatewayStreamConsumer._OPEN_THINK_TAGS / _CLOSE_THINK_TAGS |
Streaming-time state-machine filter that scrubs interim Telegram / Discord edits |
| 2 | cli.py |
4664–4765 | HermesCLI._stream_delta local _OPEN_TAGS / _CLOSE_TAGS |
CLI streaming-time filter for prompt_toolkit |
| 3 | agent/agent_runtime_helpers.py |
449–510 | strip_think_blocks() regexes (5 re.sub calls for the English tags) |
Final post-processing for stored / sent content |
Current contents of all three lists are identical and incomplete:
_OPEN_THINK_TAGS = (
"<REASONING_SCRATCHPAD>", "<think>", "<reasoning>",
"<THINKING>", "<thinking>", "<thought>",
)
_CLOSE_THINK_TAGS = (
"</REASONING_SCRATCHPAD>", "</think>", "</reasoning>",
"</THINKING>", "</thinking>", "</thought>",
)Note: the strip_think_blocks() function applies its re.sub regexes case-insensitively (good — covers mixed-case English), but the streaming state machines in the other two files do a plain str.find() comparison against the exact tuples above, so even the case-insensitive coverage from strip_think_blocks doesn't extend to them.
Suggested Fix
Extend all three tag tuples to include the Chinese families MiniMax M3 uses. The exact set I have observed in the wild is:
思考(think)反思(reflect)推理(reason / reason out)推敲(deliberate / weigh)
A minimal patch that brings all three sites back in sync:
_OPEN_THINK_TAGS = (
"<REASONING_SCRATCHPAD>", "<think>", "<reasoning>",
"<THINKING>", "<thinking>", "<thought>",
" 思考", " 反思", " 推理", " 推敲",
)
_CLOSE_THINK_TAGS = (
"</REASONING_SCRATCHPAD>", "</think>", "</reasoning>",
"</THINKING>", "</thinking>", "</thought>",
" 思考", " 反思", " 推理", " 推敲",
)For the streaming state machines in stream_consumer.py and cli.py, the comparison is currently a case-sensitive str.find(). To also cover the mixed-case bug from #27288 in the same change, consider normalising the search buffer (.lower() once per delta) while preserving the original text for emission — that way a single change closes both the Chinese-tag gap and the mixed-case tag gap.
For strip_think_blocks() in agent_runtime_helpers.py, add four parallel re.sub calls (case-insensitive, re.DOTALL) so the post-processing layer can never persist the raw tokens either:
content = re.sub(r' 思考.*? 思考', '', content, flags=re.DOTALL | re.IGNORECASE)
content = re.sub(r' 反思.*? 反思', '', content, flags=re.DOTALL | re.IGNORECASE)
content = re.sub(r' 推理.*? 推理', '', content, flags=re.DOTALL | re.IGNORECASE)
content = re.sub(r' 推敲.*? 推敲', '', content, flags=re.DOTALL | re.IGNORECASE)A small regression test in tests/gateway/test_stream_consumer_chinese_think_tags.py and tests/hermes_cli/test_strip_think_blocks.py that feeds a known M3 response (e.g. " 思考\n…\n 思考\nThe answer is 42.") through each filter and asserts the visible output is just "The answer is 42." would prevent this from regressing again.
Workarounds Discovered (no code change)
Until the upstream fix lands, three workarounds work reliably:
- Disable native reasoning for the model (drops the tag emission, but also drops the chain-of-thought — works against the "smart" use case but eliminates the leak):
providers: minimax-tokenplan: extra_body: reasoning: enabled: false
- Route the affected chat/topic to
MiniMax-M2.7(which doesn't emit Chinese think tags, only the English<think>family that the filter already handles). Per-channel override:telegram:-1003865674168:13: model: default: minimax-tokenplan/MiniMax-M2.7
Related Issues
- [Bug] MiniMax reasoning content leaks to CLI output even with reasoning_effort: none #17924 — same family, English tags on the CLI (closed / completed — this fix should be the model)
- Streaming reasoning tag filters miss mixed-case tag variants #27288 — same family, mixed-case English tags in streaming (still open — addressing it in the same PR would be ideal)
- GatewayStreamConsumer._clean_for_display does not filter <think> blocks — reasoning content leaks to chat platforms during streaming #9685 —
GatewayStreamConsumer._clean_for_displaydid not filter<think>blocks (closed — direct ancestor of this bug class) - [Bug]: MiniMax/DeepSeek V4 XML tool calls are rendered as text instead of executed in Web UI/gateway #27834 — MiniMax XML tool calls rendered as text (related: another MiniMax-specific content-shape issue that falls through the same filter gap)
- Bug: reasoning_effort: none silently dropped on Anthropic-protocol third-party providers (MiniMax M3/M2.7, Alibaba, …) #41379 —
reasoning_effort: nonesilently dropped on Anthropic-protocol third-party providers (MiniMax M3/M2.7) — same provider, adjacent symptom
Additional Context
- API calls themselves are healthy: 89–100% cache hit rate, 3–10 s latency, no upstream errors after the alias fix.
- Same M3 response reaches the user correctly on the non-streaming path, because
_strip_think_blocksruns over the assembled message at the end — the leak is only in the interim stream edits the gateway sends during generation, plus the persisted transcript (which does not go throughstrip_think_blocksuntil later). - The Chinese tag set is specific to MiniMax M3 in my testing; M2.7 continues to use only the English
<think>family.
Activity
liuhao1024 commentedon Jun 10, 2026
This is fixed by #43836 — adds Chinese reasoning tags (思考, 反思, 推理, 推敲, etc.) to the think-block filter regex in
agent/llm_stream.py.dklangst-sys commentedon Aug 19, 2026
Reproduction on Hermes Agent v0.20.2 — MiniMax-M3 reasoning not captured in desktop reasoning pane
Environment
tech-officer(Mac Studio, macOS 26.5.2)minimax(api_key,https://api.minimax.io/v1) — first-classproviders:entry, not a custom aliasMiniMax-M3via Plus Token Plan subscriptionSetup (verified working — model is selectable, dropdown populates from
discover_models: true, completions succeed)Symptom (observed today, 2026-08-18)
When the desktop model picker is set to
MiniMax (Plus subscription)/MiniMax-M3, withdisplay.show_reasoning: trueand a high-reasoning prompt, the thinking tokens do happen — they are visible in the response text as<think>…</think>blocks — but they are not extracted into the desktop's reasoning pane. They render as part of the visible assistant reply, prefixed with a literal<think>block that the user has to scroll past. The reasoning-pane toggle on the right edge of the bubble has no effect because the field it watches (message.reasoning_content) is never populated by the API.Direct API check
messagecontains exactly two keys:contentandrole. Noreasoning_contentkey.<think>…block at the start ofcontent.reasoning_effort: "high"(only difference:finish_reason: "stop"because max_tokens wasn't hit). Reasoning still inline incontent.usagehas nocompletion_tokens_details.reasoning_tokensfield. The 200 completion tokens billed include the inline reasoning, not separately accounted for.Root cause (in current v0.20.2 source)
The desktop reasoning pane is driven by a
message.reasoning_contentfield on the OpenAI-format response stream. MiniMax-M3 does not emit that field — its reasoning is incontentwrapped in literal<think>/</think>tags (and, in earlier M3 generations, the Chinese-tag family reported in #43827). Hermes has no automatic extraction of inline-tag reasoning into the structuredreasoning_contentchannel for this provider path.The
strip_think_blocksfunction inagent/agent_runtime_helpers.pydoes remove the tags fromcontentfor the English set, but:Related state
main(I checked:git show origin/main:agent/agent_runtime_helpers.pyandgateway/stream_consumer.pycontain no Chinese-tag references).mergedAt: null). The four-file, +162/-2 patch in that branch is the right shape; the merge just didn't happen.sweeper:implemented-on-main, so that path is healthy.Suggested fix (for whoever picks this up)
Two complementary changes:
Extract inline-tag reasoning into
reasoning_contentat the stream-consumer layer so the desktop reasoning pane can render it. The cleanest place is probablygateway/stream_consumer.pyor the OpenAI-format adapter — detect the first<think>/ Chinese-tag open in the accumulated stream, accumulate tokens until the matching close, emit them as areasoning_contentfield on the assistant message, then emit the post-close text ascontent. This is provider-agnostic and would also benefit GLM, Kimi, DeepSeek, and any other inline-thinking model.Re-land fix(agent): add Chinese reasoning tags to think-block filter for MiniMax M3 #43836's filter additions so the Chinese-tag variants (and any future inline-tag families) are at least stripped from
contenteven if the structured-field extraction isn't in place. Even if step 1 lands first, this is a defense-in-depth backstop that ensures raw reasoning never reaches the user.A third smaller change worth considering in the same PR: surface a
usage.completion_tokens_details.reasoning_tokensfield by counting the stripped tokens, so users can see what their subscription quota is actually spending on thinking vs. visible output. (This is what Anthropic, OpenAI, and DeepSeek do; the MiniMax API doesn't break it out, but Hermes can compute it locally.)Workaround (in use)
Living with the inline
<think>…block in the visible reply. The reasoning is happening; it's just not visually separated. Not a blocker, but a real UX papercut and a real correctness issue when the model switches to the Chinese-tag family (which then leaks raw).🤖 Generated with Hermes Agent
dklangst-sys commentedon Aug 19, 2026
Reporting in to note that this bug is reproducible on v0.20.2 (current release) and on current
origin/mainas of 2026-08-19 — see #89647 for a fresh report that includes the direct API response shape and a structured-field extraction fix proposal. The fix proposed in #43836 still applies cleanly but the closed-without-merge status is the blocker.fix(agent): hide MiniMax-M3 Chinese reasoning tags (#43827)