feat(agent-core): enable Preserved Thinking by default on the Anthropic provider#1432
Conversation
…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 detectedLatest commit: 9ff32cf The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
There was a problem hiding this comment.
💡 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 }] }, |
There was a problem hiding this comment.
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 👍 / 👎.
…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.
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.keepto "all"; this extends the same behavior to the Anthropic path so multi-turn reasoning keeps continuity.What changed
context_managementclear_thinking_20251015edit withkeep: "all"(retain all prior thinking blocks).[thinking] keep(config.toml) andKIMI_MODEL_THINKING_KEEP(env) with precedence env > config > default"all"; an off-value (false/0/no/off/none/null) disables it.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
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.