From bbe6ed3b90657eda7ce187455da44c0422d6919d Mon Sep 17 00:00:00 2001 From: balibabu Date: Wed, 10 Sep 2025 15:55:59 +0800 Subject: [PATCH] Fix: Fixed the issue where newly added tool operators would disappear after editing the form #10013 (#10016) ### What problem does this PR solve? Fix: Fixed the issue where newly added tool operators would disappear after editing the form #10013 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- web/src/pages/agent/form/agent-form/index.tsx | 7 ------- web/src/pages/agent/form/agent-form/use-values.ts | 12 +++++++++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/web/src/pages/agent/form/agent-form/index.tsx b/web/src/pages/agent/form/agent-form/index.tsx index 5aba35826..65fb364b7 100644 --- a/web/src/pages/agent/form/agent-form/index.tsx +++ b/web/src/pages/agent/form/agent-form/index.tsx @@ -57,13 +57,6 @@ const FormSchema = z.object({ // ) // .optional(), message_history_window_size: z.coerce.number(), - tools: z - .array( - z.object({ - component_name: z.string(), - }), - ) - .optional(), ...LlmSettingSchema, max_retries: z.coerce.number(), delay_after_error: z.coerce.number().optional(), diff --git a/web/src/pages/agent/form/agent-form/use-values.ts b/web/src/pages/agent/form/agent-form/use-values.ts index b2d61dc9f..f8747e4b4 100644 --- a/web/src/pages/agent/form/agent-form/use-values.ts +++ b/web/src/pages/agent/form/agent-form/use-values.ts @@ -1,15 +1,21 @@ import { useFetchModelId } from '@/hooks/logic-hooks'; import { RAGFlowNodeType } from '@/interfaces/database/flow'; -import { get, isEmpty } from 'lodash'; +import { get, isEmpty, omit } from 'lodash'; import { useMemo } from 'react'; import { initialAgentValues } from '../../constant'; +// You need to exclude the mcp and tools fields that are not in the form, +// otherwise the form data update will reset the tools or mcp data to an array +function omitToolsAndMcp(values: Record) { + return omit(values, ['mcp', 'tools']); +} + export function useValues(node?: RAGFlowNodeType) { const llmId = useFetchModelId(); const defaultValues = useMemo( () => ({ - ...initialAgentValues, + ...omitToolsAndMcp(initialAgentValues), llm_id: llmId, prompts: '', }), @@ -24,7 +30,7 @@ export function useValues(node?: RAGFlowNodeType) { } return { - ...formData, + ...omitToolsAndMcp(formData), prompts: get(formData, 'prompts.0.content', ''), }; }, [defaultValues, node?.data?.form]);