Skip to content

Commit 1288bf0

Browse files
author
molty3000
committed
feat: add --thinking flag for model reasoning depth
Supports Deepseek (enabled/disabled → thinking.type) and OpenAI o-series (low/medium/high → reasoning_effort). Wired through Config → Client → CallParams → CLI flag.
1 parent 5f85e12 commit 1288bf0

3 files changed

Lines changed: 44 additions & 15 deletions

File tree

cmd/kode/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ Flags:
4545
--model <name> LLM model (default: deepseek-chat)
4646
--base-url <url> API endpoint (default: https://api.deepseek.com/v1)
4747
--max-iter <n> Max think->act cycles (default: 90)
48+
--thinking <level> Reasoning depth: enabled|disabled (Deepseek) or low|medium|high (OpenAI o-series)
4849
--sandbox Run in isolated Docker container
4950
--system <prompt> System prompt override`)
5051
}
5152

5253
func runCmd() {
5354
args := os.Args[2:]
54-
var model, baseURL, system string
55+
var model, baseURL, system, thinking string
5556
maxIter := 90
5657
sandbox := false
5758

@@ -70,6 +71,9 @@ func runCmd() {
7071
case "--system":
7172
system = args[i+1]
7273
i += 2
74+
case "--thinking":
75+
thinking = args[i+1]
76+
i += 2
7377
case "--sandbox":
7478
sandbox = true
7579
i++
@@ -97,6 +101,7 @@ done:
97101
BaseURL: baseURL,
98102
MaxIterations: maxIter,
99103
SystemMessage: system,
104+
Thinking: thinking,
100105
Tools: builtinTools(),
101106
})
102107
if err != nil {

internal/llm/client.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@ import (
1414

1515
// Client sends chat completion requests to any OpenAI-compatible endpoint.
1616
type Client struct {
17-
BaseURL string
18-
APIKey string
19-
Model string
20-
http *http.Client
17+
BaseURL string
18+
APIKey string
19+
Model string
20+
Thinking string // "enabled", "disabled", "low", "medium", "high", or empty
21+
http *http.Client
2122
}
2223

2324
// New creates a Client with sensible defaults.
24-
func New(baseURL, apiKey, model string) *Client {
25+
func New(baseURL, apiKey, model, thinking string) *Client {
2526
return &Client{
26-
BaseURL: strings.TrimRight(baseURL, "/"),
27-
APIKey: apiKey,
28-
Model: model,
29-
http: &http.Client{Timeout: 120 * time.Second},
27+
BaseURL: strings.TrimRight(baseURL, "/"),
28+
APIKey: apiKey,
29+
Model: model,
30+
Thinking: thinking,
31+
http: &http.Client{Timeout: 120 * time.Second},
3032
}
3133
}
3234

@@ -65,10 +67,17 @@ type FunctionDef struct {
6567

6668
// CallParams is the request body for /chat/completions.
6769
type CallParams struct {
68-
Model string `json:"model"`
69-
Messages []Message `json:"messages"`
70-
Tools []ToolDef `json:"tools,omitempty"`
71-
Stream bool `json:"stream"`
70+
Model string `json:"model"`
71+
Messages []Message `json:"messages"`
72+
Tools []ToolDef `json:"tools,omitempty"`
73+
Stream bool `json:"stream"`
74+
Thinking *ThinkingConfig `json:"thinking,omitempty"`
75+
ReasoningEffort string `json:"reasoning_effort,omitempty"`
76+
}
77+
78+
// ThinkingConfig controls Deepseek's extended thinking feature.
79+
type ThinkingConfig struct {
80+
Type string `json:"type"` // "enabled" or "disabled"
7281
}
7382

7483
// CallResult is the parsed response from /chat/completions.
@@ -89,6 +98,13 @@ func (c *Client) Call(ctx context.Context, messages []Message, tools []ToolDef)
8998
Stream: false,
9099
}
91100

101+
switch c.Thinking {
102+
case "enabled", "disabled":
103+
body.Thinking = &ThinkingConfig{Type: c.Thinking}
104+
case "low", "medium", "high":
105+
body.ReasoningEffort = c.Thinking
106+
}
107+
92108
reqBytes, err := json.Marshal(body)
93109
if err != nil {
94110
return nil, fmt.Errorf("llm: marshal request: %w", err)

kode.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ type Config struct {
5050
// Falls back to DEEPSEEK_API_KEY, then OPENAI_API_KEY env vars.
5151
APIKey string
5252

53+
// Thinking controls the model's reasoning depth. Provider-specific:
54+
//
55+
// Deepseek: "enabled" or "disabled" → {"type": "enabled"}
56+
// OpenAI o-series: "low", "medium", "high" → {"reasoning_effort": "low"}
57+
//
58+
// Leave empty for provider default behavior.
59+
Thinking string
60+
5361
// Tools available to the agent.
5462
Tools []Tool
5563

@@ -95,7 +103,7 @@ func New(cfg Config) (*Agent, error) {
95103
}
96104

97105
registry := tool.NewRegistry(tools)
98-
client := llm.New(cfg.BaseURL, cfg.APIKey, cfg.Model)
106+
client := llm.New(cfg.BaseURL, cfg.APIKey, cfg.Model, cfg.Thinking)
99107
engine := loop.New(client, registry, cfg.MaxIterations, cfg.SystemMessage)
100108

101109
return &Agent{

0 commit comments

Comments
 (0)