Przeglądaj źródła

Feat: Insert the node data of the bottom subagent into the tool array of the head agent #3221 (#8471)

### What problem does this PR solve?

Feat: Insert the node data of the bottom subagent into the tool array of
the head agent #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
tags/v0.20.0
balibabu 4 miesięcy temu
rodzic
commit
ece27c66e9
No account linked to committer's email address

+ 3
- 5
web/src/pages/agent/form/agent-form/index.tsx Wyświetl plik

import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { z } from 'zod'; import { z } from 'zod';
import { NodeHandleId, Operator, initialAgentValues } from '../../constant';
import { Operator, initialAgentValues } from '../../constant';
import { AgentInstanceContext } from '../../context'; import { AgentInstanceContext } from '../../context';
import { INextOperatorForm } from '../../interface'; import { INextOperatorForm } from '../../interface';
import useGraphStore from '../../store'; import useGraphStore from '../../store';
import { isBottomSubAgent } from '../../utils';
import { Output } from '../components/output'; import { Output } from '../components/output';
import { PromptEditor } from '../components/prompt-editor'; import { PromptEditor } from '../components/prompt-editor';
import { AgentTools } from './agent-tools'; import { AgentTools } from './agent-tools';
const defaultValues = useValues(node); const defaultValues = useValues(node);


const isSubAgent = useMemo(() => { const isSubAgent = useMemo(() => {
const edge = edges.find(
(x) => x.target === node?.id && x.targetHandle === NodeHandleId.AgentTop,
);
return !!edge;
return isBottomSubAgent(edges, node?.id);
}, [edges, node?.id]); }, [edges, node?.id]);


const outputList = useMemo(() => { const outputList = useMemo(() => {

+ 45
- 7
web/src/pages/agent/utils.ts Wyświetl plik

import { import {
CategorizeAnchorPointPositions, CategorizeAnchorPointPositions,
NoDebugOperatorsList, NoDebugOperatorsList,
NodeHandleId,
NodeMap, NodeMap,
Operator, Operator,
} from './constant'; } from './constant';
.filter((y) => { .filter((y) => {
const node = nodes.find((x) => x.id === nodeId); const node = nodes.find((x) => x.id === nodeId);
let isNotUpstreamTool = true; let isNotUpstreamTool = true;
let isNotUpstreamAgent = true;
if (isBuildDownstream && node?.data.label === Operator.Agent) { if (isBuildDownstream && node?.data.label === Operator.Agent) {
isNotUpstreamTool = !y.target.startsWith(Operator.Tool); // Exclude the tool operator downstream of the agent operator
// Exclude the tool operator downstream of the agent operator
isNotUpstreamTool = !y.target.startsWith(Operator.Tool);
// Exclude the agent operator downstream of the agent operator
isNotUpstreamAgent = !(
y.target.startsWith(Operator.Agent) &&
y.targetHandle === NodeHandleId.AgentTop
);
} }
return ( return (
y[isBuildDownstream ? 'source' : 'target'] === nodeId && y[isBuildDownstream ? 'source' : 'target'] === nodeId &&
isNotUpstreamTool
isNotUpstreamTool &&
isNotUpstreamAgent
); );
}) })
.map((y) => y[isBuildDownstream ? 'target' : 'source']); .map((y) => y[isBuildDownstream ? 'target' : 'source']);
// return values; // return values;
// }); // });


function buildAgentTools(edges: Edge[], nodes: Node[], nodeId: string) {
const node = nodes.find((x) => x.id === nodeId);
const params = { ...(node?.data.form ?? {}) };
if (node && node.data.label === Operator.Agent) {
const bottomSubAgentEdges = edges.filter(
(x) => x.source === nodeId && x.sourceHandle === NodeHandleId.AgentBottom,
);

(params as IAgentForm).tools = (params as IAgentForm).tools.concat(
bottomSubAgentEdges.map((x) => {
const formData = buildAgentTools(edges, nodes, x.target);

return { component_name: Operator.Agent, params: { ...formData } };
}),
);
}
return params;
}

const buildOperatorParams = (operatorName: string) => const buildOperatorParams = (operatorName: string) =>
pipe( pipe(
removeUselessDataInTheOperator(operatorName), removeUselessDataInTheOperator(operatorName),


const ExcludeOperators = [Operator.Note, Operator.Tool]; const ExcludeOperators = [Operator.Note, Operator.Tool];


export function isBottomSubAgent(edges: Edge[], nodeId?: string) {
const edge = edges.find(
(x) => x.target === nodeId && x.targetHandle === NodeHandleId.AgentTop,
);
return !!edge;
}

// construct a dsl based on the node information of the graph // construct a dsl based on the node information of the graph
export const buildDslComponentsByGraph = ( export const buildDslComponentsByGraph = (
nodes: RAGFlowNodeType[], nodes: RAGFlowNodeType[],
const components: DSLComponents = {}; const components: DSLComponents = {};


nodes nodes
?.filter((x) => !ExcludeOperators.some((y) => y === x.data.label))
?.filter(
(x) =>
!ExcludeOperators.some((y) => y === x.data.label) &&
!isBottomSubAgent(edges, x.id),
)
.forEach((x) => { .forEach((x) => {
const id = x.id; const id = x.id;
const operatorName = x.data.label; const operatorName = x.data.label;

const params = buildAgentTools(edges, nodes, id);
components[id] = { components[id] = {
obj: { obj: {
...(oldDslComponents[id]?.obj ?? {}), ...(oldDslComponents[id]?.obj ?? {}),
component_name: operatorName, component_name: operatorName,
params:
buildOperatorParams(operatorName)(
x.data.form as Record<string, unknown>,
) ?? {},
params: buildOperatorParams(operatorName)(params) ?? {},
}, },
downstream: buildComponentDownstreamOrUpstream(edges, id, true, nodes), downstream: buildComponentDownstreamOrUpstream(edges, id, true, nodes),
upstream: buildComponentDownstreamOrUpstream(edges, id, false, nodes), upstream: buildComponentDownstreamOrUpstream(edges, id, false, nodes),

Ładowanie…
Anuluj
Zapisz