feat(agent): introduce ThinkingLevel for agent instance configuration

- Added ThinkingLevel field to AgentInstance to support model-specific thinking configurations.
- Implemented parseThinkingLevel function to normalize thinking level strings for compatibility.
- Updated NewAgentInstance function to initialize ThinkingLevel from model config.

This change enhances the agent's ability to adapt its thinking parameters based on the model's configuration, improving overall performance and flexibility.
This commit is contained in:
damon 2026-03-06 23:18:15 +08:00
parent e0ece0652c
commit fb8ed4fe25
2 changed files with 35 additions and 0 deletions

View file

@ -26,6 +26,7 @@ type AgentInstance struct {
MaxIterations int
MaxTokens int
Temperature float64
ThinkingLevel ThinkingLevel // Default from model config at creation (main compatibility).
ContextWindow int
SummarizeMessageThreshold int
SummarizeTokenPercent int
@ -124,6 +125,12 @@ func NewAgentInstance(
temperature = *defaults.Temperature
}
var thinkingLevelStr string
if mc, err := cfg.GetModelConfig(model); err == nil {
thinkingLevelStr = mc.ThinkingLevel
}
thinkingLevel := parseThinkingLevel(thinkingLevelStr)
summarizeMessageThreshold := defaults.SummarizeMessageThreshold
if summarizeMessageThreshold == 0 {
summarizeMessageThreshold = 20
@ -209,6 +216,7 @@ func NewAgentInstance(
MaxIterations: maxIter,
MaxTokens: maxTokens,
Temperature: temperature,
ThinkingLevel: thinkingLevel,
ContextWindow: maxTokens,
SummarizeMessageThreshold: summarizeMessageThreshold,
SummarizeTokenPercent: summarizeTokenPercent,

View file

@ -8,6 +8,29 @@ import (
"github.com/sipeed/picoclaw/pkg/config"
)
// ThinkingLevel controls how the provider sends thinking parameters (main compatibility).
// Session-level resolution uses string internally; this type is used for agent default from model config.
type ThinkingLevel string
const (
ThinkingOff ThinkingLevel = "off"
ThinkingLow ThinkingLevel = "low"
ThinkingMedium ThinkingLevel = "medium"
ThinkingHigh ThinkingLevel = "high"
ThinkingXHigh ThinkingLevel = "xhigh"
ThinkingAdaptive ThinkingLevel = "adaptive"
)
// parseThinkingLevel normalizes a config string to a ThinkingLevel (main compatibility).
// Case-insensitive and whitespace-tolerant. Returns ThinkingOff for unknown or empty.
func parseThinkingLevel(level string) ThinkingLevel {
if normalized, ok := normalizeThinkingLevel(level); ok {
return ThinkingLevel(normalized)
}
return ThinkingOff
}
// Unexported string constants for internal use (session, downgrade, aliases).
const (
thinkingOff = "off"
thinkingMinimal = "minimal"
@ -51,6 +74,10 @@ func resolveThinkingLevel(cfg *config.Config, agent *AgentInstance, sessionKey s
if modelLevel := modelThinkingLevel(cfg, agent.Model); modelLevel != "" {
return modelLevel
}
// Main compatibility: fall back to agent default (from model config at creation).
if agent.ThinkingLevel != ThinkingOff {
return string(agent.ThinkingLevel)
}
if cfg != nil {
if level, ok := normalizeThinkingLevel(cfg.Agents.Defaults.Thinking); ok {
return level