Skip to content

feat(opencode): use adaptive thinking effort for kimi family on anthr…#37696

Open
chouqin wants to merge 1 commit into
anomalyco:devfrom
chouqin:kimi-adaptive-thinking
Open

feat(opencode): use adaptive thinking effort for kimi family on anthr…#37696
chouqin wants to merge 1 commit into
anomalyco:devfrom
chouqin:kimi-adaptive-thinking

Conversation

@chouqin

@chouqin chouqin commented Jul 19, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Kimi/Moonshot's Anthropic-compatible endpoints implement Anthropic's adaptive thinking contract (thinking.type="adaptive" + output_config.effort, including xhigh and the display field). Today opencode sends manual thinking
with a hardcoded budgetTokens: 16000 default for kimi models on @ai-sdk/anthropic, and exposes no effort variants for them.

Changes:

  • Default options for kimi family models on the anthropic protocol now send {type: "adaptive", display: "summarized"} with effort: "high" instead of budget tokens. display: "summarized" matters because newer adaptive models
    default to omitting thinking text, and that text is what gets replayed on subsequent requests.
  • variants() exposes low/medium/high/xhigh/max for kimi models on @ai-sdk/anthropic, each mapping to adaptive thinking + effort.
  • anthropicEffort treats kimi family as adaptive. This also fixes models.dev-declared effort options (e.g. kimi-k3 low/high/max) being silently dropped — the anthropic branch previously returned undefined for non-Claude model
    ids.

Why it works: @ai-sdk/anthropic already lowers providerOptions.anthropic.thinking = {type: "adaptive"} and providerOptions.anthropic.effort to thinking + output_config.effort on the wire, so no SDK change is needed. Kimi
family detection matches providerID / api id / model id / api url (isKimiFamily). OpenAI-compatible kimi paths are untouched, and user-selected variants still override the default (merge order unchanged).

Note: an identical isKimiFamily helper also appears in my other PR (preserve unsigned thinking). They are independent; whichever lands second rebases to keep a single copy.

How did you verify your code works?

  • Unit tests in test/provider/transform.test.ts: default adaptive+effort for kimi on anthropic npm (asserting no budgetTokens), no thinking default for non-reasoning kimi / non-kimi anthropic / kimi on openai-compatible, the
    five effort variants' shape, and models.dev effort options mapping for a kimi-k3-like entry. bun test test/provider/transform.test.ts → 352 pass, plus bun typecheck from packages/opencode.
  • End-to-end through the installed @ai-sdk/anthropic@3.0.82 with a stub fetch capturing the request body: with the providerOptions this PR emits, the outgoing body contains thinking: {"type":"adaptive","display":"summarized"}
    and output_config: {"effort":"high"}. (No live Moonshot call — worth a quick manual check with a real key before merge.)

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant