Skip to content

Commit

Permalink
fix(AI Agent Node): Improve Tools agent empty tool input message (#9622)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
  • Loading branch information
OlegIvaniv authored Jun 5, 2024
1 parent a8bb53f commit e7f6162
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
13 changes: 7 additions & 6 deletions packages/@n8n/nodes-langchain/nodes/agents/Agent/Agent.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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: '',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,19 @@ export async function toolsAgentExecute(this: IExecuteFunctions): Promise<INodeE
throw new NodeOperationError(this.getNode(), 'The ‘text parameter is empty.');
}

// OpenAI doesn't allow empty tools array so we will provide a more user-friendly error message
if (model.lc_namespace.includes('openai') && tools.length === 0) {
throw new NodeOperationError(
this.getNode(),
"Please connect at least one tool. If you don't need any, try the conversational agent instead",
);
}

const response = await executor.invoke({
input,
system_message: options.systemMessage ?? SYSTEM_MESSAGE,
formatting_instructions:
'IMPORTANT: Always call `format_final_response` to format your final response!', //outputParser?.getFormatInstructions(),
'IMPORTANT: Always call `format_final_response` to format your final response!',
});

returnData.push({
Expand All @@ -174,7 +182,10 @@ export async function toolsAgentExecute(this: IExecuteFunctions): Promise<INodeE
});
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message }, pairedItem: { item: itemIndex } });
returnData.push({
json: { error: error?.message },
pairedItem: { item: itemIndex },
});
continue;
}

Expand Down

0 comments on commit e7f6162

Please sign in to comment.