@cascadeflow/n8n-nodes-cascadeflow 0.6.6 → 0.7.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.
Files changed (27) hide show
  1. package/README.md +97 -37
  2. package/dist/nodes/CascadeFlowAgent/CascadeFlowAgent.node.d.ts +34 -0
  3. package/dist/nodes/CascadeFlowAgent/CascadeFlowAgent.node.d.ts.map +1 -0
  4. package/dist/nodes/CascadeFlowAgent/CascadeFlowAgent.node.js +466 -0
  5. package/dist/nodes/CascadeFlowAgent/CascadeFlowAgent.node.js.map +1 -0
  6. package/dist/nodes/CascadeFlowAgent/__tests__/cascadeflow-agent-executor.test.d.ts +2 -0
  7. package/dist/nodes/CascadeFlowAgent/__tests__/cascadeflow-agent-executor.test.d.ts.map +1 -0
  8. package/dist/nodes/CascadeFlowAgent/__tests__/cascadeflow-agent-executor.test.js +98 -0
  9. package/dist/nodes/CascadeFlowAgent/__tests__/cascadeflow-agent-executor.test.js.map +1 -0
  10. package/dist/nodes/CascadeFlowAgent/cascadeflow.svg +15 -0
  11. package/dist/nodes/LmChatCascadeFlow/LmChatCascadeFlow.node.d.ts +100 -0
  12. package/dist/nodes/LmChatCascadeFlow/LmChatCascadeFlow.node.d.ts.map +1 -1
  13. package/dist/nodes/LmChatCascadeFlow/LmChatCascadeFlow.node.js +432 -303
  14. package/dist/nodes/LmChatCascadeFlow/LmChatCascadeFlow.node.js.map +1 -1
  15. package/dist/nodes/LmChatCascadeFlow/__tests__/lm-chat-cascadeflow-node.test.d.ts +2 -0
  16. package/dist/nodes/LmChatCascadeFlow/__tests__/lm-chat-cascadeflow-node.test.d.ts.map +1 -0
  17. package/dist/nodes/LmChatCascadeFlow/__tests__/lm-chat-cascadeflow-node.test.js +59 -0
  18. package/dist/nodes/LmChatCascadeFlow/__tests__/lm-chat-cascadeflow-node.test.js.map +1 -0
  19. package/dist/nodes/LmChatCascadeFlow/cascade-metadata.d.ts +27 -0
  20. package/dist/nodes/LmChatCascadeFlow/cascade-metadata.d.ts.map +1 -0
  21. package/dist/nodes/LmChatCascadeFlow/cascade-metadata.js +21 -0
  22. package/dist/nodes/LmChatCascadeFlow/cascade-metadata.js.map +1 -0
  23. package/dist/nodes/LmChatCascadeFlow/config.d.ts +41 -0
  24. package/dist/nodes/LmChatCascadeFlow/config.d.ts.map +1 -0
  25. package/dist/nodes/LmChatCascadeFlow/config.js +87 -0
  26. package/dist/nodes/LmChatCascadeFlow/config.js.map +1 -0
  27. package/package.json +17 -12
package/README.md CHANGED
@@ -16,7 +16,9 @@
16
16
 
17
17
  </div>
18
18
 
19
- **Intelligent AI model cascading for n8n workflows.**
19
+ **Intelligent AI model cascading for n8n workflows with domain understanding.**
20
+
21
+ ![cascadeflow Domain Routing](../../../.github/assets/n8n-CF-domains.jpg)
20
22
 
21
23
  This is an n8n community node that brings cascadeflow's intelligent AI model cascading to n8n workflows.
22
24
 
@@ -26,9 +28,9 @@ This is an n8n community node that brings cascadeflow's intelligent AI model cas
26
28
 
27
29
  ## How It Works
28
30
 
29
- The CascadeFlow node is a **Language Model sub-node** that sits between your AI models and downstream n8n nodes (like Basic LLM Chain, Chain, or any node that accepts Language Model inputs):
31
+ The cascadeflow node is a **Language Model sub-node** that sits between your AI models and downstream n8n nodes (like Basic LLM Chain, Chain, or any node that accepts Language Model inputs):
30
32
 
31
- ![CascadeFlow n8n Workflow](../../../.github/assets/n8n-CF.png)
33
+ ![cascadeflow n8n Workflow](../../../.github/assets/n8n-CF.png)
32
34
 
33
35
  **Architecture:**
34
36
 
@@ -39,7 +41,7 @@ The CascadeFlow node is a **Language Model sub-node** that sits between your AI
39
41
  └──────┬──────┘
40
42
 
41
43
  ├──────► ┌──────────────┐
42
- │ │ CascadeFlow
44
+ │ │ cascadeflow
43
45
  │ │ Node │ ────► ┌──────────────┐
44
46
  │ └──────────────┘ │ Basic Chain │
45
47
  ├──────► Quality checks │ Chain │
@@ -53,13 +55,13 @@ The CascadeFlow node is a **Language Model sub-node** that sits between your AI
53
55
 
54
56
  **Flow:**
55
57
  1. Query goes to cheap drafter model first
56
- 2. CascadeFlow validates the response quality
58
+ 2. cascadeflow validates the response quality
57
59
  3. If quality passes → return drafter response (fast + cheap ✅)
58
60
  4. If quality fails → escalate to verifier model (slower but accurate ⚠️)
59
61
 
60
62
  **Result:** 70-80% of queries accept the drafter, saving 40-85% on costs.
61
63
 
62
- > **ℹ️ Note:** CascadeFlow works with n8n Chain nodes but **not with AI Agent nodes**, as n8n only allows whitelisted models for Agent inputs. Use with Basic LLM Chain, Chain, or other nodes that accept Language Model connections.
64
+ > **ℹ️ Note:** Use **CascadeFlow (Model)** with n8n Chain/LLM nodes, and **CascadeFlow Agent** for agent workflows (tool calling + multi-step). The Agent node adds trace metadata and supports tool routing.
63
65
 
64
66
  ## Installation
65
67
 
@@ -94,15 +96,15 @@ RUN cd /usr/local/lib/node_modules/n8n && npm install @cascadeflow/n8n-nodes-cas
94
96
  - Configure one as your **drafter** (cheap model like `gpt-4o-mini` or `claude-3-5-haiku-20241022`)
95
97
  - Configure one as your **verifier** (powerful model like `gpt-4o` or `claude-3-5-sonnet-20241022`)
96
98
 
97
- 2. **Add the CascadeFlow node**
99
+ 2. **Add the cascadeflow node**
98
100
  - Connect the drafter model to the **Drafter** input
99
101
  - Connect the verifier model to the **Verifier** input
100
- - Adjust the **Quality Threshold** (default: 0.7)
102
+ - Optionally adjust the **Quality Threshold** (default: 0.4, and per-complexity thresholds are enabled by default)
101
103
 
102
104
  3. **Connect to a Chain node**
103
- - The CascadeFlow node outputs a Language Model connection
105
+ - The cascadeflow node outputs a Language Model connection
104
106
  - Connect it to nodes that accept AI models (Basic LLM Chain, Chain, etc.)
105
- - **Note:** Does not work with AI Agent nodes (n8n limitation)
107
+ - For agent workflows, use the **CascadeFlow Agent** node (connect tools to its `Tools` input).
106
108
 
107
109
  ### Example Workflow
108
110
 
@@ -115,10 +117,10 @@ RUN cd /usr/local/lib/node_modules/n8n && npm install @cascadeflow/n8n-nodes-cas
115
117
  v
116
118
  ┌──────────────────┐ ┌──────────────────┐
117
119
  │ OpenAI Model │──────►│ │
118
- │ gpt-4o-mini │ │ CascadeFlow │ ┌──────────────────┐
120
+ │ gpt-4o-mini │ │ cascadeflow │ ┌──────────────────┐
119
121
  └──────────────────┘ │ Node │──────►│ Basic LLM Chain │
120
122
  │ │ │ │
121
- ┌──────────────────┐ │ Threshold: 0.7 │ └──────────────────┘
123
+ ┌──────────────────┐ │ Threshold: 0.4 │ └──────────────────┘
122
124
  │ OpenAI Model │──────►│ │
123
125
  │ gpt-4o │ └──────────────────┘
124
126
  └──────────────────┘
@@ -130,28 +132,86 @@ RUN cd /usr/local/lib/node_modules/n8n && npm install @cascadeflow/n8n-nodes-cas
130
132
 
131
133
  #### Quality Threshold (0-1)
132
134
 
133
- Controls how aggressively to accept drafter responses:
135
+ Controls how aggressively to accept drafter responses when **Use Complexity Thresholds** is disabled.
136
+
137
+ Defaults to **0.4** to match the `simple` tier in CascadeFlow's default per-complexity thresholds.
134
138
 
135
- - **0.5-0.6**: Very aggressive (maximum cost savings, ~80-90% acceptance)
136
- - **0.7** (default): Balanced (good quality + savings, ~70-80% acceptance)
137
- - **0.8-0.9**: Conservative (highest quality, ~50-60% acceptance)
139
+ If you enable **Use Complexity Thresholds** (default), acceptance is driven by:
140
+ - trivial: 0.25
141
+ - simple: 0.4
142
+ - moderate: 0.55
143
+ - hard: 0.7
144
+ - expert: 0.8
138
145
 
139
146
  Lower threshold = more cost savings, higher threshold = better quality assurance.
140
147
 
148
+ ## Multi-Domain Cascading (Optional)
149
+
150
+ cascadeflow supports **intelligent domain-specific cascading** - automatically detecting the type of query and routing it to a specialized model for that domain.
151
+
152
+ ### How It Works
153
+
154
+ 1. **Enable Domain Cascading** in the node settings
155
+ 2. **Toggle individual domains** you want to support
156
+ 3. **Connect domain-specific models** to the new input ports that appear
157
+
158
+ When a query comes in, cascadeflow:
159
+ 1. Detects the domain (e.g., "Write a Python function" → Code domain)
160
+ 2. Routes to the specialized model for that domain (if connected)
161
+ 3. Falls back to drafter → verifier cascade if no domain model is available
162
+
163
+ ### Supported Domains
164
+
165
+ | Domain | Description | Example Queries |
166
+ |--------|-------------|-----------------|
167
+ | **Code** | Programming, debugging, code generation | "Write a Python function...", "Debug this code..." |
168
+ | **Math** | Mathematical reasoning, calculations, proofs | "Solve this equation...", "Prove that..." |
169
+ | **Data** | Data analysis, statistics, pandas/SQL | "Analyze this dataset...", "Write a SQL query..." |
170
+ | **Creative** | Creative writing, stories, poetry | "Write a short story...", "Compose a poem..." |
171
+ | **Legal** | Legal documents, contracts, regulations | "Draft a contract...", "Explain this law..." |
172
+ | **Medical** | Healthcare, medical knowledge, clinical | "What are the symptoms of...", "Explain this diagnosis..." |
173
+ | **Financial** | Finance, accounting, investment analysis | "Analyze this stock...", "Calculate ROI..." |
174
+ | **Science** | Scientific knowledge, research, experiments | "Explain quantum...", "How does photosynthesis..." |
175
+
176
+ ### Setup Example
177
+
178
+ ```
179
+ ┌──────────────────┐
180
+ │ Claude Haiku │──► Drafter (default cheap model)
181
+ └──────────────────┘
182
+ ┌──────────────────┐
183
+ │ GPT-4o │──► Verifier (default powerful model)
184
+ └──────────────────┘
185
+ ┌──────────────────┐ ┌──────────────────┐
186
+ │ DeepSeek Coder │──► Code │ │
187
+ └──────────────────┘ │ │
188
+ ┌──────────────────┐ │ cascadeflow │──► Chain
189
+ │ Qwen Math │──► Math │ Node │
190
+ └──────────────────┘ │ │
191
+ ┌──────────────────┐ │ │
192
+ │ Claude Sonnet │──► Legal│ │
193
+ └──────────────────┘ └──────────────────┘
194
+ ```
195
+
196
+ ### When to Use Domain Cascading
197
+
198
+ - **Use it when**: You have domain-specific models that excel in certain areas (e.g., DeepSeek for code, specialized medical models)
199
+ - **Skip it when**: Your drafter/verifier combination handles all domains well enough
200
+
141
201
  ## Flow Visualization
142
202
 
143
203
  ### Viewing Cascade Decisions in Real-Time
144
204
 
145
- CascadeFlow provides detailed logging of every cascade decision in n8n's UI:
205
+ cascadeflow provides detailed logging of every cascade decision in n8n's UI:
146
206
 
147
- 1. **Execute your workflow** with the CascadeFlow node
148
- 2. **Click on the downstream Chain node** after execution (the node that receives CascadeFlow output)
207
+ 1. **Execute your workflow** with the cascadeflow node
208
+ 2. **Click on the downstream Chain node** after execution (the node that receives cascadeflow output)
149
209
  3. **Navigate to the "Logs" tab**
150
210
 
151
211
  You'll see detailed flow information like:
152
212
 
153
213
  ```
154
- 🎯 CascadeFlow: Trying drafter model...
214
+ 🎯 cascadeflow: Trying drafter model...
155
215
  📊 Quality validation: confidence=0.85, method=heuristic
156
216
  🎯 Alignment: 0.82
157
217
 
@@ -170,7 +230,7 @@ You'll see detailed flow information like:
170
230
  Or when escalating:
171
231
 
172
232
  ```
173
- 🎯 CascadeFlow: Trying drafter model...
233
+ 🎯 cascadeflow: Trying drafter model...
174
234
  📊 Quality validation: confidence=0.62, method=heuristic
175
235
 
176
236
  ┌────────────────────────────────────────────────┐
@@ -241,7 +301,7 @@ Note: Requires Ollama installed locally
241
301
 
242
302
  **Example: Claude Haiku + GPT-4o**
243
303
 
244
- | Scenario | Traditional (GPT-4o only) | CascadeFlow (Haiku + GPT-4o) | Savings |
304
+ | Scenario | Traditional (GPT-4o only) | cascadeflow (Haiku + GPT-4o) | Savings |
245
305
  |----------|---------------------------|------------------------------|---------|
246
306
  | Simple Q&A (75% acceptance) | $0.0025 | $0.0008 | 68% |
247
307
  | Complex query (25% escalation) | $0.0025 | $0.0025 | 0% (correctly escalated) |
@@ -249,12 +309,12 @@ Note: Requires Ollama installed locally
249
309
 
250
310
  **Monthly savings (10,000 queries):**
251
311
  - Traditional (GPT-4o only): $25.00
252
- - CascadeFlow (Haiku + GPT-4o): $11.50
312
+ - cascadeflow (Haiku + GPT-4o): $11.50
253
313
  - **You save: $13.50/month** (54% savings)
254
314
 
255
315
  **Monthly savings (100,000 queries):**
256
316
  - Traditional (GPT-4o only): $250.00
257
- - CascadeFlow (Haiku + GPT-4o): $115.00
317
+ - cascadeflow (Haiku + GPT-4o): $115.00
258
318
  - **You save: $135.00/month** (54% savings)
259
319
 
260
320
  ## Example Workflows
@@ -270,7 +330,7 @@ Note: Requires Ollama installed locally
270
330
  v
271
331
  ┌─────────────────────────────────────┐
272
332
  │ Claude Haiku ────┐ │
273
- │ │ CascadeFlow │ ┌──────────────────┐
333
+ │ │ cascadeflow │ ┌──────────────────┐
274
334
  │ Claude Sonnet ───┴─► Node │──────►│ Basic Chain │
275
335
  └─────────────────────────────────────┘ │ (responds) │
276
336
  └──────┬───────────┘
@@ -292,7 +352,7 @@ Note: Requires Ollama installed locally
292
352
  v
293
353
  ┌────────────────────────────────────────┐
294
354
  │ GPT-4o-mini ─────┐ │
295
- │ │ CascadeFlow │ ┌──────────────────┐
355
+ │ │ cascadeflow │ ┌──────────────────┐
296
356
  │ GPT-4o ──────────┴─► Node │──────►│ Basic Chain │
297
357
  └────────────────────────────────────────┘ │ (generates) │
298
358
  └──────┬───────────┘
@@ -314,7 +374,7 @@ Note: Requires Ollama installed locally
314
374
  v
315
375
  ┌─────────────────────────────────────┐
316
376
  │ Ollama qwen2.5 ──┐ │
317
- │ │ CascadeFlow │ ┌──────────────────┐
377
+ │ │ cascadeflow │ ┌──────────────────┐
318
378
  │ GPT-4o ──────────┴─► Node │──────►│ Basic Chain │
319
379
  └─────────────────────────────────────┘ │ (reviews code) │
320
380
  └──────┬───────────┘
@@ -334,7 +394,7 @@ Note: Requires Ollama installed locally
334
394
  **To see the actual cascade flow and which model was used:**
335
395
 
336
396
  1. Execute your workflow
337
- 2. Click on the downstream Chain node after execution (the node that receives CascadeFlow output)
397
+ 2. Click on the downstream Chain node after execution (the node that receives cascadeflow output)
338
398
  3. Navigate to the **"Logs"** tab
339
399
  4. You'll see detailed flow information showing:
340
400
  - Whether the drafter was accepted or escalated to verifier
@@ -345,7 +405,7 @@ Note: Requires Ollama installed locally
345
405
 
346
406
  The logs provide complete visibility into the cascade decision-making process, showing exactly which path was taken for each request.
347
407
 
348
- > **ℹ️ Important:** CascadeFlow does **not work with AI Agent nodes** in n8n, as n8n only allows whitelisted models for Agent inputs. Use with Basic LLM Chain, Chain, or other nodes that accept Language Model connections.
408
+ > **ℹ️ Important:** If you need agent-style tool orchestration, use the **CascadeFlow Agent** node. It is designed for n8n agent flows and records a step-by-step trace in `response_metadata.cf.trace`.
349
409
 
350
410
  ## Compatibility
351
411
 
@@ -372,17 +432,17 @@ The logs provide complete visibility into the cascade decision-making process, s
372
432
 
373
433
  **Solution:**
374
434
  1. Make sure your workflow has executed successfully
375
- 2. Click on the **Chain node that receives the CascadeFlow output** (Basic LLM Chain, Chain, etc.)
435
+ 2. Click on the **Chain node that receives the cascadeflow output** (Basic LLM Chain, Chain, etc.)
376
436
  3. Navigate to the **"Logs"** tab (not the "Output" tab)
377
- 4. The logs appear in the downstream node, not the CascadeFlow node itself
437
+ 4. The logs appear in the downstream node, not the cascadeflow node itself
378
438
 
379
439
  ### Issue: "This node cannot be connected" when connecting to AI Agent
380
440
 
381
- **Solution:** This is expected. CascadeFlow does **not work with AI Agent nodes** because n8n only allows whitelisted models for Agent inputs. Use CascadeFlow with:
441
+ **Solution:** Use the **CascadeFlow Agent** node for agent workflows. Use the **CascadeFlow (Model)** node for Chain/LLM workflows.
382
442
  - ✅ Basic LLM Chain
383
443
  - ✅ Chain
384
444
  - ✅ Other nodes that accept Language Model connections
385
- - AI Agent (not supported)
445
+ - CascadeFlow Agent (agent workflows)
386
446
 
387
447
  ### Issue: Always escalating to verifier
388
448
 
@@ -404,11 +464,11 @@ The logs provide complete visibility into the cascade decision-making process, s
404
464
 
405
465
  ## Version History
406
466
 
407
- ### v0.6.6 (Latest)
467
+ ### v0.6.7 (Latest)
408
468
 
409
- - **Removed semantic validation**: Disabled ML-based semantic validation to prevent out-of-memory crashes in n8n environments
410
- - **Shorter domain labels**: Domain input labels simplified (Code, Math, Data, etc.) for better readability
411
- - **Updated documentation**: Cleaned up README and version history
469
+ - **Multi-domain cascading docs**: Added documentation for 8-domain intelligent cascading
470
+ - **Removed semantic validation**: Disabled ML-based semantic validation to prevent out-of-memory crashes
471
+ - **Shorter domain labels**: Domain input labels simplified (Code, Math, Data, etc.)
412
472
 
413
473
  ### v0.6.4
414
474
 
@@ -0,0 +1,34 @@
1
+ import type { INodeType, INodeTypeDescription, ISupplyDataFunctions, SupplyData } from 'n8n-workflow';
2
+ import { CascadeChatModel } from '../LmChatCascadeFlow/LmChatCascadeFlow.node';
3
+ type ToolRoutingMode = 'cascade' | 'verifier';
4
+ export interface ToolRoutingRule {
5
+ toolName: string;
6
+ routing: ToolRoutingMode;
7
+ }
8
+ export interface ToolLike {
9
+ name?: string;
10
+ description?: string;
11
+ invoke?: (args: any) => Promise<any>;
12
+ call?: (args: any) => Promise<any>;
13
+ run?: (args: any) => Promise<any>;
14
+ }
15
+ export declare class CascadeFlowAgentExecutor {
16
+ private cascadeModel;
17
+ private maxIterations;
18
+ private toolMap;
19
+ private routingRules;
20
+ constructor(cascadeModel: CascadeChatModel, tools: ToolLike[], routingRules: ToolRoutingRule[], maxIterations: number);
21
+ private normalizeMessages;
22
+ private extractToolCalls;
23
+ private executeTool;
24
+ private resolveRouting;
25
+ private buildTraceEntry;
26
+ invoke(input: any, options?: any): Promise<any>;
27
+ stream(input: any, options?: any): AsyncGenerator<any>;
28
+ }
29
+ export declare class CascadeFlowAgent implements INodeType {
30
+ description: INodeTypeDescription;
31
+ supplyData(this: ISupplyDataFunctions): Promise<SupplyData>;
32
+ }
33
+ export {};
34
+ //# sourceMappingURL=CascadeFlowAgent.node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CascadeFlowAgent.node.d.ts","sourceRoot":"","sources":["../../../nodes/CascadeFlowAgent/CascadeFlowAgent.node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,oBAAoB,EACpB,oBAAoB,EACpB,UAAU,EACX,MAAM,cAAc,CAAC;AAQtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CA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