Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(AI Agent Node): Improve Tools agent empty tool input message #9622

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading