fix(qa): wire agent thinking toggle and show reasoning in RAG timeline

Default unset agent thinking to explicit false so thinking_type models
receive disabled/enabled wire params. Render reasoning inside the quick-answer
pipeline timeline only when thinking events arrive, avoiding a flash of the
thinking step when thinking mode is off.
This commit is contained in:
wizardchen
2026-06-23 19:59:41 +08:00
committed by lyingbug
parent be26563f86
commit bc9ad3aca0
9 changed files with 240 additions and 38 deletions
@@ -53,6 +53,11 @@ func prepareChatModel(ctx context.Context, modelService interfaces.ModelService,
PresencePenalty: chatManage.SummaryConfig.PresencePenalty,
Thinking: chatManage.SummaryConfig.Thinking,
}
if opt.Thinking != nil {
pipelineInfo(ctx, "Stream", "thinking_option", map[string]interface{}{
"enabled": *opt.Thinking,
})
}
return chatModel, opt, nil
}
@@ -131,10 +131,14 @@ func (s *sessionService) applyAgentOverridesToChatManage(
cm.SummaryConfig.MaxCompletionTokens = customAgent.Config.MaxCompletionTokens
logger.Infof(ctx, "Using custom agent's max_completion_tokens: %d", customAgent.Config.MaxCompletionTokens)
}
// Agent-level thinking setting takes full control (no global fallback)
// Agent-level thinking setting takes full control (no global fallback).
// EnsureDefaults pins nil to explicit false so thinking_control wire formats
// always receive a value.
cm.SummaryConfig.Thinking = customAgent.Config.Thinking
if customAgent.Config.Thinking != nil {
logger.Infof(ctx, "Using custom agent's thinking: %v", *customAgent.Config.Thinking)
} else {
logger.Warnf(ctx, "Custom agent thinking is unset after EnsureDefaults; model thinking param will be omitted")
}
// Override retrieval strategy settings
+6
View File
@@ -315,6 +315,12 @@ func (a *CustomAgent) EnsureDefaults() {
if a.Config.AgentMode == AgentModeSmartReasoning {
a.Config.MultiTurnEnabled = true
}
// Pin thinking to an explicit false when unset so provider-specific wire
// formats (e.g. thinking_control=thinking_type) always receive a value.
if a.Config.Thinking == nil {
disabled := false
a.Config.Thinking = &disabled
}
}
// IsAgentMode returns true if this agent uses ReAct agent mode
+23
View File
@@ -0,0 +1,23 @@
package types
import "testing"
func TestEnsureDefaults_ThinkingExplicitFalse(t *testing.T) {
agent := &CustomAgent{Config: CustomAgentConfig{}}
agent.EnsureDefaults()
if agent.Config.Thinking == nil {
t.Fatal("EnsureDefaults should set Thinking to explicit false when unset")
}
if *agent.Config.Thinking {
t.Fatal("default Thinking should be false")
}
}
func TestEnsureDefaults_ThinkingPreservesTrue(t *testing.T) {
enabled := true
agent := &CustomAgent{Config: CustomAgentConfig{Thinking: &enabled}}
agent.EnsureDefaults()
if agent.Config.Thinking == nil || !*agent.Config.Thinking {
t.Fatal("EnsureDefaults must not overwrite an explicit Thinking=true")
}
}