From f5dbb5506fb4e0fea12c0924423df8d46c679a07 Mon Sep 17 00:00:00 2001 From: Oleg Ivaniv Date: Tue, 4 Jun 2024 15:32:36 +0200 Subject: [PATCH 1/3] Change Tools agent order --- .../nodes/agents/Agent/Agent.node.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/Agent.node.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/Agent.node.ts index acbdf28cf486d..e4843f356cc0c 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/Agent.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/Agent.node.ts @@ -190,7 +190,14 @@ const agentTypeProperty: INodeProperties = { name: 'agent', type: 'options', noDataExpression: true, + // eslint-disable-next-line n8n-nodes-base/node-param-options-type-unsorted-items options: [ + { + name: 'Tools Agent', + value: 'toolsAgent', + description: + 'Utilized unified Tool calling interface to select the appropriate tools and argument for execution', + }, { name: 'Conversational Agent', value: 'conversationalAgent', @@ -219,12 +226,6 @@ const agentTypeProperty: INodeProperties = { value: 'sqlAgent', description: 'Answers questions about data in an SQL database', }, - { - name: 'Tools Agent', - value: 'toolsAgent', - description: - 'Utilized unified Tool calling interface to select the appropriate tools and argument for execution', - }, ], default: '', }; From 2cfc5c090c8d378b9131174913ef5defcf6acb43 Mon Sep 17 00:00:00 2001 From: Oleg Ivaniv Date: Tue, 4 Jun 2024 17:12:02 +0200 Subject: [PATCH 2/3] Wrap OpenAI empty tools error response Signed-off-by: Oleg Ivaniv --- .../agents/Agent/agents/ToolsAgent/execute.ts | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts index 11cc3a4de2047..725a5832cc753 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts @@ -13,6 +13,7 @@ import type { ZodObject } from 'zod'; import { z } from 'zod'; import type { BaseOutputParser, StructuredOutputParser } from '@langchain/core/output_parsers'; import { OutputFixingParser } from 'langchain/output_parsers'; +import type { APIError } from 'openai/error'; import { isChatInstance, getPromptInputByType, @@ -21,6 +22,12 @@ import { } from '../../../../../utils/helpers'; import { SYSTEM_MESSAGE } from './prompt'; +function isOpenAiApiError(error: unknown): error is APIError { + return ( + !!error && typeof error === 'object' && 'type' in error && 'param' in error && 'code' in error + ); +} + function getOutputParserSchema(outputParser: BaseOutputParser): ZodObject { const parserType = outputParser.lc_namespace[outputParser.lc_namespace.length - 1]; let schema: ZodObject; @@ -159,7 +166,7 @@ export async function toolsAgentExecute(this: IExecuteFunctions): Promise Date: Wed, 5 Jun 2024 12:14:36 +0200 Subject: [PATCH 3/3] Check if model is openai before showing the empty tools error Signed-off-by: Oleg Ivaniv --- .../agents/Agent/agents/ToolsAgent/execute.ts | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts index 725a5832cc753..603f5afb666b5 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts @@ -13,7 +13,6 @@ import type { ZodObject } from 'zod'; import { z } from 'zod'; import type { BaseOutputParser, StructuredOutputParser } from '@langchain/core/output_parsers'; import { OutputFixingParser } from 'langchain/output_parsers'; -import type { APIError } from 'openai/error'; import { isChatInstance, getPromptInputByType, @@ -22,12 +21,6 @@ import { } from '../../../../../utils/helpers'; import { SYSTEM_MESSAGE } from './prompt'; -function isOpenAiApiError(error: unknown): error is APIError { - return ( - !!error && typeof error === 'object' && 'type' in error && 'param' in error && 'code' in error - ); -} - function getOutputParserSchema(outputParser: BaseOutputParser): ZodObject { const parserType = outputParser.lc_namespace[outputParser.lc_namespace.length - 1]; let schema: ZodObject; @@ -162,6 +155,14 @@ export async function toolsAgentExecute(this: IExecuteFunctions): Promise