Skip to content

Consolidate reasoning_content echo detection, add Xiaomi MiMo support - #24832

Open
stanleylai wants to merge 1 commit into
NousResearch:mainfrom
stanleylai:fix/consolidate-reasoning-echo-detection
Open

stanleylai wants to merge 1 commit into
NousResearch:mainfrom
stanleylai:fix/consolidate-reasoning-echo-detection

Conversation

@stanleylai

Copy link
Copy Markdown

Bug Description

Xiaomi MiMo (mimo-v2.5-pro) requires reasoning_content to be echoed back on assistant messages in multi-turn conversations. Without it, the API returns HTTP 400:

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

This is the same requirement as DeepSeek V4 and Kimi/Moonshot — Hermes already has fixes for those, but MiMo was not detected by any of the three existing methods (_needs_deepseek_tool_reasoning, _needs_kimi_tool_reasoning, _needs_thinking_reasoning_pad).

Impact: Anyone using MiMo via any provider (opencode-go, OpenRouter, custom endpoints) hits a hard failure on every message after the first turn.

Root Cause

Three separate detection methods existed for the same underlying requirement (echo reasoning_content), each with its own provider-specific logic. MiMo wasn't in any of them, and adding yet another copy would compound the sprawl.

Fix

Consolidate the three detection methods into a single _needs_reasoning_content_echo() backed by a module-level _REASONING_ECHO_PROVIDERS table. Add Xiaomi MiMo entries:

  • _REASONING_ECHO_PROVIDERS table at module level — tuple of (provider, model_substr, host) rows, checked as OR
  • _needs_reasoning_content_echo() — one method replacing three, iterates the table
  • Xiaomi entries: "mimo-" model substring (hyphen avoids false positives on the common ML acronym) + api.xiaomimimo.com host fallback
  • Deleted: _needs_deepseek_tool_reasoning(), _needs_kimi_tool_reasoning(), _needs_thinking_reasoning_pad()
  • Updated all call sites and comments to mention MiMo
  • Net: +107 / −65 lines across 2 files

How to Verify

  1. hermes chat -q "What model are you?" -m mimo-v2.5-pro --provider opencode-go — turn 1 works
  2. hermes chat --resume <session_id> -q "What did I just ask?" — turn 2 works (previously HTTP 400)
  3. grep reasoning_content ~/.hermes/logs/agent.log — no 400 errors after restart
  4. python -m pytest tests/run_agent/test_deepseek_reasoning_content_echo.py -v — 44/44 pass

Test Plan

  • Unit tests pass (44/44)
  • Live verification: multi-turn MiMo conversation works, zero 400s in logs
  • Regression: DeepSeek and Kimi detection still works (covered by existing parametrized tests)
  • Negative test: non-MiMo models (e.g. qwen3.5-plus) correctly return False

Risk Assessment

Low — The consolidated method preserves exact semantics for DeepSeek and Kimi (same match logic, same rows). MiMo detection uses "mimo-" with hyphen to avoid false positives. Kimi detection is now case-insensitive (.lower()s first), which is harmless since providers are already normalized at init.

@stanleylai
stanleylai force-pushed the fix/consolidate-reasoning-echo-detection branch from 6428c67 to 0b0df6c Compare May 13, 2026 05:48
@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/xiaomi Xiaomi MiLM P2 Medium — degraded but workaround exists labels May 13, 2026
@stanleylai
stanleylai force-pushed the fix/consolidate-reasoning-echo-detection branch 2 times, most recently from cfb2803 to ef6efb5 Compare May 15, 2026 05:41
Merge _needs_deepseek_tool_reasoning(), _needs_kimi_tool_reasoning(),
and _needs_thinking_reasoning_pad() into a single
_needs_reasoning_content_echo() backed by a module-level
_REASONING_ECHO_PROVIDERS table.

Problem:
  Xiaomi MiMo (mimo-v2.5-pro) requires reasoning_content echoed back
  on assistant messages in multi-turn conversations, identical to
  DeepSeek V4 and Kimi/Moonshot. Without it, the API returns HTTP 400:
  'The reasoning_content in the thinking mode must be passed back.'
  MiMo wasn't detected by any of the three existing methods, and adding
  a fourth copy would continue the sprawl.

Solution:
  - Replace three provider-specific detection methods with one table-
    driven _needs_reasoning_content_echo(). Each row is
    (provider, model_substr, host) with OR semantics — any non-None
    column matching suffices.
  - Add Xiaomi entries: ('xiaomi', 'mimo-', None) for provider+model
    and (None, None, 'api.xiaomimimo.com') for host fallback.
  - Preserve all existing DeepSeek and Kimi/Moonshot detection paths.
  - Update tests: rename classes, add Xiaomi test cases (provider,
    model substring, host match, non-match negative case).

This makes adding future providers a one-line table entry instead of
a new method. Existing providers unaffected — all 44 unit tests pass.

Co-authored-by: Hermes Agent <hermes@staneryln.com>
@stanleylai
stanleylai force-pushed the fix/consolidate-reasoning-echo-detection branch from ef6efb5 to d0287f7 Compare May 16, 2026 19:33

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the MiMo echo-back work. The reported runtime failure is already covered on current main: run_agent.py:5478-5483 includes MiMo in _needs_thinking_reasoning_pad(), and run_agent.py:5521-5535 implements Xiaomi/model/host detection. The replay path applies that predicate at agent/agent_runtime_helpers.py:2768.

Problems

  • The proposed consolidation removes the current hot-path cache. Main caches the result by provider, model, and base URL at run_agent.py:5474-5483; the submitted table lookup performs row and host checks on each call.

Suggested changes

  • If this refactor is salvaged, retain _thinking_pad_cache and its current key/invalidation semantics while centralizing the underlying matching data.
  • Update against the current helper layout; agent/agent_runtime_helpers.py:2763-2896 now owns the replay forwarding and provider-switch reapplication logic.

Automated hermes-sweeper review.

Comment thread run_agent.py
@@ -10374,71 +10389,34 @@ def _build_assistant_message(self, assistant_message, finish_reason: str) -> dic

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please retain the current _thinking_pad_cache behavior when consolidating this predicate. On main, run_agent.py:5474-5483 caches the provider/model/base-URL result because this check is called repeatedly in the agent loop.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 2026

This branch has not been deployed

No deployments
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-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants