mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-26 00:46:52 +08:00
### What problem does this PR solve? Feat: Delete the agent and tool nodes downstream of the agent node #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -315,7 +315,11 @@ export function useAddNode(reactFlowInstance?: ReactFlowInstance<any, any>) {
|
||||
if (agentNode) {
|
||||
// Calculate the coordinates of child nodes to prevent newly added child nodes from covering other child nodes
|
||||
const allChildAgentNodeIds = edges
|
||||
.filter((x) => x.source === nodeId && x.sourceHandle === 'e')
|
||||
.filter(
|
||||
(x) =>
|
||||
x.source === nodeId &&
|
||||
x.sourceHandle === NodeHandleId.AgentBottom,
|
||||
)
|
||||
.map((x) => x.target);
|
||||
|
||||
const xAxises = nodes
|
||||
@ -334,8 +338,8 @@ export function useAddNode(reactFlowInstance?: ReactFlowInstance<any, any>) {
|
||||
addEdge({
|
||||
source: nodeId,
|
||||
target: newNode.id,
|
||||
sourceHandle: 'e',
|
||||
targetHandle: 'f',
|
||||
sourceHandle: NodeHandleId.AgentBottom,
|
||||
targetHandle: NodeHandleId.AgentTop,
|
||||
});
|
||||
}
|
||||
} else if (type === Operator.Tool) {
|
||||
|
||||
@ -1,14 +1,18 @@
|
||||
import { RAGFlowNodeType } from '@/interfaces/database/flow';
|
||||
import { OnBeforeDelete } from '@xyflow/react';
|
||||
import { Node, OnBeforeDelete } from '@xyflow/react';
|
||||
import { Operator } from '../constant';
|
||||
import useGraphStore from '../store';
|
||||
import { deleteAllDownstreamAgentsAndTool } from '../utils/delete-node';
|
||||
|
||||
const UndeletableNodes = [Operator.Begin, Operator.IterationStart];
|
||||
|
||||
export function useBeforeDelete() {
|
||||
const getOperatorTypeFromId = useGraphStore(
|
||||
(state) => state.getOperatorTypeFromId,
|
||||
);
|
||||
const { getOperatorTypeFromId, getNode } = useGraphStore((state) => state);
|
||||
|
||||
const agentPredicate = (node: Node) => {
|
||||
return getOperatorTypeFromId(node.id) === Operator.Agent;
|
||||
};
|
||||
|
||||
const handleBeforeDelete: OnBeforeDelete<RAGFlowNodeType> = async ({
|
||||
nodes, // Nodes to be deleted
|
||||
edges, // Edges to be deleted
|
||||
@ -47,6 +51,27 @@ export function useBeforeDelete() {
|
||||
return true;
|
||||
});
|
||||
|
||||
// Delete the agent and tool nodes downstream of the agent node
|
||||
if (nodes.some(agentPredicate)) {
|
||||
nodes.filter(agentPredicate).forEach((node) => {
|
||||
const { downstreamAgentAndToolEdges, downstreamAgentAndToolNodeIds } =
|
||||
deleteAllDownstreamAgentsAndTool(node.id, edges);
|
||||
|
||||
downstreamAgentAndToolNodeIds.forEach((nodeId) => {
|
||||
const currentNode = getNode(nodeId);
|
||||
if (toBeDeletedNodes.every((x) => x.id !== nodeId) && currentNode) {
|
||||
toBeDeletedNodes.push(currentNode);
|
||||
}
|
||||
});
|
||||
|
||||
downstreamAgentAndToolEdges.forEach((edge) => {
|
||||
if (toBeDeletedEdges.every((x) => x.id !== edge.id)) {
|
||||
toBeDeletedEdges.push(edge);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
}
|
||||
|
||||
return {
|
||||
nodes: toBeDeletedNodes,
|
||||
edges: toBeDeletedEdges,
|
||||
|
||||
Reference in New Issue
Block a user