Skip to content

[Bug]: Chinese reasoning tags ( 思考 / 反思 / 推理 / 推敲) from MiniMax-M3 leak to user output in streaming + final response #43827

Closed

Description

@pdscomp

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 a8f404b29 on main)
  • Provider: minimax-tokenplan (custom provider, https://api.minimax.io/v1, api_mode: chat_completions, API key from MINIMAX_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

  1. Configure a custom minimax-tokenplan provider pointed at https://api.minimax.io/v1 with MiniMax-M3 registered (see config above).
  2. Start the gateway and chat with the model via Telegram, or run hermes chat -m MiniMax-M3 --provider minimax-tokenplan interactively.
  3. Send any prompt that triggers a reasoning response (basically any non-trivial question — M3 reasons by default).
  4. Watch the streaming response.
  5. 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:

  1. 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
  2. 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

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_blocks runs 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 through strip_think_blocks until later).
  • The Chinese tag set is specific to MiniMax M3 in my testing; M2.7 continues to use only the English <think> family.

Activity

  1. added
    type/bugSomething isn't working
    comp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint
    comp/gatewayGateway runner, session dispatch, delivery
    P2Medium — degraded but workaround exists
    on Jun 10, 2026
  2. liuhao1024 commented on Jun 10, 2026

    @liuhao1024

    This is fixed by #43836 — adds Chinese reasoning tags (思考, 反思, 推理, 推敲, etc.) to the think-block filter regex in agent/llm_stream.py.

  3. added
    area/i18nLocalization, locales, translations
    area/streamingStreaming responses: gateway delivery, provider wire
    on Jul 19, 2026
  4. dklangst-sys commented on Aug 19, 2026

    @dklangst-sys

    Reproduction on Hermes Agent v0.20.2 — MiniMax-M3 reasoning not captured in desktop reasoning pane

    Environment

    • Hermes Agent v0.20.2 (df4b651, 2026-08-16)
    • Profile: tech-officer (Mac Studio, macOS 26.5.2)
    • Provider: minimax (api_key, https://api.minimax.io/v1) — first-class providers: entry, not a custom alias
    • Model: MiniMax-M3 via Plus Token Plan subscription
    • Sym: same root cause as the original report, different provider path

    Setup (verified working — model is selectable, dropdown populates from discover_models: true, completions succeed)

    # config.yaml
    providers:
      minimax:
        name: MiniMax (Plus subscription)
        base_url: https://api.minimax.io/v1
        api_key: ${MINIMAX_API_KEY}
        discover_models: true
    # .env
    MINIMAX_API_KEY=sk-cp-…    # Plus Token Plan subscription key
    MINIMAX_BASE_URL=https://api.minimax.io/v1

    Symptom (observed today, 2026-08-18)

    When the desktop model picker is set to MiniMax (Plus subscription) / MiniMax-M3, with display.show_reasoning: true and 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

    // POST https://api.minimax.io/v1/chat/completions
    //   { "model": "MiniMax-M3", "max_tokens": 200,
    //     "messages": [{"role":"user","content":"What is 17 * 24? Think step by step."}] }
    // Authorization: Bearer <sk-cp-…>
    
    {
      "choices": [{
        "finish_reason": "length",
        "message": {
          "role": "assistant",
          "content": "<think>The user is asking for a simple multiplication: 17 × 24…\n…408\n\nLet \u200b"
        }
      }],
      "usage": {"total_tokens": 389, "prompt_tokens": 189, "completion_tokens": 200,
                "prompt_tokens_details": {"cached_tokens": 128}}
    }
    • message contains exactly two keys: content and role. No reasoning_content key.
    • The reasoning is embedded as a literal <think>… block at the start of content.
    • Same shape with reasoning_effort: "high" (only difference: finish_reason: "stop" because max_tokens wasn't hit). Reasoning still inline in content.
    • usage has no completion_tokens_details.reasoning_tokens field. 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_content field on the OpenAI-format response stream. MiniMax-M3 does not emit that field — its reasoning is in content wrapped 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 structured reasoning_content channel for this provider path.

    The strip_think_blocks function in agent/agent_runtime_helpers.py does remove the tags from content for the English set, but:

    1. The desktop reasoning pane needs the reasoning available as a structured field, not just stripped from the visible text.
    2. Per [Bug]: Chinese reasoning tags ( 思考 / 反思 / 推理 / 推敲) from MiniMax-M3 leak to user output in streaming + final response #43827, the Chinese-tag family is not in the filter at all — so on M3 generations that emit those, the inline reasoning leaks through to the user entirely.

    Related state

    Suggested fix (for whoever picks this up)

    Two complementary changes:

    1. Extract inline-tag reasoning into reasoning_content at the stream-consumer layer so the desktop reasoning pane can render it. The cleanest place is probably gateway/stream_consumer.py or the OpenAI-format adapter — detect the first <think> / Chinese-tag open in the accumulated stream, accumulate tokens until the matching close, emit them as a reasoning_content field on the assistant message, then emit the post-close text as content. This is provider-agnostic and would also benefit GLM, Kimi, DeepSeek, and any other inline-thinking model.

    2. 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 content even 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_tokens field 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

  5. dklangst-sys commented on Aug 19, 2026

    @dklangst-sys

    Reporting in to note that this bug is reproducible on v0.20.2 (current release) and on current origin/main as 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existsarea/i18nLocalization, locales, translationsarea/streamingStreaming responses: gateway delivery, provider wirecomp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpointcomp/gatewayGateway runner, session dispatch, deliveryprovider/minimaxMiniMax (Anthropic transport)type/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions