From fb8ed4fe25c1cba6c1cb5f3ebc0efbac98217eb6 Mon Sep 17 00:00:00 2001 From: damon Date: Fri, 6 Mar 2026 23:18:15 +0800 Subject: [PATCH] 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. --- pkg/agent/instance.go | 8 ++++++++ pkg/agent/thinking.go | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/pkg/agent/instance.go b/pkg/agent/instance.go index e04c0652d..539b09357 100644 --- a/pkg/agent/instance.go +++ b/pkg/agent/instance.go @@ -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, diff --git a/pkg/agent/thinking.go b/pkg/agent/thinking.go index 41760d40f..8de7b9354 100644 --- a/pkg/agent/thinking.go +++ b/pkg/agent/thinking.go @@ -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