Skip to content

Commit 4a22704

Browse files
Feature enhancement: thinking budget flag (#44)
1 parent a2a5f2c commit 4a22704

10 files changed

+72
-895
lines changed

internal/agent/anthropic.go

+22-21
Original file line numberDiff line numberDiff line change
@@ -126,30 +126,31 @@ func NewAnthropicExecutor(baseUrl string, apiKey string, logger Logger, ignorer
126126
}),
127127
}
128128

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
130130
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+
}
149137

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)
152143
}
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)
153154
}
154155

155156
// Set optional parameters if provided and thinking is not enabled

internal/agent/deepseek.go

-338
This file was deleted.

0 commit comments

Comments
 (0)