feat(AI Agent Tool Node): Add Agent Tool (#17108)

This commit is contained in:
Mutasem Aldmour
2025-07-09 11:41:58 +02:00
committed by GitHub
parent 3be5823b97
commit f67581b74d
14 changed files with 500 additions and 116 deletions

View File

@@ -6,6 +6,7 @@ import { z } from 'zod';
import type { ZodObjectAny } from '../../../../types/types';
import { checkForStructuredTools } from '../agents/utils';
import { getInputs } from '../V2/utils';
describe('checkForStructuredTools', () => {
let mockNode: INode;
@@ -105,3 +106,172 @@ describe('checkForStructuredTools', () => {
});
});
});
describe('getInputs', () => {
it('should include all inputs when no flags are set to false', () => {
const inputs = getInputs(true, true, true);
expect(inputs).toEqual([
'main',
{
type: 'ai_languageModel',
displayName: 'Chat Model',
required: true,
maxConnections: 1,
filter: {
excludedNodes: [
'@n8n/n8n-nodes-langchain.lmCohere',
'@n8n/n8n-nodes-langchain.lmOllama',
'n8n/n8n-nodes-langchain.lmOpenAi',
'@n8n/n8n-nodes-langchain.lmOpenHuggingFaceInference',
],
},
},
{
type: 'ai_languageModel',
displayName: 'Fallback Model',
required: true,
maxConnections: 1,
filter: {
excludedNodes: [
'@n8n/n8n-nodes-langchain.lmCohere',
'@n8n/n8n-nodes-langchain.lmOllama',
'n8n/n8n-nodes-langchain.lmOpenAi',
'@n8n/n8n-nodes-langchain.lmOpenHuggingFaceInference',
],
},
},
{
type: 'ai_memory',
displayName: 'Memory',
maxConnections: 1,
},
{
type: 'ai_tool',
displayName: 'Tool',
},
{
type: 'ai_outputParser',
displayName: 'Output Parser',
maxConnections: 1,
},
]);
});
it('should exclude Output Parser when hasOutputParser is false', () => {
const inputs = getInputs(true, false, true);
expect(inputs).toEqual([
'main',
{
type: 'ai_languageModel',
displayName: 'Chat Model',
required: true,
maxConnections: 1,
filter: {
excludedNodes: [
'@n8n/n8n-nodes-langchain.lmCohere',
'@n8n/n8n-nodes-langchain.lmOllama',
'n8n/n8n-nodes-langchain.lmOpenAi',
'@n8n/n8n-nodes-langchain.lmOpenHuggingFaceInference',
],
},
},
{
type: 'ai_languageModel',
displayName: 'Fallback Model',
required: true,
maxConnections: 1,
filter: {
excludedNodes: [
'@n8n/n8n-nodes-langchain.lmCohere',
'@n8n/n8n-nodes-langchain.lmOllama',
'n8n/n8n-nodes-langchain.lmOpenAi',
'@n8n/n8n-nodes-langchain.lmOpenHuggingFaceInference',
],
},
},
{
type: 'ai_memory',
displayName: 'Memory',
maxConnections: 1,
},
{
type: 'ai_tool',
displayName: 'Tool',
},
]);
});
it('should exclude Fallback Model when needsFallback is false', () => {
const inputs = getInputs(true, true, false);
expect(inputs).toEqual([
'main',
{
type: 'ai_languageModel',
displayName: 'Chat Model',
required: true,
maxConnections: 1,
filter: {
excludedNodes: [
'@n8n/n8n-nodes-langchain.lmCohere',
'@n8n/n8n-nodes-langchain.lmOllama',
'n8n/n8n-nodes-langchain.lmOpenAi',
'@n8n/n8n-nodes-langchain.lmOpenHuggingFaceInference',
],
},
},
{
type: 'ai_memory',
displayName: 'Memory',
maxConnections: 1,
},
{
type: 'ai_tool',
displayName: 'Tool',
},
{
type: 'ai_outputParser',
displayName: 'Output Parser',
maxConnections: 1,
},
]);
});
it('should include main input when hasMainInput is true', () => {
const inputs = getInputs(true, true, true);
expect(inputs[0]).toBe('main');
});
it('should exclude main input when hasMainInput is false', () => {
const inputs = getInputs(false, true, true);
expect(inputs).not.toContain('main');
});
it('should handle all flags set to false', () => {
const inputs = getInputs(false, false, false);
expect(inputs).toEqual([
{
type: 'ai_languageModel',
displayName: 'Chat Model',
required: true,
maxConnections: 1,
filter: {
excludedNodes: [
'@n8n/n8n-nodes-langchain.lmCohere',
'@n8n/n8n-nodes-langchain.lmOllama',
'n8n/n8n-nodes-langchain.lmOpenAi',
'@n8n/n8n-nodes-langchain.lmOpenHuggingFaceInference',
],
},
},
{
type: 'ai_memory',
displayName: 'Memory',
maxConnections: 1,
},
{
type: 'ai_tool',
displayName: 'Tool',
},
]);
});
});