@n8n/n8n-nodes-langchain 1.120.2 → 1.121.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/credentials/VercelAiGatewayApi.credentials.js +1 -1
  2. package/dist/credentials/VercelAiGatewayApi.credentials.js.map +1 -1
  3. package/dist/known/credentials.json +1 -0
  4. package/dist/known/nodes.json +4 -0
  5. package/dist/nodes/agents/Agent/V3/AgentV3.node.js +1 -1
  6. package/dist/nodes/agents/Agent/V3/AgentV3.node.js.map +1 -1
  7. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/execute.js +20 -399
  8. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/execute.js.map +1 -1
  9. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/buildExecutionContext.js +74 -0
  10. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/buildExecutionContext.js.map +1 -0
  11. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/buildResponseMetadata.js +37 -0
  12. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/buildResponseMetadata.js.map +1 -0
  13. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/checkMaxIterations.js +40 -0
  14. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/checkMaxIterations.js.map +1 -0
  15. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/createAgentSequence.js +61 -0
  16. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/createAgentSequence.js.map +1 -0
  17. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.js +88 -0
  18. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.js.map +1 -0
  19. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/finalizeResult.js +58 -0
  20. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/finalizeResult.js.map +1 -0
  21. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/index.js +50 -0
  22. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/index.js.map +1 -0
  23. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/prepareItemContext.js +66 -0
  24. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/prepareItemContext.js.map +1 -0
  25. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/runAgent.js +99 -0
  26. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/runAgent.js.map +1 -0
  27. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/types.js +17 -0
  28. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/types.js.map +1 -0
  29. package/dist/nodes/agents/Agent/agents/ToolsAgent/common.js +55 -19
  30. package/dist/nodes/agents/Agent/agents/ToolsAgent/common.js.map +1 -1
  31. package/dist/nodes/document_loaders/DocumentGithubLoader/DocumentGithubLoader.node.js +1 -0
  32. package/dist/nodes/document_loaders/DocumentGithubLoader/DocumentGithubLoader.node.js.map +1 -1
  33. package/dist/nodes/mcp/McpClient/McpClient.node.js +335 -0
  34. package/dist/nodes/mcp/McpClient/McpClient.node.js.map +1 -0
  35. package/dist/nodes/mcp/McpClient/listSearch.js +58 -0
  36. package/dist/nodes/mcp/McpClient/listSearch.js.map +1 -0
  37. package/dist/nodes/mcp/McpClient/resourceMapping.js +61 -0
  38. package/dist/nodes/mcp/McpClient/resourceMapping.js.map +1 -0
  39. package/dist/nodes/mcp/McpClient/utils.js +248 -0
  40. package/dist/nodes/mcp/McpClient/utils.js.map +1 -0
  41. package/dist/nodes/mcp/McpClientTool/McpClientTool.node.js +13 -55
  42. package/dist/nodes/mcp/McpClientTool/McpClientTool.node.js.map +1 -1
  43. package/dist/nodes/mcp/McpClientTool/loadOptions.js +2 -3
  44. package/dist/nodes/mcp/McpClientTool/loadOptions.js.map +1 -1
  45. package/dist/nodes/mcp/McpClientTool/types.js.map +1 -1
  46. package/dist/nodes/mcp/McpClientTool/utils.js +2 -174
  47. package/dist/nodes/mcp/McpClientTool/utils.js.map +1 -1
  48. package/dist/nodes/mcp/{McpClientTool → shared}/descriptions.js +40 -0
  49. package/dist/nodes/mcp/shared/descriptions.js.map +1 -0
  50. package/dist/nodes/mcp/shared/types.js +17 -0
  51. package/dist/nodes/mcp/shared/types.js.map +1 -0
  52. package/dist/nodes/mcp/shared/utils.js +231 -0
  53. package/dist/nodes/mcp/shared/utils.js.map +1 -0
  54. package/dist/nodes/tools/ToolHttpRequest/utils.js +5 -11
  55. package/dist/nodes/tools/ToolHttpRequest/utils.js.map +1 -1
  56. package/dist/nodes/vendors/OpenAi/OpenAi.node.js +3 -2
  57. package/dist/nodes/vendors/OpenAi/OpenAi.node.js.map +1 -1
  58. package/dist/nodes/vendors/OpenAi/v1/actions/audio/index.js +2 -2
  59. package/dist/nodes/vendors/OpenAi/v1/actions/audio/index.js.map +1 -1
  60. package/dist/nodes/vendors/OpenAi/v2/OpenAiV2.node.js +1 -1
  61. package/dist/nodes/vendors/OpenAi/v2/OpenAiV2.node.js.map +1 -1
  62. package/dist/nodes/vendors/OpenAi/v2/actions/audio/index.js +2 -2
  63. package/dist/nodes/vendors/OpenAi/v2/actions/audio/index.js.map +1 -1
  64. package/dist/nodes/vendors/OpenAi/v2/actions/text/classify.operation.js +12 -3
  65. package/dist/nodes/vendors/OpenAi/v2/actions/text/classify.operation.js.map +1 -1
  66. package/dist/types/credentials.json +2 -2
  67. package/dist/types/nodes.json +5 -4
  68. package/dist/utils/agent-execution/buildSteps.js +77 -0
  69. package/dist/utils/agent-execution/buildSteps.js.map +1 -0
  70. package/dist/utils/agent-execution/createEngineRequests.js +48 -0
  71. package/dist/utils/agent-execution/createEngineRequests.js.map +1 -0
  72. package/dist/utils/agent-execution/index.js +42 -0
  73. package/dist/utils/agent-execution/index.js.map +1 -0
  74. package/dist/utils/agent-execution/memoryManagement.js +66 -0
  75. package/dist/utils/agent-execution/memoryManagement.js.map +1 -0
  76. package/dist/utils/agent-execution/processEventStream.js +128 -0
  77. package/dist/utils/agent-execution/processEventStream.js.map +1 -0
  78. package/dist/utils/agent-execution/types.js +17 -0
  79. package/dist/utils/agent-execution/types.js.map +1 -0
  80. package/package.json +11 -9
  81. package/dist/nodes/mcp/McpClientTool/descriptions.js.map +0 -1
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var buildExecutionContext_exports = {};
30
+ __export(buildExecutionContext_exports, {
31
+ buildToolsAgentExecutionContext: () => buildToolsAgentExecutionContext
32
+ });
33
+ module.exports = __toCommonJS(buildExecutionContext_exports);
34
+ var import_n8n_workflow = require("n8n-workflow");
35
+ var import_node_assert = __toESM(require("node:assert"));
36
+ var import_common = require("../../common");
37
+ async function buildToolsAgentExecutionContext(ctx) {
38
+ const items = ctx.getInputData();
39
+ const batchSize = ctx.getNodeParameter("options.batching.batchSize", 0, 1);
40
+ const delayBetweenBatches = ctx.getNodeParameter(
41
+ "options.batching.delayBetweenBatches",
42
+ 0,
43
+ 0
44
+ );
45
+ const needsFallback = ctx.getNodeParameter("needsFallback", 0, false);
46
+ const memory = await (0, import_common.getOptionalMemory)(ctx);
47
+ const model = await (0, import_common.getChatModel)(ctx, 0);
48
+ (0, import_node_assert.default)(model, "Please connect a model to the Chat Model input");
49
+ let fallbackModel = null;
50
+ if (needsFallback) {
51
+ const maybeFallbackModel = await (0, import_common.getChatModel)(ctx, 1);
52
+ if (!maybeFallbackModel) {
53
+ throw new import_n8n_workflow.NodeOperationError(
54
+ ctx.getNode(),
55
+ "Please connect a model to the Fallback Model input or disable the fallback option"
56
+ );
57
+ }
58
+ fallbackModel = maybeFallbackModel;
59
+ }
60
+ return {
61
+ items,
62
+ batchSize,
63
+ delayBetweenBatches,
64
+ needsFallback,
65
+ model,
66
+ fallbackModel,
67
+ memory
68
+ };
69
+ }
70
+ // Annotate the CommonJS export names for ESM import in node:
71
+ 0 && (module.exports = {
72
+ buildToolsAgentExecutionContext
73
+ });
74
+ //# sourceMappingURL=buildExecutionContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../nodes/agents/Agent/agents/ToolsAgent/V3/helpers/buildExecutionContext.ts"],"sourcesContent":["import type { BaseChatModel } from '@langchain/core/language_models/chat_models';\nimport type { BaseChatMemory } from 'langchain/memory';\nimport { NodeOperationError } from 'n8n-workflow';\nimport type { IExecuteFunctions, ISupplyDataFunctions, INodeExecutionData } from 'n8n-workflow';\nimport assert from 'node:assert';\n\nimport { getChatModel, getOptionalMemory } from '../../common';\n\n/**\n * Execution context that contains shared configuration needed across all items\n */\nexport type ToolsAgentExecutionContext = {\n\titems: INodeExecutionData[];\n\tbatchSize: number;\n\tdelayBetweenBatches: number;\n\tneedsFallback: boolean;\n\tmodel: BaseChatModel;\n\tfallbackModel: BaseChatModel | null;\n\tmemory: BaseChatMemory | undefined;\n};\n\n/**\n * Builds the execution context by collecting shared configuration\n * such as models, memory, batching settings, and streaming flags.\n *\n * @param ctx - The execution context (IExecuteFunctions or ISupplyDataFunctions)\n * @returns ExecutionContext containing all shared configuration\n */\nexport async function buildToolsAgentExecutionContext(\n\tctx: IExecuteFunctions | ISupplyDataFunctions,\n): Promise<ToolsAgentExecutionContext> {\n\tconst items = ctx.getInputData();\n\tconst batchSize = ctx.getNodeParameter('options.batching.batchSize', 0, 1) as number;\n\tconst delayBetweenBatches = ctx.getNodeParameter(\n\t\t'options.batching.delayBetweenBatches',\n\t\t0,\n\t\t0,\n\t) as number;\n\tconst needsFallback = ctx.getNodeParameter('needsFallback', 0, false) as boolean;\n\n\tconst memory = await getOptionalMemory(ctx);\n\tconst model = await getChatModel(ctx, 0);\n\tassert(model, 'Please connect a model to the Chat Model input');\n\n\tlet fallbackModel: BaseChatModel | null = null;\n\tif (needsFallback) {\n\t\tconst maybeFallbackModel = await getChatModel(ctx, 1);\n\t\tif (!maybeFallbackModel) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tctx.getNode(),\n\t\t\t\t'Please connect a model to the Fallback Model input or disable the fallback option',\n\t\t\t);\n\t\t}\n\t\tfallbackModel = maybeFallbackModel;\n\t}\n\n\treturn {\n\t\titems,\n\t\tbatchSize,\n\t\tdelayBetweenBatches,\n\t\tneedsFallback,\n\t\tmodel,\n\t\tfallbackModel,\n\t\tmemory,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAAmC;AAEnC,yBAAmB;AAEnB,oBAAgD;AAsBhD,eAAsB,gCACrB,KACsC;AACtC,QAAM,QAAQ,IAAI,aAAa;AAC/B,QAAM,YAAY,IAAI,iBAAiB,8BAA8B,GAAG,CAAC;AACzE,QAAM,sBAAsB,IAAI;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACA,QAAM,gBAAgB,IAAI,iBAAiB,iBAAiB,GAAG,KAAK;AAEpE,QAAM,SAAS,UAAM,iCAAkB,GAAG;AAC1C,QAAM,QAAQ,UAAM,4BAAa,KAAK,CAAC;AACvC,yBAAAA,SAAO,OAAO,gDAAgD;AAE9D,MAAI,gBAAsC;AAC1C,MAAI,eAAe;AAClB,UAAM,qBAAqB,UAAM,4BAAa,KAAK,CAAC;AACpD,QAAI,CAAC,oBAAoB;AACxB,YAAM,IAAI;AAAA,QACT,IAAI,QAAQ;AAAA,QACZ;AAAA,MACD;AAAA,IACD;AACA,oBAAgB;AAAA,EACjB;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;","names":["assert"]}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var buildResponseMetadata_exports = {};
20
+ __export(buildResponseMetadata_exports, {
21
+ buildResponseMetadata: () => buildResponseMetadata
22
+ });
23
+ module.exports = __toCommonJS(buildResponseMetadata_exports);
24
+ var import_agent_execution = require("../../../../../../../utils/agent-execution");
25
+ function buildResponseMetadata(response, itemIndex) {
26
+ const currentIterationCount = response?.metadata?.iterationCount ?? 0;
27
+ return {
28
+ previousRequests: (0, import_agent_execution.buildSteps)(response, itemIndex),
29
+ itemIndex,
30
+ iterationCount: currentIterationCount + 1
31
+ };
32
+ }
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ buildResponseMetadata
36
+ });
37
+ //# sourceMappingURL=buildResponseMetadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../nodes/agents/Agent/agents/ToolsAgent/V3/helpers/buildResponseMetadata.ts"],"sourcesContent":["import type { EngineResponse } from 'n8n-workflow';\n\nimport { buildSteps } from '@utils/agent-execution';\n\nimport type { RequestResponseMetadata } from '../types';\n\n/**\n * Builds metadata for an engine request, tracking iteration count and previous requests.\n *\n * This helper centralizes the logic for incrementing iteration count and building\n * the request history, which is used to enforce max iterations and maintain context.\n *\n * @param response - The optional engine response from previous tool execution\n * @param itemIndex - The current item index being processed\n * @returns Metadata object with previousRequests and iterationCount\n *\n */\nexport function buildResponseMetadata(\n\tresponse: EngineResponse<RequestResponseMetadata> | undefined,\n\titemIndex: number,\n): RequestResponseMetadata {\n\tconst currentIterationCount = response?.metadata?.iterationCount ?? 0;\n\n\treturn {\n\t\tpreviousRequests: buildSteps(response, itemIndex),\n\t\titemIndex,\n\t\titerationCount: currentIterationCount + 1,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,6BAA2B;AAepB,SAAS,sBACf,UACA,WAC0B;AAC1B,QAAM,wBAAwB,UAAU,UAAU,kBAAkB;AAEpE,SAAO;AAAA,IACN,sBAAkB,mCAAW,UAAU,SAAS;AAAA,IAChD;AAAA,IACA,gBAAgB,wBAAwB;AAAA,EACzC;AACD;","names":[]}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var checkMaxIterations_exports = {};
20
+ __export(checkMaxIterations_exports, {
21
+ checkMaxIterations: () => checkMaxIterations
22
+ });
23
+ module.exports = __toCommonJS(checkMaxIterations_exports);
24
+ var import_n8n_workflow = require("n8n-workflow");
25
+ function checkMaxIterations(response, maxIterations, node) {
26
+ if (response?.metadata?.iterationCount === void 0) {
27
+ return;
28
+ }
29
+ if (response.metadata.iterationCount >= maxIterations) {
30
+ throw new import_n8n_workflow.NodeOperationError(
31
+ node,
32
+ `Max iterations (${maxIterations}) reached. The agent could not complete the task within the allowed number of iterations.`
33
+ );
34
+ }
35
+ }
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ checkMaxIterations
39
+ });
40
+ //# sourceMappingURL=checkMaxIterations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../nodes/agents/Agent/agents/ToolsAgent/V3/helpers/checkMaxIterations.ts"],"sourcesContent":["import { NodeOperationError } from 'n8n-workflow';\nimport type { INode, EngineResponse } from 'n8n-workflow';\n\nimport type { RequestResponseMetadata } from '../types';\n\n/**\n * Checks if the maximum iteration limit has been reached and throws an error if so.\n *\n * This function is called at the start of each agent execution to enforce\n * the maximum number of tool call iterations allowed.\n *\n * @param response - The engine response containing iteration metadata (if this is a continuation)\n * @param maxIterations - The maximum number of iterations allowed\n * @param node - The current node (for error context)\n * @throws {NodeOperationError} When the iteration count reaches or exceeds maxIterations\n *\n * @example\n * ```typescript\n * const response: EngineResponse<RequestResponseMetadata> = {\n * // ... response data\n * metadata: { iterationCount: 3 }\n * };\n *\n * // This will throw if iterationCount >= maxIterations\n * checkMaxIterations(response, 2, node);\n * ```\n */\nexport function checkMaxIterations(\n\tresponse: EngineResponse<RequestResponseMetadata> | undefined,\n\tmaxIterations: number,\n\tnode: INode,\n): void {\n\t// Only check if this is a continuation (response has iteration count)\n\tif (response?.metadata?.iterationCount === undefined) {\n\t\treturn;\n\t}\n\n\tif (response.metadata.iterationCount >= maxIterations) {\n\t\tthrow new NodeOperationError(\n\t\t\tnode,\n\t\t\t`Max iterations (${maxIterations}) reached. The agent could not complete the task within the allowed number of iterations.`,\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAmC;AA2B5B,SAAS,mBACf,UACA,eACA,MACO;AAEP,MAAI,UAAU,UAAU,mBAAmB,QAAW;AACrD;AAAA,EACD;AAEA,MAAI,SAAS,SAAS,kBAAkB,eAAe;AACtD,UAAM,IAAI;AAAA,MACT;AAAA,MACA,mBAAmB,aAAa;AAAA,IACjC;AAAA,EACD;AACD;","names":[]}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var createAgentSequence_exports = {};
20
+ __export(createAgentSequence_exports, {
21
+ createAgentSequence: () => createAgentSequence
22
+ });
23
+ module.exports = __toCommonJS(createAgentSequence_exports);
24
+ var import_runnables = require("@langchain/core/runnables");
25
+ var import_agents = require("langchain/agents");
26
+ var import_common = require("../../common");
27
+ function createAgentSequence(model, tools, prompt, _options, outputParser, memory, fallbackModel) {
28
+ const agent = (0, import_agents.createToolCallingAgent)({
29
+ llm: model,
30
+ tools: getAllTools(model, tools),
31
+ prompt,
32
+ streamRunnable: false
33
+ });
34
+ let fallbackAgent;
35
+ if (fallbackModel) {
36
+ fallbackAgent = (0, import_agents.createToolCallingAgent)({
37
+ llm: fallbackModel,
38
+ tools: getAllTools(fallbackModel, tools),
39
+ prompt,
40
+ streamRunnable: false
41
+ });
42
+ }
43
+ const runnableAgent = import_runnables.RunnableSequence.from([
44
+ fallbackAgent ? agent.withFallbacks([fallbackAgent]) : agent,
45
+ (0, import_common.getAgentStepsParser)(outputParser, memory),
46
+ import_common.fixEmptyContentMessage
47
+ ]);
48
+ runnableAgent.singleAction = true;
49
+ runnableAgent.streamRunnable = false;
50
+ return runnableAgent;
51
+ }
52
+ function getAllTools(model, tools) {
53
+ const modelTools = model.metadata?.tools ?? [];
54
+ const allTools = [...tools, ...modelTools];
55
+ return allTools;
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ createAgentSequence
60
+ });
61
+ //# sourceMappingURL=createAgentSequence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../nodes/agents/Agent/agents/ToolsAgent/V3/helpers/createAgentSequence.ts"],"sourcesContent":["import type { BaseChatModel } from '@langchain/core/language_models/chat_models';\nimport type { ChatPromptTemplate } from '@langchain/core/prompts';\nimport { RunnableSequence } from '@langchain/core/runnables';\nimport { type AgentRunnableSequence, createToolCallingAgent } from 'langchain/agents';\nimport type { BaseChatMemory } from 'langchain/memory';\nimport type { DynamicStructuredTool, Tool } from 'langchain/tools';\n\nimport type { N8nOutputParser } from '@utils/output_parsers/N8nOutputParser';\n\nimport { fixEmptyContentMessage, getAgentStepsParser } from '../../common';\n\n/**\n * Creates an agent sequence with the given configuration.\n * The sequence includes the agent, output parser, and fallback logic.\n *\n * @param model - The primary chat model\n * @param tools - Array of tools available to the agent\n * @param prompt - The prompt template\n * @param _options - Additional options (maxIterations, returnIntermediateSteps)\n * @param outputParser - Optional output parser for structured responses\n * @param memory - Optional memory for conversation context\n * @param fallbackModel - Optional fallback model if primary fails\n * @returns AgentRunnableSequence ready for execution\n */\nexport function createAgentSequence(\n\tmodel: BaseChatModel,\n\ttools: Array<DynamicStructuredTool | Tool>,\n\tprompt: ChatPromptTemplate,\n\t_options: { maxIterations?: number; returnIntermediateSteps?: boolean },\n\toutputParser?: N8nOutputParser,\n\tmemory?: BaseChatMemory,\n\tfallbackModel?: BaseChatModel | null,\n) {\n\tconst agent = createToolCallingAgent({\n\t\tllm: model,\n\t\ttools: getAllTools(model, tools),\n\t\tprompt,\n\t\tstreamRunnable: false,\n\t});\n\n\tlet fallbackAgent: AgentRunnableSequence | undefined;\n\tif (fallbackModel) {\n\t\tfallbackAgent = createToolCallingAgent({\n\t\t\tllm: fallbackModel,\n\t\t\ttools: getAllTools(fallbackModel, tools),\n\t\t\tprompt,\n\t\t\tstreamRunnable: false,\n\t\t});\n\t}\n\tconst runnableAgent = RunnableSequence.from([\n\t\tfallbackAgent ? agent.withFallbacks([fallbackAgent]) : agent,\n\t\tgetAgentStepsParser(outputParser, memory),\n\t\tfixEmptyContentMessage,\n\t]) as AgentRunnableSequence;\n\n\trunnableAgent.singleAction = true;\n\trunnableAgent.streamRunnable = false;\n\n\treturn runnableAgent;\n}\n\n/**\n * Uses provided tools and tried to get tools from model metadata\n * Some chat model nodes can define built-in tools in their metadata\n */\nfunction getAllTools(model: BaseChatModel, tools: Array<DynamicStructuredTool | Tool>) {\n\tconst modelTools = (model.metadata?.tools as Tool[]) ?? [];\n\tconst allTools = [...tools, ...modelTools];\n\treturn allTools;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,uBAAiC;AACjC,oBAAmE;AAMnE,oBAA4D;AAerD,SAAS,oBACf,OACA,OACA,QACA,UACA,cACA,QACA,eACC;AACD,QAAM,YAAQ,sCAAuB;AAAA,IACpC,KAAK;AAAA,IACL,OAAO,YAAY,OAAO,KAAK;AAAA,IAC/B;AAAA,IACA,gBAAgB;AAAA,EACjB,CAAC;AAED,MAAI;AACJ,MAAI,eAAe;AAClB,wBAAgB,sCAAuB;AAAA,MACtC,KAAK;AAAA,MACL,OAAO,YAAY,eAAe,KAAK;AAAA,MACvC;AAAA,MACA,gBAAgB;AAAA,IACjB,CAAC;AAAA,EACF;AACA,QAAM,gBAAgB,kCAAiB,KAAK;AAAA,IAC3C,gBAAgB,MAAM,cAAc,CAAC,aAAa,CAAC,IAAI;AAAA,QACvD,mCAAoB,cAAc,MAAM;AAAA,IACxC;AAAA,EACD,CAAC;AAED,gBAAc,eAAe;AAC7B,gBAAc,iBAAiB;AAE/B,SAAO;AACR;AAMA,SAAS,YAAY,OAAsB,OAA4C;AACtF,QAAM,aAAc,MAAM,UAAU,SAAoB,CAAC;AACzD,QAAM,WAAW,CAAC,GAAG,OAAO,GAAG,UAAU;AACzC,SAAO;AACR;","names":[]}
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var executeBatch_exports = {};
20
+ __export(executeBatch_exports, {
21
+ executeBatch: () => executeBatch
22
+ });
23
+ module.exports = __toCommonJS(executeBatch_exports);
24
+ var import_n8n_workflow = require("n8n-workflow");
25
+ var import_N8nOutputParser = require("../../../../../../../utils/output_parsers/N8nOutputParser");
26
+ var import_createAgentSequence = require("./createAgentSequence");
27
+ var import_finalizeResult = require("./finalizeResult");
28
+ var import_prepareItemContext = require("./prepareItemContext");
29
+ var import_runAgent = require("./runAgent");
30
+ async function executeBatch(ctx, batch, startIndex, model, fallbackModel, memory, response) {
31
+ const returnData = [];
32
+ let request = void 0;
33
+ const batchPromises = batch.map(async (_item, batchItemIndex) => {
34
+ const itemIndex = startIndex + batchItemIndex;
35
+ const itemContext = await (0, import_prepareItemContext.prepareItemContext)(ctx, itemIndex, response);
36
+ const { tools, prompt, options, outputParser: outputParser2 } = itemContext;
37
+ const executor = (0, import_createAgentSequence.createAgentSequence)(
38
+ model,
39
+ tools,
40
+ prompt,
41
+ options,
42
+ outputParser2,
43
+ memory,
44
+ fallbackModel
45
+ );
46
+ return await (0, import_runAgent.runAgent)(ctx, executor, itemContext, model, memory, response);
47
+ });
48
+ const batchResults = await Promise.allSettled(batchPromises);
49
+ const outputParser = await (0, import_N8nOutputParser.getOptionalOutputParser)(ctx, 0);
50
+ batchResults.forEach((result, index) => {
51
+ const itemIndex = startIndex + index;
52
+ if (result.status === "rejected") {
53
+ const error = result.reason;
54
+ if (ctx.continueOnFail()) {
55
+ returnData.push({
56
+ json: { error: error.message },
57
+ pairedItem: { item: itemIndex }
58
+ });
59
+ return;
60
+ } else {
61
+ throw new import_n8n_workflow.NodeOperationError(ctx.getNode(), error);
62
+ }
63
+ }
64
+ const batchResult = result.value;
65
+ if (!batchResult) {
66
+ return;
67
+ }
68
+ if ("actions" in batchResult) {
69
+ if (!request) {
70
+ request = {
71
+ actions: batchResult.actions,
72
+ metadata: batchResult.metadata
73
+ };
74
+ } else {
75
+ request.actions.push.apply(request.actions, batchResult.actions);
76
+ }
77
+ return;
78
+ }
79
+ const itemResult = (0, import_finalizeResult.finalizeResult)(batchResult, itemIndex, memory, outputParser);
80
+ returnData.push(itemResult);
81
+ });
82
+ return { returnData, request };
83
+ }
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {
86
+ executeBatch
87
+ });
88
+ //# sourceMappingURL=executeBatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.ts"],"sourcesContent":["import type { BaseChatModel } from '@langchain/core/language_models/chat_models';\nimport type { AgentRunnableSequence } from 'langchain/agents';\nimport type { BaseChatMemory } from 'langchain/memory';\nimport { NodeOperationError } from 'n8n-workflow';\nimport type {\n\tIExecuteFunctions,\n\tISupplyDataFunctions,\n\tINodeExecutionData,\n\tEngineResponse,\n\tEngineRequest,\n} from 'n8n-workflow';\n\nimport { getOptionalOutputParser } from '@utils/output_parsers/N8nOutputParser';\n\nimport type { RequestResponseMetadata, AgentResult } from '../types';\nimport { createAgentSequence } from './createAgentSequence';\nimport { finalizeResult } from './finalizeResult';\nimport { prepareItemContext } from './prepareItemContext';\nimport { runAgent } from './runAgent';\n\ntype BatchResult = AgentResult | EngineRequest<RequestResponseMetadata>;\n/**\n * Executes a batch of items, handling both successful execution and errors.\n * Applies continue-on-fail logic when errors occur.\n *\n * @param ctx - The execution context\n * @param batch - Array of items to process in this batch\n * @param startIndex - Starting index of the batch in the original items array (used to calculate itemIndex)\n * @param model - Primary chat model\n * @param fallbackModel - Optional fallback model\n * @param memory - Optional memory for conversation context\n * @param response - Optional engine response with previous tool calls\n * @returns Object containing execution data and optional requests\n */\nexport async function executeBatch(\n\tctx: IExecuteFunctions | ISupplyDataFunctions,\n\tbatch: INodeExecutionData[],\n\tstartIndex: number,\n\tmodel: BaseChatModel,\n\tfallbackModel: BaseChatModel | null,\n\tmemory: BaseChatMemory | undefined,\n\tresponse?: EngineResponse<RequestResponseMetadata>,\n): Promise<{\n\treturnData: INodeExecutionData[];\n\trequest: EngineRequest<RequestResponseMetadata> | undefined;\n}> {\n\tconst returnData: INodeExecutionData[] = [];\n\tlet request: EngineRequest<RequestResponseMetadata> | undefined = undefined;\n\n\tconst batchPromises = batch.map(async (_item, batchItemIndex) => {\n\t\tconst itemIndex = startIndex + batchItemIndex;\n\n\t\tconst itemContext = await prepareItemContext(ctx, itemIndex, response);\n\n\t\tconst { tools, prompt, options, outputParser } = itemContext;\n\n\t\t// Create executors for primary and fallback models\n\t\tconst executor: AgentRunnableSequence = createAgentSequence(\n\t\t\tmodel,\n\t\t\ttools,\n\t\t\tprompt,\n\t\t\toptions,\n\t\t\toutputParser,\n\t\t\tmemory,\n\t\t\tfallbackModel,\n\t\t);\n\n\t\t// Run the agent\n\t\treturn await runAgent(ctx, executor, itemContext, model, memory, response);\n\t});\n\n\tconst batchResults = await Promise.allSettled(batchPromises);\n\t// This is only used to check if the output parser is connected\n\t// so we can parse the output if needed. Actual output parsing is done in the loop above\n\tconst outputParser = await getOptionalOutputParser(ctx, 0);\n\n\tbatchResults.forEach((result, index) => {\n\t\tconst itemIndex = startIndex + index;\n\t\tif (result.status === 'rejected') {\n\t\t\tconst error = result.reason as Error;\n\t\t\tif (ctx.continueOnFail()) {\n\t\t\t\treturnData.push({\n\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t\t} as INodeExecutionData);\n\t\t\t\treturn;\n\t\t\t} else {\n\t\t\t\tthrow new NodeOperationError(ctx.getNode(), error);\n\t\t\t}\n\t\t}\n\t\tconst batchResult = result.value as BatchResult;\n\n\t\tif (!batchResult) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ('actions' in batchResult) {\n\t\t\tif (!request) {\n\t\t\t\trequest = {\n\t\t\t\t\tactions: batchResult.actions,\n\t\t\t\t\tmetadata: batchResult.metadata,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\trequest.actions.push.apply(request.actions, batchResult.actions);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Finalize the result\n\t\tconst itemResult = finalizeResult(batchResult, itemIndex, memory, outputParser);\n\t\treturnData.push(itemResult);\n\t});\n\n\treturn { returnData, request };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAAmC;AASnC,6BAAwC;AAGxC,iCAAoC;AACpC,4BAA+B;AAC/B,gCAAmC;AACnC,sBAAyB;AAgBzB,eAAsB,aACrB,KACA,OACA,YACA,OACA,eACA,QACA,UAIE;AACF,QAAM,aAAmC,CAAC;AAC1C,MAAI,UAA8D;AAElE,QAAM,gBAAgB,MAAM,IAAI,OAAO,OAAO,mBAAmB;AAChE,UAAM,YAAY,aAAa;AAE/B,UAAM,cAAc,UAAM,8CAAmB,KAAK,WAAW,QAAQ;AAErE,UAAM,EAAE,OAAO,QAAQ,SAAS,cAAAA,cAAa,IAAI;AAGjD,UAAM,eAAkC;AAAA,MACvC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACAA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAGA,WAAO,UAAM,0BAAS,KAAK,UAAU,aAAa,OAAO,QAAQ,QAAQ;AAAA,EAC1E,CAAC;AAED,QAAM,eAAe,MAAM,QAAQ,WAAW,aAAa;AAG3D,QAAM,eAAe,UAAM,gDAAwB,KAAK,CAAC;AAEzD,eAAa,QAAQ,CAAC,QAAQ,UAAU;AACvC,UAAM,YAAY,aAAa;AAC/B,QAAI,OAAO,WAAW,YAAY;AACjC,YAAM,QAAQ,OAAO;AACrB,UAAI,IAAI,eAAe,GAAG;AACzB,mBAAW,KAAK;AAAA,UACf,MAAM,EAAE,OAAO,MAAM,QAAQ;AAAA,UAC7B,YAAY,EAAE,MAAM,UAAU;AAAA,QAC/B,CAAuB;AACvB;AAAA,MACD,OAAO;AACN,cAAM,IAAI,uCAAmB,IAAI,QAAQ,GAAG,KAAK;AAAA,MAClD;AAAA,IACD;AACA,UAAM,cAAc,OAAO;AAE3B,QAAI,CAAC,aAAa;AACjB;AAAA,IACD;AAEA,QAAI,aAAa,aAAa;AAC7B,UAAI,CAAC,SAAS;AACb,kBAAU;AAAA,UACT,SAAS,YAAY;AAAA,UACrB,UAAU,YAAY;AAAA,QACvB;AAAA,MACD,OAAO;AACN,gBAAQ,QAAQ,KAAK,MAAM,QAAQ,SAAS,YAAY,OAAO;AAAA,MAChE;AACA;AAAA,IACD;AAGA,UAAM,iBAAa,sCAAe,aAAa,WAAW,QAAQ,YAAY;AAC9E,eAAW,KAAK,UAAU;AAAA,EAC3B,CAAC;AAED,SAAO,EAAE,YAAY,QAAQ;AAC9B;","names":["outputParser"]}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var finalizeResult_exports = {};
30
+ __export(finalizeResult_exports, {
31
+ finalizeResult: () => finalizeResult
32
+ });
33
+ module.exports = __toCommonJS(finalizeResult_exports);
34
+ var import_omit = __toESM(require("lodash/omit"));
35
+ var import_n8n_workflow = require("n8n-workflow");
36
+ function finalizeResult(result, itemIndex, memory, outputParser) {
37
+ if (memory && outputParser) {
38
+ const parsedOutput = (0, import_n8n_workflow.jsonParse)(result.output);
39
+ result.output = parsedOutput?.output ?? parsedOutput;
40
+ }
41
+ const itemResult = {
42
+ json: (0, import_omit.default)(
43
+ result,
44
+ "system_message",
45
+ "formatting_instructions",
46
+ "input",
47
+ "chat_history",
48
+ "agent_scratchpad"
49
+ ),
50
+ pairedItem: { item: itemIndex }
51
+ };
52
+ return itemResult;
53
+ }
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ finalizeResult
57
+ });
58
+ //# sourceMappingURL=finalizeResult.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../nodes/agents/Agent/agents/ToolsAgent/V3/helpers/finalizeResult.ts"],"sourcesContent":["import type { BaseChatMemory } from 'langchain/memory';\nimport omit from 'lodash/omit';\nimport { jsonParse } from 'n8n-workflow';\nimport type { INodeExecutionData } from 'n8n-workflow';\n\nimport type { N8nOutputParser } from '@utils/output_parsers/N8nOutputParser';\n\nimport type { AgentResult } from '../types';\n\n/**\n * Finalizes the result by parsing output and preparing execution data.\n * Handles output parser integration and memory-based parsing.\n *\n * @param result - The agent result to finalize\n * @param itemIndex - The current item index\n * @param memory - Optional memory for parsing context\n * @param outputParser - Optional output parser for structured responses\n * @returns INodeExecutionData ready for output\n */\nexport function finalizeResult(\n\tresult: AgentResult,\n\titemIndex: number,\n\tmemory: BaseChatMemory | undefined,\n\toutputParser: N8nOutputParser | undefined,\n): INodeExecutionData {\n\t// If memory and outputParser are connected, parse the output.\n\tif (memory && outputParser) {\n\t\tconst parsedOutput = jsonParse<{ output: Record<string, unknown> }>(result.output);\n\t\t// Type assertion needed because parsedOutput can be various types\n\t\tresult.output = (parsedOutput?.output ?? parsedOutput) as unknown as string;\n\t}\n\n\t// Omit internal keys before returning the result.\n\tconst itemResult: INodeExecutionData = {\n\t\tjson: omit(\n\t\t\tresult,\n\t\t\t'system_message',\n\t\t\t'formatting_instructions',\n\t\t\t'input',\n\t\t\t'chat_history',\n\t\t\t'agent_scratchpad',\n\t\t),\n\t\tpairedItem: { item: itemIndex },\n\t};\n\n\treturn itemResult;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAiB;AACjB,0BAA0B;AAiBnB,SAAS,eACf,QACA,WACA,QACA,cACqB;AAErB,MAAI,UAAU,cAAc;AAC3B,UAAM,mBAAe,+BAA+C,OAAO,MAAM;AAEjF,WAAO,SAAU,cAAc,UAAU;AAAA,EAC1C;AAGA,QAAM,aAAiC;AAAA,IACtC,UAAM,YAAAA;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA,YAAY,EAAE,MAAM,UAAU;AAAA,EAC/B;AAEA,SAAO;AACR;","names":["omit"]}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var helpers_exports = {};
20
+ __export(helpers_exports, {
21
+ buildExecutionContext: () => import_buildExecutionContext.buildToolsAgentExecutionContext,
22
+ buildResponseMetadata: () => import_buildResponseMetadata.buildResponseMetadata,
23
+ checkMaxIterations: () => import_checkMaxIterations.checkMaxIterations,
24
+ createAgentSequence: () => import_createAgentSequence.createAgentSequence,
25
+ executeBatch: () => import_executeBatch.executeBatch,
26
+ finalizeResult: () => import_finalizeResult.finalizeResult,
27
+ prepareItemContext: () => import_prepareItemContext.prepareItemContext,
28
+ runAgent: () => import_runAgent.runAgent
29
+ });
30
+ module.exports = __toCommonJS(helpers_exports);
31
+ var import_buildExecutionContext = require("./buildExecutionContext");
32
+ var import_createAgentSequence = require("./createAgentSequence");
33
+ var import_prepareItemContext = require("./prepareItemContext");
34
+ var import_runAgent = require("./runAgent");
35
+ var import_finalizeResult = require("./finalizeResult");
36
+ var import_executeBatch = require("./executeBatch");
37
+ var import_checkMaxIterations = require("./checkMaxIterations");
38
+ var import_buildResponseMetadata = require("./buildResponseMetadata");
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ buildExecutionContext,
42
+ buildResponseMetadata,
43
+ checkMaxIterations,
44
+ createAgentSequence,
45
+ executeBatch,
46
+ finalizeResult,
47
+ prepareItemContext,
48
+ runAgent
49
+ });
50
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../nodes/agents/Agent/agents/ToolsAgent/V3/helpers/index.ts"],"sourcesContent":["export { buildToolsAgentExecutionContext as buildExecutionContext } from './buildExecutionContext';\nexport type { ToolsAgentExecutionContext as ExecutionContext } from './buildExecutionContext';\n\nexport { createAgentSequence } from './createAgentSequence';\n\nexport { prepareItemContext } from './prepareItemContext';\nexport type { ItemContext } from './prepareItemContext';\n\nexport { runAgent } from './runAgent';\n\nexport { finalizeResult } from './finalizeResult';\n\nexport { executeBatch } from './executeBatch';\n\nexport { checkMaxIterations } from './checkMaxIterations';\n\nexport { buildResponseMetadata } from './buildResponseMetadata';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mCAAyE;AAGzE,iCAAoC;AAEpC,gCAAmC;AAGnC,sBAAyB;AAEzB,4BAA+B;AAE/B,0BAA6B;AAE7B,gCAAmC;AAEnC,mCAAsC;","names":[]}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var prepareItemContext_exports = {};
20
+ __export(prepareItemContext_exports, {
21
+ prepareItemContext: () => prepareItemContext
22
+ });
23
+ module.exports = __toCommonJS(prepareItemContext_exports);
24
+ var import_n8n_workflow = require("n8n-workflow");
25
+ var import_agent_execution = require("../../../../../../../utils/agent-execution");
26
+ var import_helpers = require("../../../../../../../utils/helpers");
27
+ var import_N8nOutputParser = require("../../../../../../../utils/output_parsers/N8nOutputParser");
28
+ var import_common = require("../../common");
29
+ async function prepareItemContext(ctx, itemIndex, response) {
30
+ const steps = (0, import_agent_execution.buildSteps)(response, itemIndex);
31
+ const input = (0, import_helpers.getPromptInputByType)({
32
+ ctx,
33
+ i: itemIndex,
34
+ inputKey: "text",
35
+ promptTypeKey: "promptType"
36
+ });
37
+ if (input === void 0) {
38
+ throw new import_n8n_workflow.NodeOperationError(ctx.getNode(), 'The "text" parameter is empty.');
39
+ }
40
+ const outputParser = await (0, import_N8nOutputParser.getOptionalOutputParser)(ctx, itemIndex);
41
+ const tools = await (0, import_common.getTools)(ctx, outputParser);
42
+ const options = ctx.getNodeParameter("options", itemIndex);
43
+ if (options.enableStreaming === void 0) {
44
+ options.enableStreaming = true;
45
+ }
46
+ const messages = await (0, import_common.prepareMessages)(ctx, itemIndex, {
47
+ systemMessage: options.systemMessage,
48
+ passthroughBinaryImages: options.passthroughBinaryImages ?? true,
49
+ outputParser
50
+ });
51
+ const prompt = (0, import_common.preparePrompt)(messages);
52
+ return {
53
+ itemIndex,
54
+ input,
55
+ steps,
56
+ tools,
57
+ prompt,
58
+ options,
59
+ outputParser
60
+ };
61
+ }
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ prepareItemContext
65
+ });
66
+ //# sourceMappingURL=prepareItemContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../nodes/agents/Agent/agents/ToolsAgent/V3/helpers/prepareItemContext.ts"],"sourcesContent":["import type { ChatPromptTemplate } from '@langchain/core/prompts';\nimport type { DynamicStructuredTool, Tool } from 'langchain/tools';\nimport { NodeOperationError } from 'n8n-workflow';\nimport type { IExecuteFunctions, ISupplyDataFunctions, EngineResponse } from 'n8n-workflow';\n\nimport { buildSteps, type ToolCallData } from '@utils/agent-execution';\nimport { getPromptInputByType } from '@utils/helpers';\nimport { getOptionalOutputParser } from '@utils/output_parsers/N8nOutputParser';\nimport type { N8nOutputParser } from '@utils/output_parsers/N8nOutputParser';\n\nimport { getTools, prepareMessages, preparePrompt } from '../../common';\nimport type { AgentOptions, RequestResponseMetadata } from '../types';\n\n/**\n * Context specific to a single item's processing\n */\nexport type ItemContext = {\n\titemIndex: number;\n\tinput: string;\n\tsteps: ToolCallData[];\n\ttools: Array<DynamicStructuredTool | Tool>;\n\tprompt: ChatPromptTemplate;\n\toptions: AgentOptions;\n\toutputParser: N8nOutputParser | undefined;\n};\n\n/**\n * Prepares the context for processing a single item.\n * This includes loading steps, input, tools, prompt, and options.\n *\n * @param ctx - The execution context\n * @param itemIndex - The index of the item to process\n * @param response - Optional engine response with previous tool calls\n * @returns ItemContext containing all item-specific state\n */\nexport async function prepareItemContext(\n\tctx: IExecuteFunctions | ISupplyDataFunctions,\n\titemIndex: number,\n\tresponse?: EngineResponse<RequestResponseMetadata>,\n): Promise<ItemContext> {\n\tconst steps = buildSteps(response, itemIndex);\n\n\tconst input = getPromptInputByType({\n\t\tctx,\n\t\ti: itemIndex,\n\t\tinputKey: 'text',\n\t\tpromptTypeKey: 'promptType',\n\t});\n\tif (input === undefined) {\n\t\tthrow new NodeOperationError(ctx.getNode(), 'The \"text\" parameter is empty.');\n\t}\n\n\tconst outputParser = await getOptionalOutputParser(ctx, itemIndex);\n\tconst tools = await getTools(ctx, outputParser);\n\tconst options = ctx.getNodeParameter('options', itemIndex) as AgentOptions;\n\n\tif (options.enableStreaming === undefined) {\n\t\toptions.enableStreaming = true;\n\t}\n\n\t// Prepare the prompt messages and prompt template.\n\tconst messages = await prepareMessages(ctx, itemIndex, {\n\t\tsystemMessage: options.systemMessage,\n\t\tpassthroughBinaryImages: options.passthroughBinaryImages ?? true,\n\t\toutputParser,\n\t});\n\tconst prompt: ChatPromptTemplate = preparePrompt(messages);\n\n\treturn {\n\t\titemIndex,\n\t\tinput,\n\t\tsteps,\n\t\ttools,\n\t\tprompt,\n\t\toptions,\n\t\toutputParser,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAAmC;AAGnC,6BAA8C;AAC9C,qBAAqC;AACrC,6BAAwC;AAGxC,oBAAyD;AAyBzD,eAAsB,mBACrB,KACA,WACA,UACuB;AACvB,QAAM,YAAQ,mCAAW,UAAU,SAAS;AAE5C,QAAM,YAAQ,qCAAqB;AAAA,IAClC;AAAA,IACA,GAAG;AAAA,IACH,UAAU;AAAA,IACV,eAAe;AAAA,EAChB,CAAC;AACD,MAAI,UAAU,QAAW;AACxB,UAAM,IAAI,uCAAmB,IAAI,QAAQ,GAAG,gCAAgC;AAAA,EAC7E;AAEA,QAAM,eAAe,UAAM,gDAAwB,KAAK,SAAS;AACjE,QAAM,QAAQ,UAAM,wBAAS,KAAK,YAAY;AAC9C,QAAM,UAAU,IAAI,iBAAiB,WAAW,SAAS;AAEzD,MAAI,QAAQ,oBAAoB,QAAW;AAC1C,YAAQ,kBAAkB;AAAA,EAC3B;AAGA,QAAM,WAAW,UAAM,+BAAgB,KAAK,WAAW;AAAA,IACtD,eAAe,QAAQ;AAAA,IACvB,yBAAyB,QAAQ,2BAA2B;AAAA,IAC5D;AAAA,EACD,CAAC;AACD,QAAM,aAA6B,6BAAc,QAAQ;AAEzD,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;","names":[]}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var runAgent_exports = {};
20
+ __export(runAgent_exports, {
21
+ runAgent: () => runAgent
22
+ });
23
+ module.exports = __toCommonJS(runAgent_exports);
24
+ var import_agent_execution = require("../../../../../../../utils/agent-execution");
25
+ var import_prompt = require("../../prompt");
26
+ var import_buildResponseMetadata = require("./buildResponseMetadata");
27
+ async function runAgent(ctx, executor, itemContext, model, memory, response) {
28
+ const { itemIndex, input, steps, tools, options } = itemContext;
29
+ const invokeParams = {
30
+ steps,
31
+ input,
32
+ system_message: options.systemMessage ?? import_prompt.SYSTEM_MESSAGE,
33
+ formatting_instructions: "IMPORTANT: For your response to user, you MUST use the `format_final_json_response` tool with your complete answer formatted according to the required schema. Do not attempt to format the JSON manually - always use this tool. Your response will be rejected if it is not properly formatted through this tool. Only use this tool once you are ready to provide your final answer."
34
+ };
35
+ const executeOptions = { signal: ctx.getExecutionCancelSignal() };
36
+ const isStreamingAvailable = "isStreaming" in ctx ? ctx.isStreaming?.() : void 0;
37
+ if ("isStreaming" in ctx && options.enableStreaming && isStreamingAvailable && ctx.getNode().typeVersion >= 2.1) {
38
+ const chatHistory = await (0, import_agent_execution.loadMemory)(memory, model, options.maxTokensFromMemory);
39
+ const eventStream = executor.streamEvents(
40
+ {
41
+ ...invokeParams,
42
+ chat_history: chatHistory
43
+ },
44
+ {
45
+ version: "v2",
46
+ ...executeOptions
47
+ }
48
+ );
49
+ const result = await (0, import_agent_execution.processEventStream)(
50
+ ctx,
51
+ eventStream,
52
+ itemIndex,
53
+ options.returnIntermediateSteps,
54
+ memory,
55
+ input
56
+ );
57
+ if (result.toolCalls && result.toolCalls.length > 0) {
58
+ const actions = await (0, import_agent_execution.createEngineRequests)(result.toolCalls, itemIndex, tools);
59
+ return {
60
+ actions,
61
+ metadata: (0, import_buildResponseMetadata.buildResponseMetadata)(response, itemIndex)
62
+ };
63
+ }
64
+ return result;
65
+ } else {
66
+ const chatHistory = await (0, import_agent_execution.loadMemory)(memory, model, options.maxTokensFromMemory);
67
+ const modelResponse = await executor.invoke({
68
+ ...invokeParams,
69
+ chat_history: chatHistory
70
+ });
71
+ if ("returnValues" in modelResponse) {
72
+ if (memory && input && modelResponse.returnValues.output) {
73
+ let fullOutput = modelResponse.returnValues.output;
74
+ if (steps.length > 0) {
75
+ const toolContext = steps.map(
76
+ (step) => `Tool: ${step.action.tool}, Input: ${JSON.stringify(step.action.toolInput)}, Result: ${step.observation}`
77
+ ).join("; ");
78
+ fullOutput = `[Used tools: ${toolContext}] ${fullOutput}`;
79
+ }
80
+ await (0, import_agent_execution.saveToMemory)(input, fullOutput, memory);
81
+ }
82
+ const result = { ...modelResponse.returnValues };
83
+ if (options.returnIntermediateSteps && steps.length > 0) {
84
+ result.intermediateSteps = steps;
85
+ }
86
+ return result;
87
+ }
88
+ const actions = await (0, import_agent_execution.createEngineRequests)(modelResponse, itemIndex, tools);
89
+ return {
90
+ actions,
91
+ metadata: (0, import_buildResponseMetadata.buildResponseMetadata)(response, itemIndex)
92
+ };
93
+ }
94
+ }
95
+ // Annotate the CommonJS export names for ESM import in node:
96
+ 0 && (module.exports = {
97
+ runAgent
98
+ });
99
+ //# sourceMappingURL=runAgent.js.map