Skip to content

Commit 3029147

Browse files
claude provider: properly handle "withThinking"
1 parent c268269 commit 3029147

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

llms/anthropic/anthropic.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,16 @@ func (p *Anthropic) adaptRequest(_ internal.Adapter, requester llmberjack.Reques
240240

241241
// System messages are handled as separate messages with RoleSystem
242242

243-
// Add budget tokens for thinking if specified
244-
if opts.BudgetTokens != nil && *opts.BudgetTokens > 0 {
243+
// Resolve thinking configuration:
244+
// - WithThinking(false) explicitly disables thinking
245+
// - WithThinking(true) enables with BudgetTokens if set, otherwise default
246+
// - BudgetTokens alone (without WithThinking) enables thinking
247+
if r.Thinking != nil && !*r.Thinking {
248+
// Explicitly disabled, do not set thinking
249+
} else if opts.BudgetTokens != nil && *opts.BudgetTokens > 0 {
245250
params.Thinking = opts.BudgetTokens
251+
} else if r.Thinking != nil && *r.Thinking {
252+
params.Thinking = lo.ToPtr(DefaultThinkingBudgetTokens)
246253
}
247254

248255
// Process messages

llms/anthropic/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
BackendVertexAI Backend = "vertexai"
1212

1313
BackendVertexAiDefaultMaxTokens = 4096
14+
DefaultThinkingBudgetTokens = 10_000
1415
)
1516

1617
type Opt func(*Anthropic)

0 commit comments

Comments
 (0)