Skip to content

feat(agent-core): enable Preserved Thinking by default on the Anthropic provider#1432

Merged
RealKai42 merged 4 commits into
mainfrom
kaiyi/guangzhou-v2
Jul 6, 2026
Merged

feat(agent-core): enable Preserved Thinking by default on the Anthropic provider#1432
RealKai42 merged 4 commits into
mainfrom
kaiyi/guangzhou-v2

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

Related Issue

No tracking issue — implements a direct maintainer/user request to default Preserved Thinking on for the Anthropic provider too.

Problem

For Anthropic-protocol requests (Claude and Kimi in Anthropic-compatible mode), prior turns' thinking was not preserved across turns by default. The Kimi provider already defaults thinking.keep to "all"; this extends the same behavior to the Anthropic path so multi-turn reasoning keeps continuity.

What changed

  • Default Preserved Thinking on for the Anthropic provider while Thinking is on, sending a context_management clear_thinking_20251015 edit with keep: "all" (retain all prior thinking blocks).
  • Reuse [thinking] keep (config.toml) and KIMI_MODEL_THINKING_KEEP (env) with precedence env > config > default "all"; an off-value (false/0/no/off/none/null) disables it.
  • Applies to every Anthropic provider (Claude and Kimi in Anthropic-compatible mode); only injected while Thinking is on.

Unit and integration tests are updated, bilingual docs (config-files.md, env-vars.md) are synced, and a changeset is included. Validated end-to-end against real endpoints (openai-protocol Kimi, Anthropic-protocol Kimi, and Claude) with multi-turn tool loops.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

…ic provider

Default thinking.keep to "all" for the Anthropic provider (Claude and Kimi in Anthropic-compatible mode) while Thinking is on, via a context_management clear_thinking_20251015 edit, mirroring the Kimi default. Reuses [thinking] keep and KIMI_MODEL_THINKING_KEEP (env > config > default "all"); off-values disable it.
@changeset-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9ff32cf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 6, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@97cd881
npx https://pkg.pr.new/@moonshot-ai/kimi-code@97cd881

commit: 97cd881

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9ff32cfc87

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

? current
: [...current, CONTEXT_MANAGEMENT_BETA];
return this._withGenerationKwargs({
contextManagement: { edits: [{ type: CLEAR_THINKING_EDIT, keep }] },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve existing context-management edits

When a caller has already configured another Anthropic context-management edit (for example clear_tool_uses_20250919 via withGenerationKwargs) and then calls withThinkingKeep(), this line replaces the whole contextManagement object. That silently drops the existing edit, so combined context editing stops clearing tool results; merge/prepend the clear_thinking_20251015 edit instead (Anthropic also requires the thinking edit to be first when edits are combined: https://platform.claude.com/docs/en/build-with-claude/context-editing#combining-strategies).

Useful? React with 👍 / 👎.

RealKai42 added 3 commits July 6, 2026 21:40
…sages API

Force the beta endpoint (client.beta.messages.create) when thinking.keep is enabled, since clear_thinking_20251015 is only honored there. Also prepend clear_thinking to any existing context-management edits (for example clear_tool_uses) instead of replacing them, keeping it first as Anthropic requires when combining edits.
Note in code comments and bilingual docs that enabling Anthropic Preserved Thinking routes requests to the beta Messages API (client.beta.messages.create), with keep=off as the escape hatch back to the standard endpoint. Correct the resolveThinkingKeep comment to reflect that compaction shares ConfigState.provider and intentionally carries the same keep.
…aApi)

Add a streaming beta-endpoint capture and a test that withThinkingKeep forces the beta endpoint even when constructed with betaApi: false, pinning down the documented behavior.
@RealKai42 RealKai42 merged commit 25a655c into main Jul 6, 2026
10 checks passed
@RealKai42 RealKai42 deleted the kaiyi/guangzhou-v2 branch July 6, 2026 15:45
@github-actions github-actions Bot mentioned this pull request Jul 6, 2026
wbxl2000 added a commit that referenced this pull request Jul 7, 2026
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