n8n-nodes-orchestrator-agent 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/nodes/OrchestratorAgent/OrchestratorAgent.node.d.ts +8 -0
- package/dist/nodes/OrchestratorAgent/OrchestratorAgent.node.d.ts.map +1 -0
- package/dist/nodes/OrchestratorAgent/OrchestratorAgent.node.js +308 -0
- package/dist/nodes/OrchestratorAgent/OrchestratorAgent.node.js.map +1 -0
- package/dist/nodes/OrchestratorAgent/OrchestratorAgent.node.json +16 -0
- package/dist/nodes/OrchestratorAgent/orchestrator.svg +22 -0
- package/dist/utils/outputRouter.d.ts +11 -0
- package/dist/utils/outputRouter.d.ts.map +1 -0
- package/dist/utils/outputRouter.js +45 -0
- package/dist/utils/outputRouter.js.map +1 -0
- package/dist/utils/schemaBuilder.d.ts +16 -0
- package/dist/utils/schemaBuilder.d.ts.map +1 -0
- package/dist/utils/schemaBuilder.js +24 -0
- package/dist/utils/schemaBuilder.js.map +1 -0
- package/dist/utils/systemPromptBuilder.d.ts +7 -0
- package/dist/utils/systemPromptBuilder.d.ts.map +1 -0
- package/dist/utils/systemPromptBuilder.js +32 -0
- package/dist/utils/systemPromptBuilder.js.map +1 -0
- package/package.json +67 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kDAAkD,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OrchestratorAgent = void 0;
|
|
4
|
+
var OrchestratorAgent_node_1 = require("./nodes/OrchestratorAgent/OrchestratorAgent.node");
|
|
5
|
+
Object.defineProperty(exports, "OrchestratorAgent", { enumerable: true, get: function () { return OrchestratorAgent_node_1.OrchestratorAgent; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,2FAAqF;AAA5E,2HAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
2
|
+
import { buildOutputArrays } from '../../utils/outputRouter';
|
|
3
|
+
export declare class OrchestratorAgent implements INodeType {
|
|
4
|
+
description: INodeTypeDescription;
|
|
5
|
+
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
|
|
6
|
+
}
|
|
7
|
+
export { buildOutputArrays };
|
|
8
|
+
//# sourceMappingURL=OrchestratorAgent.node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OrchestratorAgent.node.d.ts","sourceRoot":"","sources":["../../../nodes/OrchestratorAgent/OrchestratorAgent.node.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,SAAS,EACT,oBAAoB,EAGrB,MAAM,cAAc,CAAC;AAOtB,OAAO,EAAmB,iBAAiB,EAAmB,MAAM,0BAA0B,CAAC;AAI/F,qBAAa,iBAAkB,YAAW,SAAS;IACjD,WAAW,EAAE,oBAAoB,CAoM/B;IAEI,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;CAsKxE;AAGD,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildOutputArrays = exports.OrchestratorAgent = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const messages_1 = require("@langchain/core/messages");
|
|
6
|
+
const schemaBuilder_1 = require("../../utils/schemaBuilder");
|
|
7
|
+
const systemPromptBuilder_1 = require("../../utils/systemPromptBuilder");
|
|
8
|
+
const outputRouter_1 = require("../../utils/outputRouter");
|
|
9
|
+
Object.defineProperty(exports, "buildOutputArrays", { enumerable: true, get: function () { return outputRouter_1.buildOutputArrays; } });
|
|
10
|
+
class OrchestratorAgent {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.description = {
|
|
13
|
+
displayName: 'Orchestrator Agent',
|
|
14
|
+
name: 'orchestratorAgent',
|
|
15
|
+
icon: 'file:orchestrator.svg',
|
|
16
|
+
group: ['transform'],
|
|
17
|
+
version: 1,
|
|
18
|
+
subtitle: '={{ ($parameter["agents"]["agentValues"] || []).length + " agents" }}',
|
|
19
|
+
description: 'Routes user messages to the appropriate sub-agent using LLM classification. Works as an intelligent Switch with AI reasoning.',
|
|
20
|
+
defaults: {
|
|
21
|
+
name: 'Orchestrator Agent',
|
|
22
|
+
},
|
|
23
|
+
codex: {
|
|
24
|
+
categories: ['AI'],
|
|
25
|
+
subcategories: {
|
|
26
|
+
AI: ['Agents', 'Root Nodes'],
|
|
27
|
+
},
|
|
28
|
+
resources: {
|
|
29
|
+
primaryDocumentation: [
|
|
30
|
+
{
|
|
31
|
+
url: 'https://github.com/growsales-ai/n8n-nodes-orchestrator-agent',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
inputs: [
|
|
37
|
+
n8n_workflow_1.NodeConnectionTypes.Main,
|
|
38
|
+
{
|
|
39
|
+
type: n8n_workflow_1.NodeConnectionTypes.AiLanguageModel,
|
|
40
|
+
required: true,
|
|
41
|
+
displayName: 'Chat Model',
|
|
42
|
+
maxConnections: 1,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: n8n_workflow_1.NodeConnectionTypes.AiMemory,
|
|
46
|
+
required: false,
|
|
47
|
+
displayName: 'Memory',
|
|
48
|
+
maxConnections: 1,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
// Dynamic outputs — each element is { type, displayName } so names render on canvas
|
|
52
|
+
outputs: '={{ (function() { var agents = ($parameter["agents"] && $parameter["agents"]["agentValues"]) ? $parameter["agents"]["agentValues"] : []; var r = []; for (var i = 0; i < agents.length; i++) { r.push({ type: "main", displayName: agents[i].name || ("Agent " + i) }); } if ($parameter["enableFallback"]) { r.push({ type: "main", displayName: "Fallback" }); } if (r.length === 0) { r.push({ type: "main", displayName: "Output" }); } return r; })() }}',
|
|
53
|
+
properties: [
|
|
54
|
+
// ── Sub-Agents ───────────────────────────────────────────────────
|
|
55
|
+
{
|
|
56
|
+
displayName: 'Sub-Agents',
|
|
57
|
+
name: 'agents',
|
|
58
|
+
type: 'fixedCollection',
|
|
59
|
+
typeOptions: { multipleValues: true, sortable: true },
|
|
60
|
+
description: 'Define each sub-agent and when to route to it',
|
|
61
|
+
default: {},
|
|
62
|
+
options: [
|
|
63
|
+
{
|
|
64
|
+
name: 'agentValues',
|
|
65
|
+
displayName: 'Sub-Agent',
|
|
66
|
+
values: [
|
|
67
|
+
{
|
|
68
|
+
displayName: 'Name',
|
|
69
|
+
name: 'name',
|
|
70
|
+
type: 'string',
|
|
71
|
+
default: '',
|
|
72
|
+
placeholder: 'e.g. Scheduling Agent',
|
|
73
|
+
description: 'Displayed as the output label in the canvas',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
displayName: 'Description',
|
|
77
|
+
name: 'description',
|
|
78
|
+
type: 'string',
|
|
79
|
+
typeOptions: { rows: 3 },
|
|
80
|
+
default: '',
|
|
81
|
+
placeholder: 'e.g. Route here when the user wants to schedule appointments, check availability, or cancel bookings',
|
|
82
|
+
description: 'Natural language description for the LLM to decide routing',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
displayName: 'Routing Key (Optional)',
|
|
86
|
+
name: 'routingKey',
|
|
87
|
+
type: 'string',
|
|
88
|
+
default: '',
|
|
89
|
+
description: 'If provided, exact-match routing bypasses the LLM call (e.g. "/schedule")',
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
// ── Input ────────────────────────────────────────────────────────
|
|
96
|
+
{
|
|
97
|
+
displayName: 'Input Source',
|
|
98
|
+
name: 'inputSource',
|
|
99
|
+
type: 'options',
|
|
100
|
+
options: [
|
|
101
|
+
{ name: 'Take from previous node automatically', value: 'auto' },
|
|
102
|
+
{ name: 'Define below', value: 'define' },
|
|
103
|
+
],
|
|
104
|
+
default: 'auto',
|
|
105
|
+
description: 'Where to read the text to classify. Auto mode tries chatInput, message, text, input fields in order.',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
displayName: 'Input Text',
|
|
109
|
+
name: 'inputText',
|
|
110
|
+
type: 'string',
|
|
111
|
+
displayOptions: { show: { inputSource: ['define'] } },
|
|
112
|
+
default: '',
|
|
113
|
+
description: 'Text to classify. Use expressions like {{ $json.chatInput }}',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
displayName: 'System Prompt Prefix (Optional)',
|
|
117
|
+
name: 'systemPromptPrefix',
|
|
118
|
+
type: 'string',
|
|
119
|
+
typeOptions: { rows: 4 },
|
|
120
|
+
default: '',
|
|
121
|
+
placeholder: 'e.g. This is a Brazilian Portuguese customer support bot for a real estate company.',
|
|
122
|
+
description: 'Optional instructions prepended to the auto-generated classification prompt',
|
|
123
|
+
},
|
|
124
|
+
// ── Fallback ─────────────────────────────────────────────────────
|
|
125
|
+
{
|
|
126
|
+
displayName: 'Enable Fallback Output',
|
|
127
|
+
name: 'enableFallback',
|
|
128
|
+
type: 'boolean',
|
|
129
|
+
default: true,
|
|
130
|
+
description: "Whether to add an extra output for messages that don't match any sub-agent",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
displayName: 'Minimum Confidence',
|
|
134
|
+
name: 'minConfidence',
|
|
135
|
+
type: 'number',
|
|
136
|
+
typeOptions: { minValue: 0, maxValue: 1, numberStepSize: 0.05 },
|
|
137
|
+
default: 0.5,
|
|
138
|
+
displayOptions: { show: { enableFallback: [true] } },
|
|
139
|
+
description: 'If the model confidence is below this threshold, route to fallback instead',
|
|
140
|
+
},
|
|
141
|
+
// ── Metadata & Session ───────────────────────────────────────────
|
|
142
|
+
{
|
|
143
|
+
displayName: 'Include Routing Metadata',
|
|
144
|
+
name: 'includeMetadata',
|
|
145
|
+
type: 'boolean',
|
|
146
|
+
default: true,
|
|
147
|
+
description: 'Whether to add a $json._orchestrator field to the output with routing decision details',
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
displayName: 'Session ID',
|
|
151
|
+
name: 'sessionId',
|
|
152
|
+
type: 'string',
|
|
153
|
+
default: '={{ $json.sessionId ?? $execution.id }}',
|
|
154
|
+
description: 'Session ID passed to the Memory sub-node',
|
|
155
|
+
},
|
|
156
|
+
// ── Advanced ─────────────────────────────────────────────────────
|
|
157
|
+
{
|
|
158
|
+
displayName: 'Options',
|
|
159
|
+
name: 'options',
|
|
160
|
+
type: 'collection',
|
|
161
|
+
placeholder: 'Add Option',
|
|
162
|
+
default: {},
|
|
163
|
+
options: [
|
|
164
|
+
{
|
|
165
|
+
displayName: 'Max Tokens (Classification)',
|
|
166
|
+
name: 'maxTokens',
|
|
167
|
+
type: 'number',
|
|
168
|
+
default: 256,
|
|
169
|
+
description: 'Max tokens for the classification LLM call',
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
displayName: 'Pass Full Input to Outputs',
|
|
173
|
+
name: 'passFullInput',
|
|
174
|
+
type: 'boolean',
|
|
175
|
+
default: true,
|
|
176
|
+
description: 'Whether to merge all input fields into the output alongside routing metadata',
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
displayName: 'Retry on Parse Failure',
|
|
180
|
+
name: 'retryOnParseFail',
|
|
181
|
+
type: 'boolean',
|
|
182
|
+
default: true,
|
|
183
|
+
description: 'Whether to retry once with explicit JSON instructions if structured output fails to parse',
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
displayName: 'Temperature',
|
|
187
|
+
name: 'temperature',
|
|
188
|
+
type: 'number',
|
|
189
|
+
typeOptions: { minValue: 0, maxValue: 1, numberStepSize: 0.1 },
|
|
190
|
+
default: 0,
|
|
191
|
+
description: 'Temperature for classification. 0 = deterministic (recommended)',
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
async execute() {
|
|
199
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
200
|
+
const items = this.getInputData();
|
|
201
|
+
// ── Parameters ──────────────────────────────────────────────────────
|
|
202
|
+
const agentsParam = this.getNodeParameter('agents', 0);
|
|
203
|
+
const agents = (_a = agentsParam.agentValues) !== null && _a !== void 0 ? _a : [];
|
|
204
|
+
if (agents.length === 0) {
|
|
205
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'At least one sub-agent must be configured in the Sub-Agents section.');
|
|
206
|
+
}
|
|
207
|
+
const enableFallback = this.getNodeParameter('enableFallback', 0);
|
|
208
|
+
const minConfidence = enableFallback
|
|
209
|
+
? this.getNodeParameter('minConfidence', 0)
|
|
210
|
+
: 0;
|
|
211
|
+
const includeMetadata = this.getNodeParameter('includeMetadata', 0);
|
|
212
|
+
const inputSource = this.getNodeParameter('inputSource', 0);
|
|
213
|
+
const systemPromptPrefix = this.getNodeParameter('systemPromptPrefix', 0);
|
|
214
|
+
const options = this.getNodeParameter('options', 0, {});
|
|
215
|
+
const passFullInput = options.passFullInput !== false;
|
|
216
|
+
const retryOnParseFail = options.retryOnParseFail !== false;
|
|
217
|
+
// ── LLM & Memory (initialized once, shared across items) ────────────
|
|
218
|
+
const llm = (await this.getInputConnectionData(n8n_workflow_1.NodeConnectionTypes.AiLanguageModel, 0));
|
|
219
|
+
const schema = (0, schemaBuilder_1.buildRoutingSchema)(agents.length, enableFallback);
|
|
220
|
+
const structuredLLM = llm.withStructuredOutput(schema);
|
|
221
|
+
const systemPrompt = (0, systemPromptBuilder_1.buildSystemPrompt)(agents, enableFallback, systemPromptPrefix);
|
|
222
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
223
|
+
const memoryNode = (await this.getInputConnectionData(n8n_workflow_1.NodeConnectionTypes.AiMemory, 0));
|
|
224
|
+
let chatHistory = [];
|
|
225
|
+
if (memoryNode) {
|
|
226
|
+
try {
|
|
227
|
+
chatHistory = (_c = (await ((_b = memoryNode.chatHistory) === null || _b === void 0 ? void 0 : _b.getMessages()))) !== null && _c !== void 0 ? _c : [];
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
chatHistory = [];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// ── Accumulated outputs ─────────────────────────────────────────────
|
|
234
|
+
const totalOutputs = agents.length + (enableFallback ? 1 : 0);
|
|
235
|
+
const accumulatedOutputs = Array.from({ length: totalOutputs }, () => []);
|
|
236
|
+
// ── Process each input item ─────────────────────────────────────────
|
|
237
|
+
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
|
238
|
+
const startTime = Date.now();
|
|
239
|
+
const item = items[itemIndex];
|
|
240
|
+
const inputData = passFullInput ? { ...item.json } : {};
|
|
241
|
+
// Resolve input text
|
|
242
|
+
let inputText;
|
|
243
|
+
if (inputSource === 'define') {
|
|
244
|
+
inputText = this.getNodeParameter('inputText', itemIndex);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
inputText = String((_g = (_f = (_e = (_d = item.json.chatInput) !== null && _d !== void 0 ? _d : item.json.message) !== null && _e !== void 0 ? _e : item.json.text) !== null && _f !== void 0 ? _f : item.json.input) !== null && _g !== void 0 ? _g : JSON.stringify(item.json));
|
|
248
|
+
}
|
|
249
|
+
// Exact match bypass
|
|
250
|
+
const exactMatchIndex = (0, outputRouter_1.checkExactMatch)(agents, inputText);
|
|
251
|
+
if (exactMatchIndex !== -1) {
|
|
252
|
+
const outputItem = (0, outputRouter_1.buildOutputItem)(exactMatchIndex, agents, inputText, { agentIndex: exactMatchIndex, confidence: 1.0, reasoning: 'Exact routing key match' }, inputData, includeMetadata, startTime);
|
|
253
|
+
accumulatedOutputs[exactMatchIndex].push(outputItem);
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
// LLM classification
|
|
257
|
+
const messages = [
|
|
258
|
+
new messages_1.SystemMessage(systemPrompt),
|
|
259
|
+
...chatHistory,
|
|
260
|
+
new messages_1.HumanMessage(inputText),
|
|
261
|
+
];
|
|
262
|
+
let result;
|
|
263
|
+
try {
|
|
264
|
+
result = (await structuredLLM.invoke(messages));
|
|
265
|
+
}
|
|
266
|
+
catch (firstError) {
|
|
267
|
+
if (!retryOnParseFail)
|
|
268
|
+
throw firstError;
|
|
269
|
+
try {
|
|
270
|
+
const retryMessages = [
|
|
271
|
+
new messages_1.SystemMessage(systemPrompt +
|
|
272
|
+
'\n\nCRITICAL: Respond with valid JSON only. No markdown fences, no explanation.'),
|
|
273
|
+
...chatHistory,
|
|
274
|
+
new messages_1.HumanMessage(inputText),
|
|
275
|
+
];
|
|
276
|
+
result = (await structuredLLM.invoke(retryMessages));
|
|
277
|
+
}
|
|
278
|
+
catch (retryError) {
|
|
279
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `LLM classification failed after retry: ${retryError.message}`, { itemIndex });
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
// Apply confidence threshold
|
|
283
|
+
let finalIndex = result.agentIndex;
|
|
284
|
+
if (enableFallback && result.confidence < minConfidence) {
|
|
285
|
+
finalIndex = agents.length; // route to fallback
|
|
286
|
+
}
|
|
287
|
+
// Clamp to valid range
|
|
288
|
+
if (finalIndex < 0 || finalIndex >= totalOutputs) {
|
|
289
|
+
finalIndex = enableFallback ? agents.length : 0;
|
|
290
|
+
}
|
|
291
|
+
// Update memory
|
|
292
|
+
if (memoryNode) {
|
|
293
|
+
try {
|
|
294
|
+
await ((_h = memoryNode.chatHistory) === null || _h === void 0 ? void 0 : _h.addUserMessage(inputText));
|
|
295
|
+
await ((_j = memoryNode.chatHistory) === null || _j === void 0 ? void 0 : _j.addAIChatMessage(`[routed to: ${(_l = (_k = agents[result.agentIndex]) === null || _k === void 0 ? void 0 : _k.name) !== null && _l !== void 0 ? _l : 'Fallback'}]`));
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
// Memory update errors are non-fatal
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
const outputItem = (0, outputRouter_1.buildOutputItem)(finalIndex, agents, inputText, result, inputData, includeMetadata, startTime);
|
|
302
|
+
accumulatedOutputs[finalIndex].push(outputItem);
|
|
303
|
+
}
|
|
304
|
+
return accumulatedOutputs;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
exports.OrchestratorAgent = OrchestratorAgent;
|
|
308
|
+
//# sourceMappingURL=OrchestratorAgent.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OrchestratorAgent.node.js","sourceRoot":"","sources":["../../../nodes/OrchestratorAgent/OrchestratorAgent.node.ts"],"names":[],"mappings":";;;AAAA,+CAOsB;AAGtB,uDAAoF;AAEpF,6DAA+D;AAC/D,yEAAqF;AACrF,2DAA+F;AAoXtF,kGApXiB,gCAAiB,OAoXjB;AAhX1B,MAAa,iBAAiB;IAA9B;QACE,gBAAW,GAAyB;YAClC,WAAW,EAAE,oBAAoB;YACjC,IAAI,EAAE,mBAAmB;YACzB,IAAI,EAAE,uBAAuB;YAC7B,KAAK,EAAE,CAAC,WAAW,CAAC;YACpB,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,uEAAuE;YACjF,WAAW,EACT,+HAA+H;YACjI,QAAQ,EAAE;gBACR,IAAI,EAAE,oBAAoB;aAC3B;YACD,KA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W,0CAAE,gBAAgB,CAC5C,eAAe,MAAA,MAAA,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,0CAAE,IAAI,mCAAI,UAAU,GAAG,CAChE,CAAA,CAAC;gBACJ,CAAC;gBAAC,MAAM,CAAC;oBACP,qCAAqC;gBACvC,CAAC;YACH,CAAC;YAED,MAAM,UAAU,GAAG,IAAA,8BAAe,EAChC,UAAU,EACV,MAAM,EACN,SAAS,EACT,MAAM,EACN,SAAS,EACT,eAAe,EACf,SAAS,CACV,CAAC;YACF,kBAAkB,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,kBAAkB,CAAC;IAC5B,CAAC;CACF;AA7WD,8CA6WC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"node": "n8n-nodes-orchestrator-agent.orchestratorAgent",
|
|
3
|
+
"nodeVersion": "1.0",
|
|
4
|
+
"codexVersion": "1.0",
|
|
5
|
+
"categories": ["AI"],
|
|
6
|
+
"subcategories": {
|
|
7
|
+
"AI": ["Agents", "Root Nodes"]
|
|
8
|
+
},
|
|
9
|
+
"resources": {
|
|
10
|
+
"primaryDocumentation": [
|
|
11
|
+
{
|
|
12
|
+
"url": "https://github.com/growsales-ai/n8n-nodes-orchestrator-agent"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 60">
|
|
2
|
+
<!-- Background -->
|
|
3
|
+
<rect width="60" height="60" rx="12" fill="#FF6B6B"/>
|
|
4
|
+
|
|
5
|
+
<!-- Input line from top -->
|
|
6
|
+
<line x1="30" y1="6" x2="30" y2="18" stroke="white" stroke-width="2.5" stroke-linecap="round"/>
|
|
7
|
+
|
|
8
|
+
<!-- Central hub circle -->
|
|
9
|
+
<circle cx="30" cy="24" r="7" fill="white"/>
|
|
10
|
+
<!-- Hub inner dot -->
|
|
11
|
+
<circle cx="30" cy="24" r="3" fill="#FF6B6B"/>
|
|
12
|
+
|
|
13
|
+
<!-- Output lines: left, center, right -->
|
|
14
|
+
<line x1="25" y1="30" x2="12" y2="46" stroke="white" stroke-width="2" stroke-linecap="round"/>
|
|
15
|
+
<line x1="30" y1="31" x2="30" y2="46" stroke="white" stroke-width="2" stroke-linecap="round"/>
|
|
16
|
+
<line x1="35" y1="30" x2="48" y2="46" stroke="white" stroke-width="2" stroke-linecap="round"/>
|
|
17
|
+
|
|
18
|
+
<!-- Output endpoint dots -->
|
|
19
|
+
<circle cx="12" cy="49" r="3.5" fill="white"/>
|
|
20
|
+
<circle cx="30" cy="49" r="3.5" fill="white"/>
|
|
21
|
+
<circle cx="48" cy="49" r="3.5" fill="white"/>
|
|
22
|
+
</svg>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { INodeExecutionData } from 'n8n-workflow';
|
|
2
|
+
import { AgentDefinition } from './systemPromptBuilder';
|
|
3
|
+
export interface RoutingResult {
|
|
4
|
+
agentIndex: number;
|
|
5
|
+
confidence: number;
|
|
6
|
+
reasoning: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function checkExactMatch(agents: AgentDefinition[], inputText: string): number;
|
|
9
|
+
export declare function buildOutputItem(routedIndex: number, agents: AgentDefinition[], inputText: string, result: RoutingResult, inputData: Record<string, unknown>, includeMetadata: boolean, startTime: number): INodeExecutionData;
|
|
10
|
+
export declare function buildOutputArrays(routedIndex: number, agents: AgentDefinition[], inputText: string, result: RoutingResult, inputData: Record<string, unknown>, includeMetadata: boolean, enableFallback: boolean, startTime: number): INodeExecutionData[][];
|
|
11
|
+
//# sourceMappingURL=outputRouter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputRouter.d.ts","sourceRoot":"","sources":["../../utils/outputRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CASpF;AAED,wBAAgB,eAAe,CAC7B,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,eAAe,EAAE,EACzB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,eAAe,EAAE,OAAO,EACxB,SAAS,EAAE,MAAM,GAChB,kBAAkB,CAoBpB;AAED,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,eAAe,EAAE,EACzB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,eAAe,EAAE,OAAO,EACxB,cAAc,EAAE,OAAO,EACvB,SAAS,EAAE,MAAM,GAChB,kBAAkB,EAAE,EAAE,CAQxB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkExactMatch = checkExactMatch;
|
|
4
|
+
exports.buildOutputItem = buildOutputItem;
|
|
5
|
+
exports.buildOutputArrays = buildOutputArrays;
|
|
6
|
+
function checkExactMatch(agents, inputText) {
|
|
7
|
+
var _a;
|
|
8
|
+
const trimmed = inputText.trim();
|
|
9
|
+
for (let i = 0; i < agents.length; i++) {
|
|
10
|
+
const key = (_a = agents[i].routingKey) === null || _a === void 0 ? void 0 : _a.trim();
|
|
11
|
+
if (key && trimmed === key) {
|
|
12
|
+
return i;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return -1;
|
|
16
|
+
}
|
|
17
|
+
function buildOutputItem(routedIndex, agents, inputText, result, inputData, includeMetadata, startTime) {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
const metadata = includeMetadata
|
|
20
|
+
? {
|
|
21
|
+
_orchestrator: {
|
|
22
|
+
routedTo: routedIndex < agents.length ? ((_b = (_a = agents[routedIndex]) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : 'Fallback') : 'Fallback',
|
|
23
|
+
routedIndex,
|
|
24
|
+
confidence: result.confidence,
|
|
25
|
+
reasoning: result.reasoning,
|
|
26
|
+
inputText,
|
|
27
|
+
latencyMs: Date.now() - startTime,
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
: {};
|
|
31
|
+
return {
|
|
32
|
+
json: {
|
|
33
|
+
...inputData,
|
|
34
|
+
...metadata,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function buildOutputArrays(routedIndex, agents, inputText, result, inputData, includeMetadata, enableFallback, startTime) {
|
|
39
|
+
const totalOutputs = agents.length + (enableFallback ? 1 : 0);
|
|
40
|
+
const outputArrays = Array.from({ length: totalOutputs }, () => []);
|
|
41
|
+
const item = buildOutputItem(routedIndex, agents, inputText, result, inputData, includeMetadata, startTime);
|
|
42
|
+
outputArrays[routedIndex].push(item);
|
|
43
|
+
return outputArrays;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=outputRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputRouter.js","sourceRoot":"","sources":["../../utils/outputRouter.ts"],"names":[],"mappings":";;AASA,0CASC;AAED,0CA4BC;AAED,8CAiBC;AA1DD,SAAgB,eAAe,CAAC,MAAyB,EAAE,SAAiB;;IAC1E,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;IACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CA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AAE,MAAM,EAAE,YAAY,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;IAE5F,MAAM,IAAI,GAAG,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC;IAC5G,YAAY,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAErC,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare function buildRoutingSchema(agentCount: number, hasFallback: boolean): z.ZodObject<{
|
|
3
|
+
agentIndex: z.ZodNumber;
|
|
4
|
+
confidence: z.ZodNumber;
|
|
5
|
+
reasoning: z.ZodString;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
agentIndex: number;
|
|
8
|
+
confidence: number;
|
|
9
|
+
reasoning: string;
|
|
10
|
+
}, {
|
|
11
|
+
agentIndex: number;
|
|
12
|
+
confidence: number;
|
|
13
|
+
reasoning: string;
|
|
14
|
+
}>;
|
|
15
|
+
export type RoutingSchema = ReturnType<typeof buildRoutingSchema>;
|
|
16
|
+
//# sourceMappingURL=schemaBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaBuilder.d.ts","sourceRoot":"","sources":["../../utils/schemaBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO;;;;;;;;;;;;GAkB1E;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildRoutingSchema = buildRoutingSchema;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
function buildRoutingSchema(agentCount, hasFallback) {
|
|
6
|
+
const maxIndex = hasFallback ? agentCount : agentCount - 1;
|
|
7
|
+
return zod_1.z.object({
|
|
8
|
+
agentIndex: zod_1.z
|
|
9
|
+
.number()
|
|
10
|
+
.int()
|
|
11
|
+
.min(0)
|
|
12
|
+
.max(maxIndex)
|
|
13
|
+
.describe(`Index of the chosen agent (0-${maxIndex})`),
|
|
14
|
+
confidence: zod_1.z
|
|
15
|
+
.number()
|
|
16
|
+
.min(0)
|
|
17
|
+
.max(1)
|
|
18
|
+
.describe('Confidence score for this routing decision (0.0 to 1.0)'),
|
|
19
|
+
reasoning: zod_1.z
|
|
20
|
+
.string()
|
|
21
|
+
.describe('One-sentence explanation for this routing decision'),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=schemaBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaBuilder.js","sourceRoot":"","sources":["../../utils/schemaBuilder.ts"],"names":[],"mappings":";;AAEA,gDAkBC;AApBD,6BAAwB;AAExB,SAAgB,kBAAkB,CAAC,UAAkB,EAAE,WAAoB;IACzE,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC;IAC3D,OAAO,OAAC,CAAC,MAAM,CAAC;QACd,UAAU,EAAE,OAAC;aACV,MAAM,EAAE;aACR,GAAG,EAAE;aACL,GAAG,CAAC,CAAC,CAAC;aACN,GAAG,CAAC,QAAQ,CAAC;aACb,QAAQ,CAAC,gCAAgC,QAAQ,GAAG,CAAC;QACxD,UAAU,EAAE,OAAC;aACV,MAAM,EAAE;aACR,GAAG,CAAC,CAAC,CAAC;aACN,GAAG,CAAC,CAAC,CAAC;aACN,QAAQ,CAAC,yDAAyD,CAAC;QACtE,SAAS,EAAE,OAAC;aACT,MAAM,EAAE;aACR,QAAQ,CAAC,oDAAoD,CAAC;KAClE,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface AgentDefinition {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
routingKey?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function buildSystemPrompt(agents: AgentDefinition[], enableFallback: boolean, systemPromptPrefix: string): string;
|
|
7
|
+
//# sourceMappingURL=systemPromptBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systemPromptBuilder.d.ts","sourceRoot":"","sources":["../../utils/systemPromptBuilder.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,eAAe,EAAE,EACzB,cAAc,EAAE,OAAO,EACvB,kBAAkB,EAAE,MAAM,GACzB,MAAM,CAiCR"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildSystemPrompt = buildSystemPrompt;
|
|
4
|
+
function buildSystemPrompt(agents, enableFallback, systemPromptPrefix) {
|
|
5
|
+
const fallbackIndex = agents.length;
|
|
6
|
+
const agentLines = agents
|
|
7
|
+
.map((agent, index) => {
|
|
8
|
+
let entry = `[${index}] ${agent.name}\n → ${agent.description}`;
|
|
9
|
+
if (agent.routingKey) {
|
|
10
|
+
entry += `\n Exact routing key: "${agent.routingKey}"`;
|
|
11
|
+
}
|
|
12
|
+
return entry;
|
|
13
|
+
})
|
|
14
|
+
.join('\n\n');
|
|
15
|
+
const fallbackLine = enableFallback
|
|
16
|
+
? `\n\n[${fallbackIndex}] Fallback\n → Use this when no other agent is a good match`
|
|
17
|
+
: '';
|
|
18
|
+
const prefix = systemPromptPrefix ? `${systemPromptPrefix.trim()}\n\n` : '';
|
|
19
|
+
return (`${prefix}` +
|
|
20
|
+
`You are a routing classifier. Your only job is to analyze the user's message and decide which specialized agent should handle it.\n\n` +
|
|
21
|
+
`Available agents:\n${agentLines}${fallbackLine}\n\n` +
|
|
22
|
+
`Rules:\n` +
|
|
23
|
+
`- Analyze the user message, considering conversation history if provided\n` +
|
|
24
|
+
`- Return the index (0-based) of the most appropriate agent\n` +
|
|
25
|
+
(enableFallback
|
|
26
|
+
? `- If no agent is a good fit, use index ${fallbackIndex} (Fallback)\n`
|
|
27
|
+
: '') +
|
|
28
|
+
`- Provide a confidence score between 0.0 and 1.0\n` +
|
|
29
|
+
`- Provide a one-sentence reasoning\n\n` +
|
|
30
|
+
`Respond ONLY with the JSON schema provided.`);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=systemPromptBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systemPromptBuilder.js","sourceRoot":"","sources":["../../utils/systemPromptBuilder.ts"],"names":[],"mappings":";;AAMA,8CAqCC;AArCD,SAAgB,iBAAiB,CAC/B,MAAyB,EACzB,cAAuB,EACvB,kBAA0B;IAE1B,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IAEpC,MAAM,UAAU,GAAG,MAAM;SACtB,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACpB,IAAI,KAAK,GAAG,IAAI,KAAK,KAAK,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,WAAW,EAAE,CAAC;QACjE,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;YACrB,KAAK,IAAI,2BAA2B,KAAK,CAAC,UAAU,GAAG,CAAC;QAC1D,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;SACD,IAAI,CAAC,MAAM,CAAC,CAAC;IAEhB,MAAM,YAAY,GAAG,cAAc;QACjC,CAAC,CAAC,QAAQ,aAAa,8DAA8D;QACrF,CAAC,CAAC,EAAE,CAAC;IAEP,MAAM,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IAE5E,OAAO,CACL,GAAG,MAAM,EAAE;QACX,uIAAuI;QACvI,sBAAsB,UAAU,GAAG,YAAY,MAAM;QACrD,UAAU;QACV,4EAA4E;QAC5E,8DAA8D;QAC9D,CAAC,cAAc;YACb,CAAC,CAAC,0CAA0C,aAAa,eAAe;YACxE,CAAC,CAAC,EAAE,CAAC;QACP,oDAAoD;QACpD,wCAAwC;QACxC,6CAA6C,CAC9C,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "n8n-nodes-orchestrator-agent",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Orchestrator Agent Node for n8n — intelligent multi-output classifier with LLM routing",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"n8n-community-node-package",
|
|
7
|
+
"n8n",
|
|
8
|
+
"ai-agent",
|
|
9
|
+
"orchestrator",
|
|
10
|
+
"router",
|
|
11
|
+
"langchain",
|
|
12
|
+
"classifier"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"main": "index.js",
|
|
16
|
+
"n8n": {
|
|
17
|
+
"n8nNodesApiVersion": 1,
|
|
18
|
+
"credentials": [],
|
|
19
|
+
"nodes": [
|
|
20
|
+
"dist/nodes/OrchestratorAgent/OrchestratorAgent.node.js"
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc && node postbuild.js",
|
|
25
|
+
"dev": "tsc --watch",
|
|
26
|
+
"lint": "eslint nodes --ext .ts",
|
|
27
|
+
"test": "jest",
|
|
28
|
+
"prepublishOnly": "npm run build && npm test"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@langchain/core": "^0.3.0",
|
|
35
|
+
"zod": "^3.23.8"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/jest": "^29",
|
|
39
|
+
"@types/node": "^18",
|
|
40
|
+
"jest": "^29",
|
|
41
|
+
"n8n-workflow": "*",
|
|
42
|
+
"ts-jest": "^29",
|
|
43
|
+
"typescript": "^5"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"n8n-workflow": "*"
|
|
47
|
+
},
|
|
48
|
+
"jest": {
|
|
49
|
+
"preset": "ts-jest",
|
|
50
|
+
"testEnvironment": "node",
|
|
51
|
+
"testMatch": [
|
|
52
|
+
"**/__tests__/**/*.test.ts"
|
|
53
|
+
],
|
|
54
|
+
"moduleNameMapper": {
|
|
55
|
+
"^n8n-workflow$": "<rootDir>/node_modules/n8n-workflow"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=18"
|
|
60
|
+
},
|
|
61
|
+
"repository": {
|
|
62
|
+
"type": "git",
|
|
63
|
+
"url": "https://github.com/growsales-ai/n8n-nodes-orchestrator-agent"
|
|
64
|
+
},
|
|
65
|
+
"author": "Growsales AI <growsales.ai@gmail.com>",
|
|
66
|
+
"homepage": "https://github.com/growsales-ai/n8n-nodes-orchestrator-agent"
|
|
67
|
+
}
|