From 07a83f93d5335a99afcc5256303620b5fca4c7c7 Mon Sep 17 00:00:00 2001 From: balibabu Date: Tue, 9 Sep 2025 21:18:24 +0800 Subject: [PATCH] Feat: The prompt words "plan" are displayed only when the agent operator has sub-agent operators or sub-tool operators. #10000 (#10001) ### What problem does this PR solve? Feat: The prompt words "plan" are displayed only when the agent operator has sub-agent operators or sub-tool operators. . #10000 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- web/src/pages/agent/form/agent-form/index.tsx | 2 +- .../agent-form/use-build-prompt-options.ts | 25 ++++++++++++++----- web/src/pages/agent/utils.ts | 10 ++++++++ web/src/pages/agents/agent-card.tsx | 2 ++ 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/web/src/pages/agent/form/agent-form/index.tsx b/web/src/pages/agent/form/agent-form/index.tsx index 8692ab96e..f761e6d3c 100644 --- a/web/src/pages/agent/form/agent-form/index.tsx +++ b/web/src/pages/agent/form/agent-form/index.tsx @@ -86,7 +86,7 @@ function AgentForm({ node }: INextOperatorForm) { const defaultValues = useValues(node); - const { extraOptions } = useBuildPromptExtraPromptOptions(); + const { extraOptions } = useBuildPromptExtraPromptOptions(edges, node?.id); const ExceptionMethodOptions = Object.values(AgentExceptionMethod).map( (x) => ({ diff --git a/web/src/pages/agent/form/agent-form/use-build-prompt-options.ts b/web/src/pages/agent/form/agent-form/use-build-prompt-options.ts index 9c34ce77c..5a0f04abb 100644 --- a/web/src/pages/agent/form/agent-form/use-build-prompt-options.ts +++ b/web/src/pages/agent/form/agent-form/use-build-prompt-options.ts @@ -1,6 +1,8 @@ import { useFetchPrompt } from '@/hooks/use-agent-request'; +import { Edge } from '@xyflow/react'; import { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; +import { hasSubAgentOrTool } from '../../utils'; export const PromptIdentity = 'RAGFlow-Prompt'; @@ -11,16 +13,27 @@ function wrapPromptWithTag(text: string, tag: string) { `; } -export function useBuildPromptExtraPromptOptions() { +export function useBuildPromptExtraPromptOptions( + edges: Edge[], + nodeId?: string, +) { const { data: prompts } = useFetchPrompt(); const { t } = useTranslation(); + const has = hasSubAgentOrTool(edges, nodeId); const options = useMemo(() => { - return Object.entries(prompts || {}).map(([key, value]) => ({ - label: key, - value: wrapPromptWithTag(value, key), - })); - }, [prompts]); + return Object.entries(prompts || {}) + .map(([key, value]) => ({ + label: key, + value: wrapPromptWithTag(value, key), + })) + .filter((x) => { + if (!has) { + return x.label === 'citation_guidelines'; + } + return true; + }); + }, [has, prompts]); const extraOptions = [ { label: PromptIdentity, title: t('flow.frameworkPrompts'), options }, diff --git a/web/src/pages/agent/utils.ts b/web/src/pages/agent/utils.ts index c7d60dfd2..c36b1b855 100644 --- a/web/src/pages/agent/utils.ts +++ b/web/src/pages/agent/utils.ts @@ -152,6 +152,16 @@ export function isBottomSubAgent(edges: Edge[], nodeId?: string) { return !!edge; } +export function hasSubAgentOrTool(edges: Edge[], nodeId?: string) { + const edge = edges.find( + (x) => + x.source === nodeId && + (x.sourceHandle === NodeHandleId.Tool || + x.sourceHandle === NodeHandleId.AgentBottom), + ); + return !!edge; +} + // construct a dsl based on the node information of the graph export const buildDslComponentsByGraph = ( nodes: RAGFlowNodeType[], diff --git a/web/src/pages/agents/agent-card.tsx b/web/src/pages/agents/agent-card.tsx index 831575c39..e1aa20ac4 100644 --- a/web/src/pages/agents/agent-card.tsx +++ b/web/src/pages/agents/agent-card.tsx @@ -1,5 +1,6 @@ import { HomeCard } from '@/components/home-card'; import { MoreButton } from '@/components/more-button'; +import { SharedBadge } from '@/components/shared-badge'; import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks'; import { IFlow } from '@/interfaces/database/agent'; import { AgentDropdown } from './agent-dropdown'; @@ -20,6 +21,7 @@ export function AgentCard({ data, showAgentRenameModal }: DatasetCardProps) { } + sharedBadge={{data.nickname}} onClick={navigateToAgent(data?.id)} /> );