feat(claude): add adaptive thinking + output effort for Opus 4.7+#781
feat(claude): add adaptive thinking + output effort for Opus 4.7+#781NicolasWalter wants to merge 1 commit into
Conversation
@NicolasWalter hello,please sign the CLA. |
|
@NicolasWalter please solve conflicts. |
|
@NicolasWalter Thanks for the PR! The feature direction looks good to me, and I confirmed that the current Claude adapter does not yet expose adaptive thinking / output effort support. A few small suggestions before merging:
|
00e0e6c to
cd2ec76
Compare
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+.
cd2ec76 to
5f22b99
Compare
|
Thanks for the review. I addressed all three points:
I also rebased the branch on the latest |
|
@NicolasWalter hello, I suggest exposing |
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.