fix(AI Agent Node): Fix tool calling when tools run in a loop (#15250)

Co-authored-by: JP van Oosten <jp@n8n.io>
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Yiorgis Gozadinos
2025-05-13 14:40:07 +02:00
committed by GitHub
parent 52f27a76ac
commit cd1d6c9dfc
8 changed files with 113 additions and 15 deletions

View File

@@ -60,17 +60,21 @@ export class WorkflowToolService {
// Creates the tool based on the provided parameters
async createTool({
ctx,
name,
description,
itemIndex,
}: {
ctx: ISupplyDataFunctions;
name: string;
description: string;
itemIndex: number;
}): Promise<DynamicTool | DynamicStructuredTool> {
let runIndex = 0;
// Handler for the tool execution, will be called when the tool is executed
// This function will execute the sub-workflow and return the response
// We get the runIndex from the context to handle multiple executions
// of the same tool when the tool is used in a loop or in a parallel execution.
let runIndex: number = ctx.getNextRunIndex();
const toolHandler = async (
query: string | IDataObject,
runManager?: CallbackManagerForToolRun,