import { NodeConnectionTypes } from 'n8n-workflow'; import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription, INodeTypeBaseDescription, } from 'n8n-workflow'; import { promptTypeOptions, textFromPreviousNode, textInput } from '@utils/descriptions'; import { getInputs } from './utils'; import { getToolsAgentProperties } from '../agents/ToolsAgent/V2/description'; import { toolsAgentExecute } from '../agents/ToolsAgent/V2/execute'; export class AgentV2 implements INodeType { description: INodeTypeDescription; constructor(baseDescription: INodeTypeBaseDescription) { this.description = { ...baseDescription, version: [2, 2.1, 2.2], defaults: { name: 'AI Agent', color: '#404040', }, inputs: `={{ ((hasOutputParser, needsFallback) => { ${getInputs.toString()}; return getInputs(true, hasOutputParser, needsFallback); })($parameter.hasOutputParser === undefined || $parameter.hasOutputParser === true, $parameter.needsFallback !== undefined && $parameter.needsFallback === true) }}`, outputs: [NodeConnectionTypes.Main], properties: [ { displayName: 'Tip: Get a feel for agents with our quick tutorial or see an example of how this node works', name: 'aiAgentStarterCallout', type: 'callout', default: '', }, promptTypeOptions, { ...textFromPreviousNode, displayOptions: { show: { promptType: ['auto'], }, }, }, { ...textInput, displayOptions: { show: { promptType: ['define'], }, }, }, { displayName: 'Require Specific Output Format', name: 'hasOutputParser', type: 'boolean', default: false, noDataExpression: true, }, { displayName: `Connect an output parser on the canvas to specify the output format you require`, name: 'notice', type: 'notice', default: '', displayOptions: { show: { hasOutputParser: [true], }, }, }, { displayName: 'Enable Fallback Model', name: 'needsFallback', type: 'boolean', default: false, noDataExpression: true, displayOptions: { show: { '@version': [{ _cnd: { gte: 2.1 } }], }, }, }, { displayName: 'Connect an additional language model on the canvas to use it as a fallback if the main model fails', name: 'fallbackNotice', type: 'notice', default: '', displayOptions: { show: { needsFallback: [true], }, }, }, ...getToolsAgentProperties({ withStreaming: true }), ], hints: [ { message: 'You are using streaming responses. Make sure to set the response mode to "Streaming Response" on the connected trigger node.', type: 'warning', location: 'outputPane', whenToDisplay: 'afterExecution', displayCondition: '={{ $parameter["enableStreaming"] === true }}', }, ], }; } async execute(this: IExecuteFunctions): Promise { return await toolsAgentExecute.call(this); } }