MCPcopy
hub / github.com/FlowiseAI/Flowise / compileSeqAgentsGraph

Function compileSeqAgentsGraph

packages/server/src/utils/buildAgentGraph.ts:636–1058  ·  view source on GitHub ↗
(params: SeqAgentsGraphParams)

Source from the content-addressed store, hash-verified

634}
635
636const compileSeqAgentsGraph = async (params: SeqAgentsGraphParams) => {
637 const {
638 depthQueue,
639 agentflow,
640 appDataSource,
641 reactFlowNodes,
642 reactFlowEdges,
643 componentNodes,
644 options,
645 prependHistoryMessages = [],
646 chatHistory = [],
647 overrideConfig = {},
648 threadId,
649 action,
650 uploadedFilesContent
651 } = params
652
653 let question = params.question
654
655 let channels: ISeqAgentsState = {
656 messages: {
657 value: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y),
658 default: () => []
659 }
660 }
661
662 // Get state
663 const seqStateNode = reactFlowNodes.find((node: IReactFlowNode) => node.data.name === 'seqState')
664 if (seqStateNode) {
665 channels = {
666 ...seqStateNode.data.instance.node,
667 ...channels
668 }
669 }
670
671 let seqGraph = new StateGraph<any>({
672 //@ts-ignore
673 channels
674 })
675
676 /*** Validate Graph ***/
677 const startAgentNodes: IReactFlowNode[] = reactFlowNodes.filter((node: IReactFlowNode) => node.data.name === 'seqStart')
678 if (!startAgentNodes.length) throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, 'Start node not found')
679 if (startAgentNodes.length > 1)
680 throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, 'Graph should have only one start node')
681
682 const endAgentNodes: IReactFlowNode[] = reactFlowNodes.filter((node: IReactFlowNode) => node.data.name === 'seqEnd')
683 const loopNodes: IReactFlowNode[] = reactFlowNodes.filter((node: IReactFlowNode) => node.data.name === 'seqLoop')
684 if (!endAgentNodes.length && !loopNodes.length) {
685 throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, 'Graph should have at least one End/Loop node')
686 }
687 /*** End of Validation ***/
688
689 let flowNodeData
690 let conditionalEdges: Record<string, { nodes: Record<string, string>; func: any }> = {}
691 let interruptedRouteMapping: Record<string, Record<string, string>> = {}
692 let conditionalToolNodes: Record<string, { source: ISeqAgentNode; toolNodes: ISeqAgentNode[] }> = {}
693 let bindModel: Record<string, any> = {}

Callers 1

buildAgentGraphFunction · 0.85

Calls 13

getAPIOverrideConfigFunction · 0.90
getErrorMessageFunction · 0.90
getSortedDepthNodesFunction · 0.85
initiateNodeFunction · 0.85
prepareConditionalEdgesFunction · 0.85
prepareLLMToToolEdgesFunction · 0.85
createBindModelFunction · 0.85
additionalCallbacksFunction · 0.85
addNodeMethod · 0.80
checkForViolationsMethod · 0.45

Tested by

no test coverage detected