@@ -126,30 +126,31 @@ func NewAnthropicExecutor(baseUrl string, apiKey string, logger Logger, ignorer
126
126
}),
127
127
}
128
128
129
- // Add extended thinking configuration if CPE_CLAUDE_THINKING is set and this is Claude 3.7
129
+ // Add extended thinking configuration if thinking budget is provided and this is Claude 3.7
130
130
var thinkingEnabled bool
131
- if strings .HasPrefix (config .Model , "claude-3-7" ) {
132
- if thinkingBudgetStr := os .Getenv ("CPE_CLAUDE_THINKING" ); thinkingBudgetStr != "" {
133
- thinkingBudget , err := strconv .Atoi (thinkingBudgetStr )
134
- if err != nil {
135
- return nil , fmt .Errorf ("invalid CPE_CLAUDE_THINKING value: %w" , err )
136
- }
137
- if thinkingBudget < 1024 {
138
- return nil , fmt .Errorf ("CPE_CLAUDE_THINKING value must be at least 1024 tokens" )
139
- }
140
- if thinkingBudget >= config .MaxTokens {
141
- return nil , fmt .Errorf ("CPE_CLAUDE_THINKING value must be less than max_tokens (%d)" , config .MaxTokens )
142
- }
143
- var thinkingConfig a.BetaThinkingConfigParamUnion = & a.BetaThinkingConfigEnabledParam {
144
- Type : a .F (a .BetaThinkingConfigEnabledTypeEnabled ),
145
- BudgetTokens : a .F (int64 (thinkingBudget )),
146
- }
147
- params .Thinking = a .F (thinkingConfig )
148
- thinkingEnabled = true
131
+ if strings .HasPrefix (config .Model , "claude-3-7" ) && config .ThinkingBudget != "" && config .ThinkingBudget != "0" {
132
+ // Parse thinking budget as a number
133
+ thinkingBudget , err := strconv .Atoi (config .ThinkingBudget )
134
+ if err != nil {
135
+ return nil , fmt .Errorf ("thinking budget must be a numerical value for Anthropic models, got %q" , config .ThinkingBudget )
136
+ }
149
137
150
- // When thinking is enabled, temperature must be 1.0 and other params must be unset
151
- params .Temperature = a .F (1.0 )
138
+ if thinkingBudget < 1024 {
139
+ return nil , fmt .Errorf ("thinking budget value must be at least 1024 tokens, got %d" , thinkingBudget )
140
+ }
141
+ if thinkingBudget >= config .MaxTokens {
142
+ return nil , fmt .Errorf ("thinking budget value must be less than max_tokens (%d), got %d" , config .MaxTokens , thinkingBudget )
152
143
}
144
+
145
+ // Only set thinking config if we have a valid budget
146
+ params .Thinking = a .F (a .BetaThinkingConfigParamUnion (& a.BetaThinkingConfigEnabledParam {
147
+ Type : a .F (a .BetaThinkingConfigEnabledTypeEnabled ),
148
+ BudgetTokens : a .F (int64 (thinkingBudget )),
149
+ }))
150
+ thinkingEnabled = true
151
+
152
+ // When thinking is enabled, temperature must be 1.0 and other params must be unset
153
+ params .Temperature = a .F (1.0 )
153
154
}
154
155
155
156
// Set optional parameters if provided and thinking is not enabled
0 commit comments