Skip to content

fix(agent): preserve MiMo thinking blocks on Anthropic replay - #26802

Open
CallMe1101 wants to merge 1 commit into
NousResearch:mainfrom
CallMe1101:fix/mimo-thinking-blocks-clean
Open

fix(agent): preserve MiMo thinking blocks on Anthropic replay#26802
CallMe1101 wants to merge 1 commit into
NousResearch:mainfrom
CallMe1101:fix/mimo-thinking-blocks-clean

Conversation

@CallMe1101

Copy link
Copy Markdown

Problem

Xiaomi MiMo's Anthropic-compatible endpoint recently tightened thinking-mode validation. When thinking mode is enabled, prior assistant turns containing tool_use must replay their full reasoning_content on subsequent requests. If omitted, MiMo returns HTTP 400:

The reasoning_content in the thinking mode must be passed back to the API.

Generic third-party Anthropic handling strips all thinking blocks, breaking MiMo replays — same root cause as Kimi (#13848) and DeepSeek (#16748).

Solution

MiMo follows the same replay contract as Kimi and DeepSeek: strip Anthropic-signed thinking blocks (third-party endpoints cannot validate signatures) but preserve unsigned thinking blocks synthesized from reasoning_content.

Changes to agent/anthropic_adapter.py

  • Add _XIAOMI_MIMO_MODEL_PREFIXES — model name prefixes (mimo-*, mimo_*, xiaomi-mimo-*, xiaomi_mimo_*)
  • Add _model_name_is_xiaomi_mimo() — detects MiMo model names (strips vendor prefix, handles deep-namespaced forms)
  • Add _is_xiaomi_mimo_anthropic_endpoint() — matches by model name or base_url host (xiaomimimo.com, mimo.com)
  • Update _preserve_unsigned_thinking to include MiMo alongside Kimi/DeepSeek
  • Inject single-space placeholder thinking block when an assistant tool-use turn has no thinking block at all — handles migrated/cross-provider history (reproduces akaDRJ's live failure from fix: pad Xiaomi MiMo reasoning_content replay #24726)

Tests

  • tests/agent/test_xiaomi_mimo_anthropic_thinking.py (277 lines): unsigned thinking preservation, signed block stripping, generic third-party behavior, placeholder injection, lookalike model names, deep-namespaced models
  • tests/run_agent/test_xiaomi_mimo_reasoning_replay.py (138 lines): reasoning padding for MiMo providers, missing/empty reasoning_content handling, lookalike detection

Notes

Testing

All 38 tests pass:

python -m pytest tests/agent/test_xiaomi_mimo_anthropic_thinking.py tests/run_agent/test_xiaomi_mimo_reasoning_replay.py -v
# 38 passed

Related

…search#24465)

Xiaomi MiMo's Anthropic-compatible endpoint requires reasoning_content
to round-trip on replayed assistant tool-call messages when thinking mode
is enabled. Without this, multi-turn conversations fail with HTTP 400:

    The reasoning_content in the thinking mode must be passed back to the API.

This applies the same strip-signed / keep-unsigned policy already used
for Kimi (/coding) and DeepSeek (/anthropic) to MiMo endpoints.

Changes to agent/anthropic_adapter.py:
- Add _XIAOMI_MIMO_MODEL_PREFIXES, _model_name_is_xiaomi_mimo(),
  _is_xiaomi_mimo_anthropic_endpoint() for model/URL detection
- Add MiMo to _preserve_unsigned_thinking condition
- Inject single-space placeholder thinking block for assistant tool-use
  turns that lack any thinking/reasoning data (reproduces NousResearch#24726)

Tests:
- tests/agent/test_xiaomi_mimo_anthropic_thinking.py (277 lines)
- tests/run_agent/test_xiaomi_mimo_reasoning_replay.py (138 lines)

Refs: NousResearch#13848 (Kimi), NousResearch#16748 (DeepSeek), NousResearch#24465, NousResearch#24726, NousResearch#26775
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/xiaomi Xiaomi MiLM labels May 16, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #24465 (earliest open PR for Xiaomi MiMo reasoning_content echo-back, 26 tests). This is the 12th+ competing PR for the same feature. See also #24784 (which adds gateway retry prevention as net-new scope).

Related: #24603, #24887, #25379, #24893 (closed), #26775 (closed, same author).

teknium1 added a commit that referenced this pull request Jun 15, 2026
Salvages the Xiaomi MiMo thinking/replay fixes from #27886/#25379/#26802/#27363 into one provider cluster, with MiMo reasoning replay enabled for native Xiaomi endpoints plus Nous/OpenRouter Xiaomi slugs.

Co-authored-by: EloquentBrush0x <283442588+EloquentBrush0x@users.noreply.github.com>

Co-authored-by: Peterson <pppan2003@gmail.com>

Co-authored-by: Zhao Zhuoran <zhao.zr11@protonmail.com>

Co-authored-by: zccyman <zccyman@users.noreply.github.com>

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracing the replay failure and covering signed versus unsigned thinking blocks. The current main path still lacks Xiaomi-specific unsigned-thinking preservation at agent/anthropic_adapter.py:2276-2279, so the underlying issue remains relevant.

Problems

  • agent/anthropic_adapter.py:509-513 makes a MiMo model slug sufficient to select Xiaomi Anthropic replay behavior. The added tests deliberately accept https://llm.example.com/anthropic for xiaomi-mimo-* and xiaomi/mimo-* models (tests/agent/test_xiaomi_mimo_anthropic_thinking.py:31-32). A model name does not establish that an arbitrary proxy accepts Xiaomi's unsigned-thinking contract.

Suggested changes

  • Scope detection to Xiaomi's xiaomimimo.com host and an /anthropic route; add negative cases for OpenAI-compatible Xiaomi URLs and arbitrary proxy/aggregator slugs. Commit 06d94943d671ad85119761d8657a7daa07eaea0a contains that narrower salvage direction, but is not on current main.

Automated hermes-sweeper review.


See hermes-agent#24465, #24726.
"""
if _model_name_is_xiaomi_mimo(model):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A MiMo-named model alone does not prove that an arbitrary Anthropic-compatible proxy implements Xiaomi's replay contract. Please gate this on Xiaomi's host plus the /anthropic route; the current tests at tests/agent/test_xiaomi_mimo_anthropic_thinking.py:31-32 lock in the overbroad proxy behavior.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/xiaomi Xiaomi MiLM sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants