diff --git a/web/src/components/originui/select-with-search.tsx b/web/src/components/originui/select-with-search.tsx index 13125dd63..da0898be5 100644 --- a/web/src/components/originui/select-with-search.tsx +++ b/web/src/components/originui/select-with-search.tsx @@ -111,9 +111,7 @@ export const SelectWithSearch = forwardRef< > {value ? ( - - {selectLabel} - + {selectLabel} ) : ( Select value @@ -159,9 +157,7 @@ export const SelectWithSearch = forwardRef< disabled={option.disabled} onSelect={handleSelect} > - - {option.label} - + {option.label} {value === option.value && ( @@ -179,9 +175,7 @@ export const SelectWithSearch = forwardRef< disabled={group.disabled} onSelect={handleSelect} > - - {group.label} - + {group.label} {value === group.value && ( diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts index 7536452f7..79c299a6a 100644 --- a/web/src/locales/en.ts +++ b/web/src/locales/en.ts @@ -1317,6 +1317,8 @@ This delimiter is used to split the input text into several text pieces echo of file: 'File upload', integer: 'Number', boolean: 'Boolean', + goto: 'Fail Branch', + comment: 'Default Value', }, llmTools: { bad_calculator: { diff --git a/web/src/pages/agent/canvas/node/agent-node.tsx b/web/src/pages/agent/canvas/node/agent-node.tsx index dd61d2711..7435628bd 100644 --- a/web/src/pages/agent/canvas/node/agent-node.tsx +++ b/web/src/pages/agent/canvas/node/agent-node.tsx @@ -3,6 +3,7 @@ import { IAgentNode } from '@/interfaces/database/flow'; import { Handle, NodeProps, Position } from '@xyflow/react'; import { get } from 'lodash'; import { memo, useMemo } from 'react'; +import { useTranslation } from 'react-i18next'; import { AgentExceptionMethod, NodeHandleId } from '../../constant'; import useGraphStore from '../../store'; import { isBottomSubAgent } from '../../utils'; @@ -20,6 +21,7 @@ function InnerAgentNode({ selected, }: NodeProps) { const edges = useGraphStore((state) => state.edges); + const { t } = useTranslation(); const isHeadAgent = useMemo(() => { return !isBottomSubAgent(edges, id); @@ -87,9 +89,9 @@ function InnerAgentNode({ {(isGotoMethod || exceptionMethod === AgentExceptionMethod.Comment) && (
- Abnormal - - {isGotoMethod ? 'Exception branch' : 'Output default value'} + On Failure + + {t(`flow.${exceptionMethod}`)}
)} diff --git a/web/src/pages/agent/constant.tsx b/web/src/pages/agent/constant.tsx index fe3255d17..6f82c5d5d 100644 --- a/web/src/pages/agent/constant.tsx +++ b/web/src/pages/agent/constant.tsx @@ -645,15 +645,23 @@ export const initialAgentValues = { ...initialLlmBaseValues, description: '', user_prompt: '', - sys_prompt: ``, + sys_prompt: ` + You are {{agent_name}}, an AI assistant specialized in {{domain_or_task}}. + + + 1. Understand the user’s request. + 2. Decompose it into logical subtasks. + 3. Execute each subtask step by step, reasoning transparently. + 4. Validate accuracy and consistency. + 5. Summarize the final result clearly. +`, prompts: [{ role: PromptRole.User, content: `{${AgentGlobals.SysQuery}}` }], message_history_window_size: 12, max_retries: 3, delay_after_error: 1, visual_files_var: '', max_rounds: 5, - exception_method: null, - exception_comment: '', + exception_method: '', exception_goto: [], exception_default_value: '', tools: [], @@ -944,5 +952,4 @@ export enum VariableType { export enum AgentExceptionMethod { Comment = 'comment', Goto = 'goto', - Null = 'null', } diff --git a/web/src/pages/agent/form/agent-form/index.tsx b/web/src/pages/agent/form/agent-form/index.tsx index c12b992c9..72cb6200b 100644 --- a/web/src/pages/agent/form/agent-form/index.tsx +++ b/web/src/pages/agent/form/agent-form/index.tsx @@ -6,6 +6,7 @@ import { } from '@/components/large-model-form-field'; import { LlmSettingSchema } from '@/components/llm-setting-items/next'; import { MessageHistoryWindowSizeFormField } from '@/components/message-history-window-size-item'; +import { SelectWithSearch } from '@/components/originui/select-with-search'; import { Form, FormControl, @@ -14,10 +15,8 @@ import { FormLabel, } from '@/components/ui/form'; import { Input, NumberInput } from '@/components/ui/input'; -import { RAGFlowSelect } from '@/components/ui/select'; import { LlmModelType } from '@/constants/knowledge'; import { useFindLlmByUuid } from '@/hooks/use-llm-request'; -import { buildOptions } from '@/utils/form'; import { zodResolver } from '@hookform/resolvers/zod'; import { memo, useEffect, useMemo } from 'react'; import { useForm, useWatch } from 'react-hook-form'; @@ -42,8 +41,6 @@ import { AgentTools, Agents } from './agent-tools'; import { useValues } from './use-values'; import { useWatchFormChange } from './use-watch-change'; -const exceptionMethodOptions = buildOptions(AgentExceptionMethod); - const FormSchema = z.object({ sys_prompt: z.string(), description: z.string().optional(), @@ -70,8 +67,7 @@ const FormSchema = z.object({ delay_after_error: z.coerce.number().optional(), visual_files_var: z.string().optional(), max_rounds: z.coerce.number().optional(), - exception_method: z.string().nullable(), - exception_comment: z.string().optional(), + exception_method: z.string().optional(), exception_goto: z.array(z.string()).optional(), exception_default_value: z.string().optional(), ...LargeModelFilterFormSchema, @@ -87,6 +83,13 @@ function AgentForm({ node }: INextOperatorForm) { const defaultValues = useValues(node); + const ExceptionMethodOptions = Object.values(AgentExceptionMethod).map( + (x) => ({ + label: t(`flow.${x}`), + value: x, + }), + ); + const isSubAgent = useMemo(() => { return isBottomSubAgent(edges, node?.id); }, [edges, node?.id]); @@ -224,38 +227,29 @@ function AgentForm({ node }: INextOperatorForm) { Exception method - )} /> - ( - - Exception default value - - - - - )} - /> - ( - - Exception comment - - - - - )} - /> + {exceptionMethod === AgentExceptionMethod.Comment && ( + ( + + Exception default value + + + + + )} + /> + )} 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 21addb892..b2d61dc9f 100644 --- a/web/src/pages/agent/form/agent-form/use-values.ts +++ b/web/src/pages/agent/form/agent-form/use-values.ts @@ -2,7 +2,7 @@ import { useFetchModelId } from '@/hooks/logic-hooks'; import { RAGFlowNodeType } from '@/interfaces/database/flow'; import { get, isEmpty } from 'lodash'; import { useMemo } from 'react'; -import { AgentExceptionMethod, initialAgentValues } from '../../constant'; +import { initialAgentValues } from '../../constant'; export function useValues(node?: RAGFlowNodeType) { const llmId = useFetchModelId(); @@ -26,10 +26,6 @@ export function useValues(node?: RAGFlowNodeType) { return { ...formData, prompts: get(formData, 'prompts.0.content', ''), - exception_method: - formData.exception_method === null - ? AgentExceptionMethod.Null - : formData.exception_method, }; }, [defaultValues, node?.data?.form]); diff --git a/web/src/pages/agent/form/agent-form/use-watch-change.ts b/web/src/pages/agent/form/agent-form/use-watch-change.ts index 97c2cb437..98b0ecf31 100644 --- a/web/src/pages/agent/form/agent-form/use-watch-change.ts +++ b/web/src/pages/agent/form/agent-form/use-watch-change.ts @@ -1,6 +1,6 @@ import { useEffect } from 'react'; import { UseFormReturn, useWatch } from 'react-hook-form'; -import { AgentExceptionMethod, PromptRole } from '../../constant'; +import { PromptRole } from '../../constant'; import useGraphStore from '../../store'; export function useWatchFormChange(id?: string, form?: UseFormReturn) { @@ -14,10 +14,6 @@ export function useWatchFormChange(id?: string, form?: UseFormReturn) { let nextValues: any = { ...values, prompts: [{ role: PromptRole.User, content: values.prompts }], - exception_method: - values.exception_method === AgentExceptionMethod.Null - ? null - : values.exception_method, }; updateNodeForm(id, nextValues);