Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Infiniflow Ragflow Agent Utils

From Leeroopedia
Knowledge Sources
Domains Frontend, Agent_System, Graph_Algorithms
Last Updated 2026-02-12 06:00 GMT

Overview

Utility functions for agent canvas graph operations including node/edge manipulation, validation, serialization, and workflow export.

Description

This module provides the core utility functions that power the agent canvas graph system. It includes functions for building DSL components from the visual graph representation (`buildDslComponentsByGraph`), constructing downstream/upstream node relationships, serializing/deserializing categorize operator data, managing node positions and duplication, validating edge connections, generating unique node names with incrementing indices, and converting between the visual graph format and the backend DSL format. The module also provides helper functions for agent-specific operations like detecting sub-agents, determining tool connections, and handling exception goto edges.

Usage

Used extensively by the agent canvas store, hooks, and form components whenever graph state needs to be transformed, validated, or serialized for API communication. Central to the save/load workflow and all node/edge manipulation operations.

Code Reference

Source Location

Signature

export function isBottomSubAgent(edges: Edge[], nodeId?: string): boolean;
export function hasSubAgentOrTool(edges: Edge[], nodeId?: string): boolean;
export function hasSubAgent(edges: Edge[], nodeId?: string): boolean;
export function transformArrayToObject(list: Array<any>, key: string): Record<string, any>;
export const buildDslComponentsByGraph: (
  nodes: Node[],
  edges: Edge[],
  agentForm: IAgentForm
) => DSLComponents;
export const buildDslGlobalVariables: (form: any) => GlobalVariableType[];
export const receiveMessageError: (res: any) => boolean;
export const replaceIdWithText: (output: unknown, getNameById: Function) => unknown;
export const isEdgeEqual: (previous: Edge, current: Edge) => boolean;
export const buildNewPositionMap: (nodes: Node[]) => Record<string, IPosition>;
export const isKeysEqual: (currentKeys: string[], previousKeys: string[]) => boolean;
export const getOperatorIndex: (handleTitle: string) => number;
export const generateSwitchHandleText: (idx: number) => string;
export const getNodeDragHandle: (nodeType?: string) => string;
export const generateNodeNamesWithIncreasingIndex: (
  name: string,
  nodes: Node[]
) => string;
export const duplicateNodeForm: (nodeData?: RAGFlowNodeType['data']) => any;
export const getDrawerWidth: () => number;
export const needsSingleStepDebugging: (label: string) => boolean;
export function showCopyIcon(label: string): boolean;
export function getRelativePositionToIterationNode(
  iterationNode: RAGFlowNodeType,
  position: XYPosition
): XYPosition;
export const generateDuplicateNode: (node: RAGFlowNodeType, name: string) => RAGFlowNodeType;
export function convertToStringArray(arr: any[]): string[];
export function convertToObjectArray<T>(arr: any[]): Array<{ value: T }>;
export const buildCategorizeListFromObject: (obj: Record<string, ICategorizeItemResult>) => ICategorizeItem[];
export const buildCategorizeObjectFromList: (list: Array<ICategorizeItem>) => Record<string, ICategorizeItemResult>;
export function getAgentNodeTools(agentNode?: RAGFlowNodeType): string[];
export function getAgentNodeMCP(agentNode?: RAGFlowNodeType): string[];
export function mapEdgeMouseEvent(handler: Function): Function;
export function buildBeginQueryWithObject(obj: Record<string, any>): BeginQuery[];
export function getArrayElementType(type: string): string;
export function buildConversationVariableSelectOptions(): Array<{ value: string; label: string }>;
export const InputModeOptions: Array<{ value: string; label: string }>;

Import

import {
  buildDslComponentsByGraph,
  buildCategorizeObjectFromList,
  replaceIdWithText,
  generateNodeNamesWithIncreasingIndex,
  duplicateNodeForm,
} from '@/pages/agent/utils';

I/O Contract

Inputs

Name Type Required Description
nodes Node[] Yes ReactFlow node array representing the current graph state.
edges Edge[] Yes ReactFlow edge array representing connections between nodes.
agentForm IAgentForm No Agent-level form configuration for DSL building.
nodeId string No Specific node identifier for targeted operations.

Outputs

Name Type Description
DSLComponents DSLComponents Serialized graph components ready for backend API consumption.
GlobalVariableType[] GlobalVariableType[] Extracted global variables from the agent form.
boolean boolean Various boolean checks (cycle detection, edge equality, sub-agent detection).
string string Generated node names, handle text, drag handle selectors.

Usage Examples

import {
  buildDslComponentsByGraph,
  generateNodeNamesWithIncreasingIndex,
  isBottomSubAgent,
} from '@/pages/agent/utils';

// Serialize graph to DSL for saving
const dslComponents = buildDslComponentsByGraph(nodes, edges, agentForm);

// Generate a unique name for a new Retrieval node
const name = generateNodeNamesWithIncreasingIndex('Retrieval', nodes);
// Returns "Retrieval 2" if "Retrieval 1" already exists

// Check if a node is a bottom-level sub-agent
const isBottom = isBottomSubAgent(edges, nodeId);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment