Skip to content

Commit

Permalink
feat(AI Agent Node): Make tools optional when using OpenAI model with…
Browse files Browse the repository at this point in the history
… Tools agent (#11212)
  • Loading branch information
OlegIvaniv authored Oct 21, 2024
1 parent 0b9b166 commit fed7c3e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
21 changes: 20 additions & 1 deletion packages/@n8n/nodes-langchain/nodes/agents/Agent/Agent.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
INodeTypeDescription,
INodeProperties,
} from 'n8n-workflow';
import { promptTypeOptions, textInput } from '../../../utils/descriptions';

import { conversationalAgentProperties } from './agents/ConversationalAgent/description';
import { conversationalAgentExecute } from './agents/ConversationalAgent/execute';
import { openAiFunctionsAgentProperties } from './agents/OpenAiFunctionsAgent/description';
Expand All @@ -21,6 +21,7 @@ import { sqlAgentAgentProperties } from './agents/SqlAgent/description';
import { sqlAgentAgentExecute } from './agents/SqlAgent/execute';
import { toolsAgentProperties } from './agents/ToolsAgent/description';
import { toolsAgentExecute } from './agents/ToolsAgent/execute';
import { promptTypeOptions, textInput } from '../../../utils/descriptions';

// Function used in the inputs expression to figure out which inputs to
// display based on the agent type
Expand Down Expand Up @@ -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',
name: 'hasOutputParser',
Expand All @@ -372,6 +390,7 @@ export class Agent implements INodeType {
displayOptions: {
show: {
hasOutputParser: [true],
agent: ['toolsAgent'],
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,6 @@ 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,
Expand Down

0 comments on commit fed7c3e

Please sign in to comment.