mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(AI Agent Node): Make tools optional when using OpenAI model with Tools agent (#11212)
This commit is contained in:
@@ -8,7 +8,7 @@ import type {
|
|||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { promptTypeOptions, textInput } from '../../../utils/descriptions';
|
|
||||||
import { conversationalAgentProperties } from './agents/ConversationalAgent/description';
|
import { conversationalAgentProperties } from './agents/ConversationalAgent/description';
|
||||||
import { conversationalAgentExecute } from './agents/ConversationalAgent/execute';
|
import { conversationalAgentExecute } from './agents/ConversationalAgent/execute';
|
||||||
import { openAiFunctionsAgentProperties } from './agents/OpenAiFunctionsAgent/description';
|
import { openAiFunctionsAgentProperties } from './agents/OpenAiFunctionsAgent/description';
|
||||||
@@ -21,6 +21,7 @@ import { sqlAgentAgentProperties } from './agents/SqlAgent/description';
|
|||||||
import { sqlAgentAgentExecute } from './agents/SqlAgent/execute';
|
import { sqlAgentAgentExecute } from './agents/SqlAgent/execute';
|
||||||
import { toolsAgentProperties } from './agents/ToolsAgent/description';
|
import { toolsAgentProperties } from './agents/ToolsAgent/description';
|
||||||
import { toolsAgentExecute } from './agents/ToolsAgent/execute';
|
import { toolsAgentExecute } from './agents/ToolsAgent/execute';
|
||||||
|
import { promptTypeOptions, textInput } from '../../../utils/descriptions';
|
||||||
|
|
||||||
// Function used in the inputs expression to figure out which inputs to
|
// Function used in the inputs expression to figure out which inputs to
|
||||||
// display based on the agent type
|
// display based on the agent type
|
||||||
@@ -351,6 +352,23 @@ export class Agent implements INodeType {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'For more reliable structured output parsing, consider using the Tools agent',
|
||||||
|
name: 'notice',
|
||||||
|
type: 'notice',
|
||||||
|
default: '',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
hasOutputParser: [true],
|
||||||
|
agent: [
|
||||||
|
'conversationalAgent',
|
||||||
|
'reActAgent',
|
||||||
|
'planAndExecuteAgent',
|
||||||
|
'openAiFunctionsAgent',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Require Specific Output Format',
|
displayName: 'Require Specific Output Format',
|
||||||
name: 'hasOutputParser',
|
name: 'hasOutputParser',
|
||||||
@@ -372,6 +390,7 @@ export class Agent implements INodeType {
|
|||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
hasOutputParser: [true],
|
hasOutputParser: [true],
|
||||||
|
agent: ['toolsAgent'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -294,14 +294,6 @@ export async function toolsAgentExecute(this: IExecuteFunctions): Promise<INodeE
|
|||||||
throw new NodeOperationError(this.getNode(), 'The ‘text‘ parameter is empty.');
|
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({
|
const response = await executor.invoke({
|
||||||
input,
|
input,
|
||||||
system_message: options.systemMessage ?? SYSTEM_MESSAGE,
|
system_message: options.systemMessage ?? SYSTEM_MESSAGE,
|
||||||
|
|||||||
Reference in New Issue
Block a user