Skip to content

Commit 9d92c68

Browse files
committed
feat(agent): support reasoning effort configuration
1 parent e0d9636 commit 9d92c68

3 files changed

Lines changed: 43 additions & 10 deletions

File tree

internal/agent/agent.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ func NewAgent(m Model, cfg config.Config, reg ...*skills.Registry) (*Agent, erro
7878
ModelInfo: findModel(cfg.Model),
7979
skills: skillsRegistry,
8080
Chat: model.Chat{
81-
Model: cfg.Model,
82-
SessionID: model.NewSessionID(),
83-
Messages: []model.Message{{Role: model.MessageRoleDeveloper, Content: developerPrompt}},
84-
Tools: toolRegistry.Tools(),
81+
Model: cfg.Model,
82+
ReasoningEffort: cfg.ReasoningEffort,
83+
SessionID: model.NewSessionID(),
84+
Messages: []model.Message{{Role: model.MessageRoleDeveloper, Content: developerPrompt}},
85+
Tools: toolRegistry.Tools(),
8586
},
8687
}, nil
8788
}

internal/config/config.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44
package config
55

66
import (
7+
"fmt"
78
"os"
89

910
"github.com/adrg/xdg"
1011
"github.com/pelletier/go-toml/v2"
12+
13+
"thing/internal/model"
1114
)
1215

1316
// Config represents the configuration for the application.
1417
type Config struct {
15-
Model string `toml:"model"`
16-
Endpoint string `toml:"endpoint"`
18+
Model string `toml:"model"`
19+
Endpoint string `toml:"endpoint"`
20+
ReasoningEffort model.ReasoningEffort `toml:"reasoning_effort"`
1721
}
1822

1923
// Load loads the configuration file from the XDG config directory.
@@ -33,6 +37,9 @@ func Load() (*Config, error) {
3337
if err := toml.NewDecoder(f).Decode(&config); err != nil {
3438
return nil, err
3539
}
40+
if config.ReasoningEffort != "" && !config.ReasoningEffort.Valid() {
41+
return nil, fmt.Errorf("invalid reasoning_effort %q: want minimal, low, medium, high, xhigh, or max", config.ReasoningEffort)
42+
}
3643

3744
return &config, nil
3845
}

internal/model/model.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,30 @@ import (
1212
// MessageRole represents the role of a message in a chat conversation.
1313
type MessageRole string
1414

15+
// ReasoningEffort controls how many reasoning tokens the model may use.
16+
// OpenAI defines these values for reasoning-capable models.
17+
type ReasoningEffort string
18+
19+
const (
20+
ReasoningEffortMinimal ReasoningEffort = "minimal"
21+
ReasoningEffortLow ReasoningEffort = "low"
22+
ReasoningEffortMedium ReasoningEffort = "medium"
23+
ReasoningEffortHigh ReasoningEffort = "high"
24+
ReasoningEffortXHigh ReasoningEffort = "xhigh"
25+
ReasoningEffortMax ReasoningEffort = "max"
26+
)
27+
28+
// Valid reports whether the reasoning effort is an OpenAI-supported value.
29+
func (r ReasoningEffort) Valid() bool {
30+
switch r {
31+
case ReasoningEffortMinimal, ReasoningEffortLow, ReasoningEffortMedium,
32+
ReasoningEffortHigh, ReasoningEffortXHigh, ReasoningEffortMax:
33+
return true
34+
default:
35+
return false
36+
}
37+
}
38+
1539
const (
1640
MessageRoleDeveloper MessageRole = "developer" // Developer-provided instructions that the model should follow.
1741
MessageRoleUser MessageRole = "user" // Messages sent by an end user.
@@ -32,10 +56,11 @@ const (
3256
// together to maximize cache hits. Keeping it here means it serializes with the
3357
// conversation and so is restored naturally when deserializing it.
3458
type Chat struct {
35-
SessionID string `json:"session_id,omitempty"`
36-
Model string `json:"model"`
37-
Tools []Tool `json:"tools"`
38-
Messages []Message `json:"messages"`
59+
SessionID string `json:"session_id,omitempty"`
60+
Model string `json:"model"`
61+
ReasoningEffort ReasoningEffort `json:"reasoning_effort,omitempty"`
62+
Tools []Tool `json:"tools"`
63+
Messages []Message `json:"messages"`
3964
}
4065

4166
// NewSessionID returns a random UUIDv4 used to identify a conversation.

0 commit comments

Comments
 (0)