Skip to content

Commit 0f2332b

Browse files
committed
quick toggling of thinking, session wide
can be set from the api as well, just like "yolo" Signed-off-by: Christopher Petito <chrisjpetito@gmail.com>
1 parent 4cd7259 commit 0f2332b

File tree

21 files changed

+598
-29
lines changed

21 files changed

+598
-29
lines changed

docs/USAGE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ During TUI sessions, you can use special slash commands. Type `/` to see all ava
170170
| `/sessions` | Browse and load past sessions |
171171
| `/shell` | Start a shell |
172172
| `/star` | Toggle star on current session |
173+
| `/think` | Toggle thinking/reasoning mode |
173174
| `/yolo` | Toggle automatic approval of tool calls |
174175

175176
#### Runtime Model Switching

pkg/api/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ type SessionResponse struct {
131131
Messages []session.Message `json:"messages,omitempty"`
132132
CreatedAt time.Time `json:"created_at"`
133133
ToolsApproved bool `json:"tools_approved"`
134+
Thinking bool `json:"thinking"`
134135
InputTokens int64 `json:"input_tokens"`
135136
OutputTokens int64 `json:"output_tokens"`
136137
WorkingDir string `json:"working_dir,omitempty"`

pkg/model/provider/anthropic/beta_client.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,27 @@ func (c *Client) createBetaStream(
7070
params.OutputFormat = anthropic.BetaJSONSchemaOutputFormat(structuredOutput.Schema)
7171
}
7272

73+
// Configure thinking if not explicitly disabled via /think command
7374
// For interleaved thinking to make sense, we use a default of 16384 tokens for the thinking budget
74-
thinkingTokens := int64(16384)
75-
if c.ModelConfig.ThinkingBudget != nil {
76-
thinkingTokens = int64(c.ModelConfig.ThinkingBudget.Tokens)
75+
thinkingEnabled := c.ModelOptions.Thinking() == nil || *c.ModelOptions.Thinking()
76+
if thinkingEnabled {
77+
thinkingTokens := int64(16384)
78+
if c.ModelConfig.ThinkingBudget != nil {
79+
thinkingTokens = int64(c.ModelConfig.ThinkingBudget.Tokens)
80+
} else {
81+
slog.Info("Anthropic Beta API using default thinking_budget with interleaved thinking", "budget_tokens", thinkingTokens)
82+
}
83+
switch {
84+
case thinkingTokens >= 1024 && thinkingTokens < maxTokens:
85+
params.Thinking = anthropic.BetaThinkingConfigParamOfEnabled(thinkingTokens)
86+
slog.Debug("Anthropic Beta API using thinking_budget with interleaved thinking", "budget_tokens", thinkingTokens)
87+
case thinkingTokens >= maxTokens:
88+
slog.Warn("Anthropic Beta API thinking_budget must be less than max_tokens, ignoring", "tokens", thinkingTokens, "max_tokens", maxTokens)
89+
default:
90+
slog.Warn("Anthropic Beta API thinking_budget below minimum (1024), ignoring", "tokens", thinkingTokens)
91+
}
7792
} else {
78-
slog.Info("Anthropic Beta API using default thinking_budget with interleaved thinking", "budget_tokens", thinkingTokens)
79-
}
80-
switch {
81-
case thinkingTokens >= 1024 && thinkingTokens < maxTokens:
82-
params.Thinking = anthropic.BetaThinkingConfigParamOfEnabled(thinkingTokens)
83-
slog.Debug("Anthropic Beta API using thinking_budget with interleaved thinking", "budget_tokens", thinkingTokens)
84-
case thinkingTokens >= maxTokens:
85-
slog.Warn("Anthropic Beta API thinking_budget must be less than max_tokens, ignoring", "tokens", thinkingTokens, "max_tokens", maxTokens)
86-
default:
87-
slog.Warn("Anthropic Beta API thinking_budget below minimum (1024), ignoring", "tokens", thinkingTokens)
93+
slog.Debug("Anthropic Beta API: Thinking disabled via /think command")
8894
}
8995

9096
if len(requestTools) > 0 {

pkg/model/provider/bedrock/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ func TestBuildInferenceConfig_DisablesTempTopPWhenThinkingEnabled(t *testing.T)
770770
assert.Equal(t, int32(64000), *cfg.MaxTokens)
771771
}
772772

773-
func TestBuildInferenceConfig_SetsTempTopPWhenThinkingDisabled(t *testing.T) {
773+
func TestBuildInferenceConfig_SetsTempTopPWhenThinkingNotConfigured(t *testing.T) {
774774
t.Parallel()
775775

776776
temp := 0.7

pkg/model/provider/openai/client.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ func (c *Client) CreateResponseStream(
358358

359359
// Configure reasoning for models that support it (o-series, gpt-5)
360360
// Request detailed reasoning summary to get thinking traces for reasoning models
361-
if isOpenAIReasoningModel(c.ModelConfig.Model) {
361+
// Skip reasoning configuration entirely if thinking is explicitly disabled (via /think command)
362+
thinkingEnabled := c.ModelOptions.Thinking() == nil || *c.ModelOptions.Thinking()
363+
if isOpenAIReasoningModel(c.ModelConfig.Model) && thinkingEnabled {
362364
params.Reasoning = shared.ReasoningParam{
363365
Summary: shared.ReasoningSummaryDetailed,
364366
}

0 commit comments

Comments
 (0)