From d874683ae4bc3446464fc406a9b4e5da8f78a8a7 Mon Sep 17 00:00:00 2001 From: TeslaZY Date: Fri, 15 Aug 2025 20:29:02 +0800 Subject: [PATCH] Fix the bug in enablePrologue under agent task mode (#9487) ### What problem does this PR solve? There is a problem with the implementation of the Agent begin-form: although the enablePrologue switch and the prologue input box are hidden in Task mode, these values are still saved in the form data. If the user first enables the opening and sets the content in Conversational mode, and then switches to Task mode, these values will still be saved and may be used in some scenarios. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- web/src/pages/agent/form/begin-form/index.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/web/src/pages/agent/form/begin-form/index.tsx b/web/src/pages/agent/form/begin-form/index.tsx index 97494d87c..db16a780f 100644 --- a/web/src/pages/agent/form/begin-form/index.tsx +++ b/web/src/pages/agent/form/begin-form/index.tsx @@ -15,7 +15,7 @@ import { FormTooltip } from '@/components/ui/tooltip'; import { buildSelectOptions } from '@/utils/component-util'; import { zodResolver } from '@hookform/resolvers/zod'; import { Plus } from 'lucide-react'; -import { memo } from 'react'; +import { memo, useEffect, useRef } from 'react'; import { useForm, useWatch } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { z } from 'zod'; @@ -70,6 +70,18 @@ function BeginForm({ node }: INextOperatorForm) { name: 'enablePrologue', }); + const previousModeRef = useRef(mode); + + useEffect(() => { + if ( + previousModeRef.current === AgentDialogueMode.Task && + mode === AgentDialogueMode.Conversational + ) { + form.setValue('enablePrologue', true); + } + previousModeRef.current = mode; + }, [mode, form]); + const { ok, currentRecord,