feat(AI Agent Node): Make tools optional when using OpenAI model with Tools agent (#11212)
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions
Benchmark Docker Image CI / build (push) Waiting to run

This commit is contained in:
oleg 2024-10-21 14:21:30 +02:00 committed by GitHub
parent 0b9b166bbc
commit fed7c3ec1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 9 deletions

View file

@ -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'],
}, },
}, },
}, },

View file

@ -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,