diff --git a/packages/global/core/workflow/runtime/constants.ts b/packages/global/core/workflow/runtime/constants.ts index accec3a32..10737d282 100644 --- a/packages/global/core/workflow/runtime/constants.ts +++ b/packages/global/core/workflow/runtime/constants.ts @@ -25,7 +25,8 @@ export enum DispatchNodeResponseKeyEnum { rewriteHistories = 'rewriteHistories', // If have the response, workflow histories will be rewrite interactive = 'INTERACTIVE', // is interactive - runTimes = 'runTimes' // run times + runTimes = 'runTimes', // run times + newVariables = 'newVariables' // new variables } export const needReplaceReferenceInputTypeList = [ diff --git a/packages/global/core/workflow/runtime/type.d.ts b/packages/global/core/workflow/runtime/type.d.ts index 43f643727..68334c1bc 100644 --- a/packages/global/core/workflow/runtime/type.d.ts +++ b/packages/global/core/workflow/runtime/type.d.ts @@ -196,6 +196,7 @@ export type DispatchNodeResultType = { [DispatchNodeResponseKeyEnum.assistantResponses]?: AIChatItemValueItemType[]; // Assistant response(Store to db) [DispatchNodeResponseKeyEnum.rewriteHistories]?: ChatItemType[]; [DispatchNodeResponseKeyEnum.runTimes]?: number; + [DispatchNodeResponseKeyEnum.newVariables]?: Record; } & T; /* Single node props */ diff --git a/packages/service/core/workflow/dispatch/agent/runTool/index.ts b/packages/service/core/workflow/dispatch/agent/runTool/index.ts index 22ca5e75d..d429b09f8 100644 --- a/packages/service/core/workflow/dispatch/agent/runTool/index.ts +++ b/packages/service/core/workflow/dispatch/agent/runTool/index.ts @@ -184,6 +184,7 @@ export const dispatchRunTools = async (props: DispatchToolModuleProps): Promise< // flat child tool response const childToolResponse = dispatchFlowResponse.map((item) => item.flowResponses).flat(); + const newVariables = dispatchFlowResponse[dispatchFlowResponse.length - 1]?.newVariables; // concat tool usage const totalPointsUsage = @@ -219,6 +220,7 @@ export const dispatchRunTools = async (props: DispatchToolModuleProps): Promise< tokens: totalTokens }, ...flatUsages - ] + ], + [DispatchNodeResponseKeyEnum.newVariables]: newVariables }; }; diff --git a/packages/service/core/workflow/dispatch/index.ts b/packages/service/core/workflow/dispatch/index.ts index 344602ba5..8bdf05373 100644 --- a/packages/service/core/workflow/dispatch/index.ts +++ b/packages/service/core/workflow/dispatch/index.ts @@ -555,6 +555,14 @@ export async function dispatchWorkFlow(data: Props): Promise => { const loopDetail: ChatHistoryItemResType[] = []; let assistantResponses: AIChatItemValueItemType[] = []; let totalPoints = 0; + let newVariables: Record = {}; for await (const item of loopInputArray) { const response = await dispatchWorkFlow({ @@ -72,6 +73,10 @@ export const dispatchLoop = async (props: Props): Promise => { assistantResponses.push(...response.assistantResponses); totalPoints = response.flowUsages.reduce((acc, usage) => acc + usage.totalPoints, 0); + newVariables = { + ...newVariables, + ...response.newVariables + }; } return { @@ -88,6 +93,7 @@ export const dispatchLoop = async (props: Props): Promise => { moduleName: name } ], - [NodeOutputKeyEnum.loopArray]: outputValueArr + [NodeOutputKeyEnum.loopArray]: outputValueArr, + [DispatchNodeResponseKeyEnum.newVariables]: newVariables }; };