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

Function executeAgentFlow

packages/server/src/utils/buildAgentflow.ts:1541–2464  ·  view source on GitHub ↗
({
    componentNodes,
    incomingInput,
    chatflow,
    chatId,
    evaluationRunId,
    appDataSource,
    telemetry,
    usageCacheManager,
    cachePool,
    sseStreamer,
    baseURL,
    isInternal,
    uploadedFilesContent,
    fileUploads,
    signal: abortController,
    isRecursive = false,
    parentExecutionId,
    iterationContext,
    isTool = false,
    chatType,
    orgId,
    workspaceId,
    subscriptionId,
    productId
}: IExecuteAgentFlowParams)

Source from the content-addressed store, hash-verified

1539 * Function to traverse the flow graph and execute the nodes
1540 */
1541export const executeAgentFlow = async ({
1542 componentNodes,
1543 incomingInput,
1544 chatflow,
1545 chatId,
1546 evaluationRunId,
1547 appDataSource,
1548 telemetry,
1549 usageCacheManager,
1550 cachePool,
1551 sseStreamer,
1552 baseURL,
1553 isInternal,
1554 uploadedFilesContent,
1555 fileUploads,
1556 signal: abortController,
1557 isRecursive = false,
1558 parentExecutionId,
1559 iterationContext,
1560 isTool = false,
1561 chatType,
1562 orgId,
1563 workspaceId,
1564 subscriptionId,
1565 productId
1566}: IExecuteAgentFlowParams) => {
1567 logger.debug('\n🚀 Starting flow execution')
1568
1569 const question = incomingInput.question
1570 const form = incomingInput.form
1571 let overrideConfig = incomingInput.overrideConfig ?? {}
1572 const uploads = incomingInput.uploads
1573 const userMessageDateTime = new Date()
1574 const chatflowid = chatflow.id
1575 const sessionId = iterationContext?.sessionId || overrideConfig.sessionId || chatId
1576 const humanInput: IHumanInput | undefined = incomingInput.humanInput
1577
1578 // Validate history schema if provided
1579 if (incomingInput.history && incomingInput.history.length > 0) {
1580 if (!validateHistorySchema(incomingInput.history)) {
1581 throw new Error(
1582 'Invalid history format. Each history item must have: ' + '{ role: "apiMessage" | "userMessage", content: string }'
1583 )
1584 }
1585 }
1586
1587 const prependedChatHistory = incomingInput.history ?? []
1588 const apiMessageId = uuidv4()
1589
1590 /*** Get chatflows and prepare data ***/
1591 const flowData = chatflow.flowData
1592 const parsedFlowData: IReactFlowObject = JSON.parse(flowData)
1593 const nodes = (parsedFlowData.nodes || []).filter((node) => node.data.name !== 'stickyNoteAgentflow')
1594 const edges = parsedFlowData.edges
1595 const { graph, nodeDependencies } = constructGraphs(nodes, edges)
1596 const { graph: reversedGraph } = constructGraphs(nodes, edges, { isReversed: true })
1597 const startNode = nodes.find((node) => node.data.name === 'startAgentflow')
1598 const startInputType = startNode?.data.inputs?.startInputType as StartInputType | undefined

Callers 3

executeFlowFunction · 0.90
_executeAgentflowFunction · 0.90
executeNodeFunction · 0.85

Calls 15

constructGraphsFunction · 0.90
getAPIOverrideConfigFunction · 0.90
getErrorMessageFunction · 0.90
utilAddChatMessageFunction · 0.90
shouldAutoPlayTTSFunction · 0.90
validateHistorySchemaFunction · 0.85
parseFormStringToJsonFunction · 0.85
resolveWebhookRefsFunction · 0.85
getStartingNodeFunction · 0.85
addExecutionFunction · 0.85

Tested by

no test coverage detected