Skip to content

feat(agent): adaptive thinking for Kimi-family Anthropic endpoints - #67228

Closed
chouqin wants to merge 1 commit into
NousResearch:mainfrom
chouqin:feat/kimi-adaptive-thinking-upstream
Closed

feat(agent): adaptive thinking for Kimi-family Anthropic endpoints#67228
chouqin wants to merge 1 commit into
NousResearch:mainfrom
chouqin:feat/kimi-adaptive-thinking-upstream

Conversation

@chouqin

@chouqin chouqin commented Jul 19, 2026

Copy link
Copy Markdown

Kimi's Anthropic-compatible endpoints (api.moonshot.cn/anthropic, api.kimi.com/coding) implement the adaptive thinking contract — they accept thinking.type=adaptive + output_config.effort (all of low, medium, high, xhigh, max verified live) and return thinking blocks, and the replay-validation 400s that originally motivated dropping the parameter (#13848) no longer occur.

_supports_adaptive_thinking() now returns True for Kimi-family models, so they get thinking={type: adaptive, display: summarized} + output_config.effort via ADAPTIVE_EFFORT_MAP instead of nothing, and the blanket drop of the thinking parameter for Kimi-family endpoints is removed. MiniMax and other non-adaptive third parties keep the manual budget_tokens path; Claude behavior is unchanged.

What does this PR do?

Kimi's Anthropic-compatible endpoints (api.moonshot.cn/anthropic, api.kimi.com/coding) implement the adaptive thinking contract. Stop dropping the thinking parameter for the Kimi family and send it in adaptive form:

Related Issue

Fixes #

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • _supports_adaptive_thinking() returns True for Kimi-family models → thinking={type: adaptive, display: summarized} + output_config.effort via ADAPTIVE_EFFORT_MAP (never manual budget_tokens)
  • the blanket drop of the thinking parameter for Kimi-family endpoints ([Bug]: 400 error for kimi-for-coding #13848-era mitigation) is removed
  • MiniMax and other non-adaptive third parties keep the manual budget_tokens path; Claude behavior unchanged

How to Test

Test it against the kimi for coding endpoint:

  • thinking.type="adaptive" + output_config.effort in {low, medium, high, xhigh, max} → all HTTP 200 with thinking blocks; display="summarized" accepted
  • multi-turn tool-call replays in every history shape — signed thinking blocks verbatim, unsigned placeholder blocks, and no thinking blocks at all (the exact [Bug]: 400 error for kimi-for-coding #13848 trigger) — all return HTTP 200; the replay-validation 400s that motivated the original drop no longer occur

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 15.2

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

Kimi's Anthropic-compatible endpoints (api.moonshot.cn/anthropic,
api.kimi.com/coding) implement the adaptive thinking contract — they
accept thinking.type=adaptive + output_config.effort (all of low,
medium, high, xhigh, max verified live) and return thinking blocks, and
the replay-validation 400s that originally motivated dropping the
parameter (NousResearch#13848) no longer occur.

_supports_adaptive_thinking() now returns True for Kimi-family models,
so they get thinking={type: adaptive, display: summarized} +
output_config.effort via ADAPTIVE_EFFORT_MAP instead of nothing, and
the blanket drop of the thinking parameter for Kimi-family endpoints is
removed. MiniMax and other non-adaptive third parties keep the manual
budget_tokens path; Claude behavior is unchanged.
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/kimi Kimi / Moonshot P2 Medium — degraded but workaround exists needs-decision Awaiting maintainer decision before any implementation labels Jul 19, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related to merged #17455/#14018 and #56727: this reverses the earlier Kimi-thinking suppression based on a claimed changed endpoint contract. It is related work, not a duplicate; please validate the current multi-turn replay contract before choosing it.

webtecnica added a commit to webtecnica/hermes-agent that referenced this pull request Jul 19, 2026
Kimi's Anthropic-compatible endpoints (api.moonshot.cn/anthropic,
api.kimi.com/coding) now implement the adaptive thinking contract
(thinking.type="adaptive" + output_config.effort), and the
replay-validation 400s that originally motivated dropping the
thinking parameter (NousResearch#13848) no longer occur.

- _supports_adaptive_thinking() returns True for Kimi-family models
- Remove blanket Kimi thinking suppression in build_anthropic_kwargs()
- MiniMax and other non-adaptive third parties keep the manual
  budget_tokens path; Claude behavior unchanged
- Update tests: Kimi gets adaptive thinking, effort mapping verified

Closes NousResearch#67228
@webtecnica

Copy link
Copy Markdown
Contributor

Implemented in #67231 — same approach: _supports_adaptive_thinking() returns True for Kimi-family models, blanket thinking suppression removed. All 53 tests pass.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for revisiting the Kimi contract. The current-main premise is real: agent/anthropic_adapter.py:2647-2648 still suppresses Anthropic thinking for Kimi-family endpoints.

Problems

  • The stated signed-thinking replay guarantee is not implemented by this diff. agent/anthropic_adapter.py:2297-2308 preserves only unsigned Kimi thinking blocks and removes any block with signature or data at :2304-2306; this PR changes neither branch.
  • The changed tests cover request construction and effort mapping, but not the stated signed-history or no-thinking-block replay cases. Existing replay coverage at tests/agent/test_kimi_coding_anthropic_thinking.py:175-212 covers only an unsigned reasoning_content-derived block.

Suggested changes

  • Add conversion tests for signed, unsigned, and absent-thinking prior tool-call histories.
  • Validate and encode the required signed-block behavior before removing the suppression; preserve the current signature-stripping safety rule unless the verified Kimi contract requires a different Kimi-specific path.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state 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 19, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #67606 — your commit was cherry-picked onto current main with your authorship preserved in git log (rebase-merge). Thanks for revisiting the Kimi thinking contract and for the thorough live verification across effort levels and replay shapes; combined with the replay-side fix in ddd81e9, Kimi-family endpoints now get full adaptive thinking on the Anthropic wire.

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 needs-decision Awaiting maintainer decision before any implementation P2 Medium — degraded but workaround exists provider/kimi Kimi / Moonshot 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 sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants