fix:variable not update in nested workflow runs (#2830)

This commit is contained in:
heheer
2024-09-28 13:59:35 +08:00
committed by GitHub
parent d95f71e9e3
commit f7a8203454
5 changed files with 21 additions and 3 deletions

View File

@@ -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 = [

View File

@@ -196,6 +196,7 @@ export type DispatchNodeResultType<T = {}> = {
[DispatchNodeResponseKeyEnum.assistantResponses]?: AIChatItemValueItemType[]; // Assistant response(Store to db)
[DispatchNodeResponseKeyEnum.rewriteHistories]?: ChatItemType[];
[DispatchNodeResponseKeyEnum.runTimes]?: number;
[DispatchNodeResponseKeyEnum.newVariables]?: Record<string, any>;
} & T;
/* Single node props */

View File

@@ -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
};
};

View File

@@ -555,6 +555,14 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
dispatchRes[item.key] = valueTypeFormat(item.defaultValue, item.valueType);
});
// Update new variables
if (dispatchRes[DispatchNodeResponseKeyEnum.newVariables]) {
variables = {
...variables,
...dispatchRes[DispatchNodeResponseKeyEnum.newVariables]
};
}
return {
node,
runStatus: 'run',

View File

@@ -38,6 +38,7 @@ export const dispatchLoop = async (props: Props): Promise<Response> => {
const loopDetail: ChatHistoryItemResType[] = [];
let assistantResponses: AIChatItemValueItemType[] = [];
let totalPoints = 0;
let newVariables: Record<string, any> = {};
for await (const item of loopInputArray) {
const response = await dispatchWorkFlow({
@@ -72,6 +73,10 @@ export const dispatchLoop = async (props: Props): Promise<Response> => {
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<Response> => {
moduleName: name
}
],
[NodeOutputKeyEnum.loopArray]: outputValueArr
[NodeOutputKeyEnum.loopArray]: outputValueArr,
[DispatchNodeResponseKeyEnum.newVariables]: newVariables
};
};