mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix(agent): honor explicit thinking off (#2898)
* fix(agent): honor explicit thinking off * fix(agent): address thinking off lint failures * Clarify unset thinking level display * fix ci
This commit is contained in:
+91
-1
@@ -1,6 +1,12 @@
|
||||
package agent
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/sipeed/picoclaw/pkg/config"
|
||||
"github.com/sipeed/picoclaw/pkg/logger"
|
||||
"github.com/sipeed/picoclaw/pkg/providers"
|
||||
)
|
||||
|
||||
// ThinkingLevel controls how the provider sends thinking parameters.
|
||||
//
|
||||
@@ -37,3 +43,87 @@ func parseThinkingLevel(level string) ThinkingLevel {
|
||||
return ThinkingOff
|
||||
}
|
||||
}
|
||||
|
||||
func isConfiguredThinkingLevel(level string) bool {
|
||||
switch strings.ToLower(strings.TrimSpace(level)) {
|
||||
case "off", "low", "medium", "high", "xhigh", "adaptive":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type thinkingSettings struct {
|
||||
level ThinkingLevel
|
||||
configured bool
|
||||
}
|
||||
|
||||
func thinkingSettingsFromModelConfig(mc *config.ModelConfig) thinkingSettings {
|
||||
if mc == nil || !isConfiguredThinkingLevel(mc.ThinkingLevel) {
|
||||
return thinkingSettings{}
|
||||
}
|
||||
return thinkingSettings{
|
||||
level: parseThinkingLevel(mc.ThinkingLevel),
|
||||
configured: true,
|
||||
}
|
||||
}
|
||||
|
||||
func activeThinkingSettings(agent *AgentInstance, modelCfg *config.ModelConfig) thinkingSettings {
|
||||
if settings := thinkingSettingsFromModelConfig(modelCfg); settings.configured {
|
||||
return settings
|
||||
}
|
||||
if modelCfg == nil && agent != nil {
|
||||
return thinkingSettings{
|
||||
level: agent.ThinkingLevel,
|
||||
configured: agent.ThinkingLevelConfigured,
|
||||
}
|
||||
}
|
||||
return thinkingSettings{}
|
||||
}
|
||||
|
||||
func applyThinkingOption(
|
||||
opts map[string]any,
|
||||
provider providers.LLMProvider,
|
||||
settings thinkingSettings,
|
||||
warnUnsupported bool,
|
||||
agentID string,
|
||||
) {
|
||||
if opts == nil || !settings.configured {
|
||||
return
|
||||
}
|
||||
if settings.level == ThinkingOff {
|
||||
opts["thinking_level"] = string(settings.level)
|
||||
return
|
||||
}
|
||||
if tc, ok := provider.(providers.ThinkingCapable); ok && tc.SupportsThinking() {
|
||||
opts["thinking_level"] = string(settings.level)
|
||||
return
|
||||
}
|
||||
if warnUnsupported {
|
||||
logger.WarnCF("agent", "thinking_level is set but current provider does not support it, ignoring",
|
||||
map[string]any{"agent_id": agentID, "thinking_level": string(settings.level)})
|
||||
}
|
||||
}
|
||||
|
||||
func applyTurnThinkingOptions(
|
||||
exec *turnExecution,
|
||||
agent *AgentInstance,
|
||||
provider providers.LLMProvider,
|
||||
warnUnsupported bool,
|
||||
) {
|
||||
if exec == nil || exec.llmOpts == nil {
|
||||
return
|
||||
}
|
||||
delete(exec.llmOpts, "thinking_level")
|
||||
settings := activeThinkingSettings(agent, exec.activeModelConfig)
|
||||
agentID := ""
|
||||
if agent != nil {
|
||||
agentID = agent.ID
|
||||
}
|
||||
applyThinkingOption(exec.llmOpts, provider, settings, warnUnsupported, agentID)
|
||||
exec.suppressReasoning = shouldSuppressReasoningFor(settings)
|
||||
}
|
||||
|
||||
func shouldSuppressReasoningFor(settings thinkingSettings) bool {
|
||||
return settings.configured && settings.level == ThinkingOff
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user