(params: SeqAgentsGraphParams)
| 634 | } |
| 635 | |
| 636 | const 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> = {} |
no test coverage detected