(params: MultiAgentsGraphParams)
| 427 | } |
| 428 | |
| 429 | const compileMultiAgentsGraph = async (params: MultiAgentsGraphParams) => { |
| 430 | const { |
| 431 | agentflow, |
| 432 | appDataSource, |
| 433 | mapNameToLabel, |
| 434 | reactFlowNodes, |
| 435 | workerNodeIds, |
| 436 | componentNodes, |
| 437 | options, |
| 438 | prependHistoryMessages = [], |
| 439 | chatHistory = [], |
| 440 | overrideConfig = {}, |
| 441 | threadId, |
| 442 | summarization = false, |
| 443 | uploadedFilesContent |
| 444 | } = params |
| 445 | |
| 446 | let question = params.question |
| 447 | |
| 448 | const channels: ITeamState = { |
| 449 | messages: { |
| 450 | value: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y), |
| 451 | default: () => [] |
| 452 | }, |
| 453 | next: 'initialState', |
| 454 | instructions: "Solve the user's request.", |
| 455 | team_members: [] |
| 456 | } |
| 457 | |
| 458 | if (summarization) channels.summarization = 'summarize' |
| 459 | |
| 460 | const workflowGraph = new StateGraph<ITeamState>({ |
| 461 | //@ts-ignore |
| 462 | channels |
| 463 | }) |
| 464 | |
| 465 | const workerNodes = reactFlowNodes.filter((node) => workerNodeIds.includes(node.data.id)) |
| 466 | |
| 467 | /*** Get API Config ***/ |
| 468 | const availableVariables = await appDataSource.getRepository(Variable).findBy(getWorkspaceSearchOptions(agentflow.workspaceId)) |
| 469 | const { nodeOverrides, variableOverrides, apiOverrideStatus } = getAPIOverrideConfig(agentflow) |
| 470 | |
| 471 | let supervisorWorkers: { [key: string]: IMultiAgentNode[] } = {} |
| 472 | |
| 473 | // Init worker nodes |
| 474 | for (const workerNode of workerNodes) { |
| 475 | const nodeInstanceFilePath = componentNodes[workerNode.data.name].filePath as string |
| 476 | const nodeModule = await import(nodeInstanceFilePath) |
| 477 | const newNodeInstance = new nodeModule.nodeClass() |
| 478 | |
| 479 | let flowNodeData = cloneDeep(workerNode.data) |
| 480 | if (overrideConfig && apiOverrideStatus) |
| 481 | flowNodeData = replaceInputsWithConfig(flowNodeData, overrideConfig, nodeOverrides, variableOverrides) |
| 482 | flowNodeData = await resolveVariables( |
| 483 | flowNodeData, |
| 484 | reactFlowNodes, |
| 485 | question, |
| 486 | chatHistory, |
no test coverage detected