feat(claude): add adaptive thinking + output effort for Opus 4.7+#781
Open
NicolasWalter wants to merge 1 commit intocloudwego:mainfrom
Open
feat(claude): add adaptive thinking + output effort for Opus 4.7+#781NicolasWalter wants to merge 1 commit intocloudwego:mainfrom
NicolasWalter wants to merge 1 commit intocloudwego:mainfrom
Conversation
Claude Opus 4.7 rejects the legacy {"type":"enabled","budget_tokens":N}
thinking shape and requires {"type":"adaptive"} with optional
output_config.effort. Without this change, enabling thinking on the new
models returns:
invalid_request_error: "thinking.type.enabled" is not supported for
this model. Use "thinking.type.adaptive" and "output_config.effort"
to control thinking behavior.
Changes (additive, backward compatible):
- Add Thinking.Mode (ThinkingModeEnabled default, ThinkingModeAdaptive
for Opus 4.7+). Empty mode keeps the legacy behavior for every
existing caller.
- Add Thinking.Effort ("low"|"medium"|"high"|"max"). When set, it
populates params.OutputConfig.Effort using the SDK's typed enum.
- Dispatch in genMessageNewParams: emit OfAdaptive for adaptive mode,
OfEnabled (with BudgetTokens) otherwise. Effort applies to both.
- normalizeOutputEffort helper (trim + case-insensitive; unknown values
are ignored rather than rejected, matching the rest of the adapter).
- Docs (README + README_zh) show the adaptive snippet next to the
existing enabled snippet.
- Unit tests cover the seven relevant cases (legacy default, empty
mode default, adaptive with/without Effort, Effort normalization,
unknown Effort ignored, Enable=false short-circuit).
No new module dependency: the adapter already imports
anthropic-sdk-go and the SDK exposes ThinkingConfigAdaptiveParam and
OutputConfigParam since v1.25+.
|
Nicolas Walter seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
feat
Check the PR title.
<type>(optional scope): <description>(Optional) Translate the PR title into Chinese.
feat(claude): 为 Opus 4.7+ 模型支持自适应思考(adaptive thinking)及输出精力等级(output effort)
(Optional) More detailed description for this PR
en:
Claude Opus 4.7 rejects the legacy
{"type":"enabled","budget_tokens":N}thinking shape and requires{"type":"adaptive"}with an optionaloutput_config.effort. The current adapter only emits the legacy shape, so callingclaude.WithThinking(...)against Opus 4.7 returns:This PR adds an opt-in adaptive path. Changes are additive and backward-compatible — every existing caller keeps its current behavior because the empty
Modedefaults toThinkingModeEnabled.Changes
Thinking.Mode(ThinkingModeEnableddefault,ThinkingModeAdaptivefor Opus 4.7+). Empty mode preserves the pre-existing behavior.Thinking.Effort("low" | "medium" | "high" | "max") → populatesparams.OutputConfig.Effortusing the SDK's typed enum. Trim + case-insensitive; unknown values are silently ignored to match the rest of the adapter's leniency.genMessageNewParams: emitOfAdaptivefor adaptive mode,OfEnabled(withBudgetTokens) otherwise.Effortapplies to both.normalizeOutputEfforthelper at the bottom ofclaude.go(next togetEnvWithFallbacks).utils.gostays untouched (no new imports there).WithThinkingexample.TestThinkingConfigwith 7 subtests covering the relevant paths: legacy default, empty mode default, adaptive with/without Effort, Effort normalization (trim + case), unknown Effort ignored,Enable=falseshort-circuit. All pass undermockeywith the same style as the existing tests.No new module dependency: the adapter already imports
github.com/anthropics/anthropic-sdk-go(5 packages from it, actually) and the SDK exposesThinkingConfigAdaptiveParamandOutputConfigParamsince v1.25+. Nothing added togo.mod.zh(optional):
本 PR 为 Claude 适配器增加 adaptive thinking 和 output effort 支持,以兼容 Opus 4.7 及更新模型。向后兼容:
Mode为空时保留原有OfEnabled+budget_tokens行为。新增Thinking.Mode、Thinking.Effort字段和ThinkingModeEnabled/ThinkingModeAdaptive常量;同时更新 README 示例,新增 7 个单元测试覆盖主要路径;未引入新的模块依赖(anthropic-sdk-go已是适配器的直接依赖)。(Optional) Which issue(s) this PR fixes
Fixes #780
(optional) The PR that updates user documentation
N/A — adapter-local README + README_zh updated in this PR.