From bc9ad3aca09196ab92edb998003c8e0b59787295 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Tue, 23 Jun 2026 19:59:41 +0800 Subject: [PATCH] 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. --- frontend/src/views/agent/AgentEditorModal.vue | 3 + .../AgentStreamDisplay.style.test.mjs | 8 + .../chat/components/AgentStreamDisplay.vue | 5 +- .../RagPipelineProgress.style.test.mjs | 25 ++- .../chat/components/RagPipelineProgress.vue | 197 +++++++++++++++--- .../service/chat_pipeline/common.go | 5 + .../application/service/session_qa_helpers.go | 6 +- internal/types/custom_agent.go | 6 + internal/types/custom_agent_test.go | 23 ++ 9 files changed, 240 insertions(+), 38 deletions(-) create mode 100644 internal/types/custom_agent_test.go diff --git a/frontend/src/views/agent/AgentEditorModal.vue b/frontend/src/views/agent/AgentEditorModal.vue index 68a15d91..df089864 100644 --- a/frontend/src/views/agent/AgentEditorModal.vue +++ b/frontend/src/views/agent/AgentEditorModal.vue @@ -2459,6 +2459,9 @@ watch(() => props.visible, async (val) => { // 补全可能缺失的字段 agentData.config = { ...defaultFormData.config, ...agentData.config }; + if (agentData.config.thinking == null) { + agentData.config.thinking = false; + } // 确保数组字段存在 if (!agentData.config.suggested_prompts) agentData.config.suggested_prompts = []; diff --git a/frontend/src/views/chat/components/AgentStreamDisplay.style.test.mjs b/frontend/src/views/chat/components/AgentStreamDisplay.style.test.mjs index daa24318..e2015c76 100644 --- a/frontend/src/views/chat/components/AgentStreamDisplay.style.test.mjs +++ b/frontend/src/views/chat/components/AgentStreamDisplay.style.test.mjs @@ -63,6 +63,14 @@ test('rag mode delegates pre-answer loading to pipeline and keeps dots while ans assert.match(source, /v-if="!ragMode \|\| displayEvents\.length > 0 \|\| showAgentActivityIndicator"/) }) +test('rag mode keeps model thinking out of the answer stream component', () => { + assert.match(source, /if \(props\.ragMode\)\s*\{[\s\S]*e\.type === 'answer'/) + assert.doesNotMatch( + source, + /if \(props\.ragMode\)\s*\{[\s\S]*e\.type === 'answer' \|\| e\.type === 'thinking'/, + ) +}) + test('only the collapsed root summary shows an expand chevron', () => { assert.match(source, /tree-root-summary[\s\S]*class="action-show-icon"/) assert.match(source, /showIntermediateSteps \? 'chevron-down' : 'chevron-right'/) diff --git a/frontend/src/views/chat/components/AgentStreamDisplay.vue b/frontend/src/views/chat/components/AgentStreamDisplay.vue index 25bb7b24..c79c5e4f 100644 --- a/frontend/src/views/chat/components/AgentStreamDisplay.vue +++ b/frontend/src/views/chat/components/AgentStreamDisplay.vue @@ -1337,9 +1337,8 @@ const displayEvents = computed(() => { const result = buildFullEventList(stream); - // Quick-answer RAG: only render the final answer stream here. Pipeline steps - // are ephemeral UI in RagPipelineProgress and are replaced by citations or - // answer output — never show tool_call cards in this component. + // Quick-answer RAG: pipeline steps and model thinking live in RagPipelineProgress; + // here we only render the final answer stream. if (props.ragMode) { return result.filter((e: any) => e.type === 'answer'); } diff --git a/frontend/src/views/chat/components/RagPipelineProgress.style.test.mjs b/frontend/src/views/chat/components/RagPipelineProgress.style.test.mjs index bb41a3d0..112b6e57 100644 --- a/frontend/src/views/chat/components/RagPipelineProgress.style.test.mjs +++ b/frontend/src/views/chat/components/RagPipelineProgress.style.test.mjs @@ -21,7 +21,8 @@ test('rag pipeline persists and collapses after the answer arrives', () => { assert.match(source, /showCollapsedRoot/) assert.match(source, /tree-root-summary/) assert.match(source, /collapsedSummaryHtml/) - assert.match(source, /visible = computed\(\(\) => steps\.value\.length > 0 \|\| showPrePipelineWait\.value\)/) + assert.match(source, /hasThinking\.value/) + assert.match(source, /const visible = computed\([\s\S]*showPrePipelineWait\.value/) }) test('rag pipeline toggles expand and collapse from the root header', () => { @@ -42,10 +43,12 @@ test('rag pipeline embeds references in the timeline instead of a separate card' assert.match(source, /rag-ref-step[\s\S]*name="file-search"/) }) -test('rag pipeline keeps loading inside the timeline without duplicate dots', () => { +test('rag pipeline keeps loading inside the thinking step instead of orphan dots', () => { assert.match(source, /showPrePipelineWait/) - assert.match(source, /showActivityIndicator = computed\(\s*\(\) => steps\.value\.length > 0 && !hasAnswer\.value/) - assert.match(source, /showPrePipelineWait = computed/) + assert.match(source, /showThinkingStep/) + assert.match(source, /thinking-loading/) + assert.match(source, /hasThinkingEvent/) + assert.doesNotMatch(source, /showActivityIndicator/) }) test('rag pipeline places references before the done row', () => { @@ -55,6 +58,20 @@ test('rag pipeline places references before the done row', () => { assert.ok(refsIndex < doneIndex) }) +test('done row appears only after the full turn completes', () => { + assert.match(source, /const showDoneRow = computed\(\(\) => \{[\s\S]*hasAnswer\.value/) +}) + +test('rag pipeline renders model thinking inside the timeline before the done row', () => { + assert.match(source, /rag-thinking-step/) + assert.match(source, /showThinkingStep/) + assert.match(source, /name="lightbulb"/) + const doneIndex = source.indexOf('agent-step-done') + const thinkingIndex = source.indexOf('rag-thinking-step') + assert.ok(doneIndex > -1 && thinkingIndex > -1) + assert.ok(thinkingIndex < doneIndex) +}) + test('clickable timeline headers use pointer cursor', () => { assert.match(source, /\.tool-event \{[\s\S]*\.action-header \{[\s\S]*cursor: pointer/) assert.match(source, /\.action-header \{[\s\S]*&\.no-results \{[\s\S]*cursor: default/) diff --git a/frontend/src/views/chat/components/RagPipelineProgress.vue b/frontend/src/views/chat/components/RagPipelineProgress.vue index e66b77cf..2b031e1d 100644 --- a/frontend/src/views/chat/components/RagPipelineProgress.vue +++ b/frontend/src/views/chat/components/RagPipelineProgress.vue @@ -1,5 +1,5 @@ diff --git a/internal/application/service/chat_pipeline/common.go b/internal/application/service/chat_pipeline/common.go index ab726589..f87e1c02 100644 --- a/internal/application/service/chat_pipeline/common.go +++ b/internal/application/service/chat_pipeline/common.go @@ -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 } diff --git a/internal/application/service/session_qa_helpers.go b/internal/application/service/session_qa_helpers.go index d75de469..ff0168e8 100644 --- a/internal/application/service/session_qa_helpers.go +++ b/internal/application/service/session_qa_helpers.go @@ -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 diff --git a/internal/types/custom_agent.go b/internal/types/custom_agent.go index 10e7b078..9530b1b9 100644 --- a/internal/types/custom_agent.go +++ b/internal/types/custom_agent.go @@ -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 diff --git a/internal/types/custom_agent_test.go b/internal/types/custom_agent_test.go new file mode 100644 index 00000000..f6259888 --- /dev/null +++ b/internal/types/custom_agent_test.go @@ -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") + } +}