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)
This commit is contained in:
balibabu
2025-09-09 21:18:24 +08:00
committed by GitHub
parent 1a904edd94
commit 07a83f93d5
4 changed files with 32 additions and 7 deletions

View File

@ -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) => ({

View File

@ -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) {
</${capitalTag}>`;
}
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 },

View File

@ -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[],

View File

@ -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) {
<MoreButton></MoreButton>
</AgentDropdown>
}
sharedBadge={<SharedBadge>{data.nickname}</SharedBadge>}
onClick={navigateToAgent(data?.id)}
/>
);