mirror of
https://github.com/n8n-io/n8n.git
synced 2026-09-24 23:22:38 +08:00
fix(AI Agent Node): Handle continueOnFail for maxIterations correctly (#23218)
This commit is contained in:
@@ -7,7 +7,7 @@ import type {
|
||||
EngineResponse,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { buildExecutionContext, executeBatch, checkMaxIterations } from './helpers';
|
||||
import { buildExecutionContext, executeBatch } from './helpers';
|
||||
import type { RequestResponseMetadata } from './types';
|
||||
|
||||
/* -----------------------------------------------------------
|
||||
@@ -31,12 +31,9 @@ export async function toolsAgentExecute(
|
||||
): Promise<INodeExecutionData[][] | EngineRequest<RequestResponseMetadata>> {
|
||||
this.logger.debug('Executing Tools Agent V3');
|
||||
|
||||
// Check max iterations if this is a continuation of a previous execution
|
||||
const maxIterations = this.getNodeParameter('options.maxIterations', 0, 10) as number;
|
||||
checkMaxIterations(response, maxIterations, this.getNode());
|
||||
let request: EngineRequest<RequestResponseMetadata> | undefined = undefined;
|
||||
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
let request: EngineRequest<RequestResponseMetadata> | undefined = undefined;
|
||||
|
||||
// Build execution context with shared configuration
|
||||
const executionContext = await buildExecutionContext(this);
|
||||
|
||||
+8
-1
@@ -1,7 +1,7 @@
|
||||
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
||||
import type { AgentRunnableSequence } from '@langchain/classic/agents';
|
||||
import type { BaseChatMemory } from '@langchain/classic/memory';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
import { assertParamIsNumber, NodeOperationError } from 'n8n-workflow';
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
ISupplyDataFunctions,
|
||||
@@ -17,6 +17,7 @@ import { createAgentSequence } from './createAgentSequence';
|
||||
import { finalizeResult } from './finalizeResult';
|
||||
import { prepareItemContext } from './prepareItemContext';
|
||||
import { runAgent } from './runAgent';
|
||||
import { checkMaxIterations } from './checkMaxIterations';
|
||||
|
||||
type BatchResult = AgentResult | EngineRequest<RequestResponseMetadata>;
|
||||
/**
|
||||
@@ -47,9 +48,15 @@ export async function executeBatch(
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
let request: EngineRequest<RequestResponseMetadata> | undefined = undefined;
|
||||
|
||||
// Check max iterations if this is a continuation of a previous execution
|
||||
const maxIterations = ctx.getNodeParameter('options.maxIterations', 0, 10);
|
||||
assertParamIsNumber('options.maxIterations', maxIterations, ctx.getNode());
|
||||
|
||||
const batchPromises = batch.map(async (_item, batchItemIndex) => {
|
||||
const itemIndex = startIndex + batchItemIndex;
|
||||
|
||||
checkMaxIterations(response, maxIterations, ctx.getNode());
|
||||
|
||||
const itemContext = await prepareItemContext(ctx, itemIndex, response);
|
||||
|
||||
const { tools, prompt, options, outputParser } = itemContext;
|
||||
|
||||
Reference in New Issue
Block a user