Send adaptive low-effort thinking for Opus 5.5 when reasoning is off
Opus 5.5 returns 400 on thinking {type:"disabled"}, and its ID matched the
"claude-opus-5" marker, so it inherited Opus 5's explicit disabled config.
This commit is contained in:
1 parent
9a013f6f4b
commit
a1f34cce4c
2 files changed
+38
No files matched your search
@@ -160,6 +160,16 @@ func (p *AnthropicProvider) buildMessageParams(req llm.ChatRequest) anthropic.Me
|
|||||||
slog.Info("anthropic adaptive thinking",
|
slog.Info("anthropic adaptive thinking",
|
||||||
"model", model,
|
"model", model,
|
||||||
"effort", string(anthropicEffort(req.Reasoning)))
|
"effort", string(anthropicEffort(req.Reasoning)))
|
||||||
|
} else if anthropicRejectsDisabledThinking(model) {
|
||||||
|
// Opus 5.5 can't turn thinking off: {type:"disabled"} is a 400
|
||||||
|
// ("use thinking.type.adaptive and output_config.effort").
|
||||||
|
// Adaptive at low effort is the closest accepted "off".
|
||||||
|
params.Thinking = anthropic.ThinkingConfigParamUnion{
|
||||||
|
OfAdaptive: &anthropic.ThinkingConfigAdaptiveParam{},
|
||||||
|
}
|
||||||
|
params.OutputConfig = anthropic.OutputConfigParam{
|
||||||
|
Effort: anthropic.OutputConfigEffortLow,
|
||||||
|
}
|
||||||
} else if anthropicThinksByDefault(model) {
|
} else if anthropicThinksByDefault(model) {
|
||||||
// Opus 5 and Sonnet 5 think by default when the thinking
|
// Opus 5 and Sonnet 5 think by default when the thinking
|
||||||
// param is omitted entirely (unlike Opus 4.7/4.8, Fable 5,
|
// param is omitted entirely (unlike Opus 4.7/4.8, Fable 5,
|
||||||
@@ -557,6 +567,13 @@ func anthropicThinksByDefault(model string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// anthropicRejectsDisabledThinking reports whether the model returns a 400
|
||||||
|
// for thinking {type:"disabled"}. Checked before anthropicThinksByDefault,
|
||||||
|
// whose "claude-opus-5" marker also matches Opus 5.5 IDs.
|
||||||
|
func anthropicRejectsDisabledThinking(model string) bool {
|
||||||
|
return strings.Contains(model, "claude-opus-5-5")
|
||||||
|
}
|
||||||
|
|
||||||
// anthropicEffort maps the unified ReasoningMode onto output_config.effort
|
// anthropicEffort maps the unified ReasoningMode onto output_config.effort
|
||||||
// for adaptive-thinking-only models.
|
// for adaptive-thinking-only models.
|
||||||
func anthropicEffort(mode llm.ReasoningMode) anthropic.OutputConfigEffort {
|
func anthropicEffort(mode llm.ReasoningMode) anthropic.OutputConfigEffort {
|
||||||
|
|||||||
@@ -759,6 +759,27 @@ func TestOpus5AndSonnet5_ThinkByDefault_ReasoningOffSendsDisabled(t *testing.T)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestOpus5_5_ReasoningOffSendsAdaptiveLow guards against a 400 from Opus
|
||||||
|
// 5.5: its ID matches the "claude-opus-5" marker, so it inherited Opus 5's
|
||||||
|
// explicit {type:"disabled"} — which Opus 5.5 rejects ("thinking.type.disabled
|
||||||
|
// is not supported for this model"). The nearest accepted equivalent of
|
||||||
|
// "reasoning off" is adaptive thinking at low effort.
|
||||||
|
func TestOpus5_5_ReasoningOffSendsAdaptiveLow(t *testing.T) {
|
||||||
|
p := NewAnthropicProvider("test-key", "")
|
||||||
|
for _, model := range []string{"claude-opus-5-5", "claude-opus-5-5-global"} {
|
||||||
|
t.Run(model, func(t *testing.T) {
|
||||||
|
got := wireJSON(t, p, llm.ChatRequest{
|
||||||
|
Model: model,
|
||||||
|
Messages: []llm.Message{{Role: "user", Content: "hi"}},
|
||||||
|
})
|
||||||
|
assert.NotContains(t, got, `"disabled"`,
|
||||||
|
"Opus 5.5 rejects thinking.type.disabled")
|
||||||
|
assert.Contains(t, got, `"thinking":{"type":"adaptive"}`)
|
||||||
|
assert.Contains(t, got, `"effort":"low"`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestLegacyThinkingModels_KeepBudgetTokens(t *testing.T) {
|
func TestLegacyThinkingModels_KeepBudgetTokens(t *testing.T) {
|
||||||
p := NewAnthropicProvider("test-key", "")
|
p := NewAnthropicProvider("test-key", "")
|
||||||
got := wireJSON(t, p, llm.ChatRequest{
|
got := wireJSON(t, p, llm.ChatRequest{
|
||||||
|
|||||||
Reference in new issue
Block a user