Skip to content

Commit 325e055

Browse files
feat(n8n): CascadeFlow Agent node + model highlighting (#102)
* feat(n8n): add CascadeFlow Agent node * fix(n8n): lazy-load models to highlight actually used nodes * chore(ci): fix python formatting/lint (black+ruff) * test(n8n): add agent executor tests + run n8n tests in CI * chore(ci): pin ruff + sync import sorting * docs(n8n): remove outdated defaults + delete planning docs * fix: resolve duplicate ruff per-file ignores * test(ci): stabilize proxy concurrency test on macos
1 parent 59a126b commit 325e055

20 files changed

Lines changed: 943 additions & 119 deletions

.github/workflows/test.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ jobs:
143143
- name: Lint n8n package
144144
run: pnpm --filter @cascadeflow/n8n-nodes-cascadeflow lint
145145

146+
- name: Smoke load built n8n nodes
147+
run: |
148+
node -e "require('./packages/integrations/n8n/dist/nodes/LmChatCascadeFlow/LmChatCascadeFlow.node.js')"
149+
node -e "require('./packages/integrations/n8n/dist/nodes/CascadeFlowAgent/CascadeFlowAgent.node.js')"
150+
151+
- name: Test n8n package
152+
run: pnpm --filter @cascadeflow/n8n-nodes-cascadeflow test
153+
146154
# Python Code Quality
147155
lint-python:
148156
name: Python Code Quality
@@ -164,7 +172,8 @@ jobs:
164172
# Pin Black to the last version that supports Python 3.9.
165173
# The repo supports Python >=3.9, and newer Black releases may format
166174
# differently (or drop 3.9), causing CI-only formatting failures.
167-
pip install "black==25.11.0" ruff mypy types-PyYAML
175+
# Pin Ruff to avoid CI-only lint drift as Ruff evolves.
176+
pip install "black==25.11.0" "ruff==0.15.0" mypy types-PyYAML
168177
169178
- name: Check formatting with Black
170179
run: black --check cascadeflow tests examples

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ cascadeflow is a **Language Model sub-node** that connects two AI Chat Model nod
370370

371371
- ✅ Works with any AI Chat Model node (OpenAI, Anthropic, Ollama, Azure, etc.)
372372
- ✅ Mix providers (e.g., Ollama drafter + GPT-4o verifier)
373+
- ✅ Includes a CascadeFlow Agent node for tool-based agent workflows (drafter/verifier + tools + trace)
373374
- ✅ Real-time flow visualization in Logs tab
374375
- ✅ Detailed metrics: confidence scores, latency, cost savings
375376

docs/guides/n8n_integration.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ cascadeflow is a **Language Model sub-node** that sits between your AI model nod
7878
**Flexible** - Use any combination of models from different providers
7979
**Universal** - Compatible with OpenAI, Anthropic, Ollama, Azure, Google, and more
8080

81-
> **ℹ️ 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.
81+
> **ℹ️ 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.
8282
8383
---
8484

@@ -142,7 +142,7 @@ First, add and configure two AI Chat Model nodes in your workflow:
142142
1. Add a **Basic LLM Chain** or **Chain** node
143143
2. Connect the cascadeflow node to it (Model input)
144144
3. Configure your chain as usual
145-
4. **Note:** Does not work with AI Agent nodes (n8n limitation)
145+
4. For agent workflows, use the **CascadeFlow Agent** node (connect tools to its `Tools` input).
146146

147147
### Step 4: Execute and View Results
148148

@@ -160,7 +160,7 @@ First, add and configure two AI Chat Model nodes in your workflow:
160160
│ gpt-4o-mini │ │ cascadeflow │ ┌──────────────────┐
161161
└──────────────────┘ │ Node │──────►│ Basic LLM Chain │
162162
│ │ │ │
163-
┌──────────────────┐ │ Threshold: 0.7 │ └──────────────────┘
163+
┌──────────────────┐ │ Threshold: 0.4 │ └──────────────────┘
164164
│ OpenAI Model │──────►│ │
165165
│ gpt-4o │ └──────────────────┘
166166
└──────────────────┘
@@ -185,11 +185,16 @@ The cascadeflow node has **two inputs** that accept AI Language Model connection
185185

186186
### Quality Threshold (0-1)
187187

188-
Controls how aggressively to accept drafter responses:
188+
Controls how aggressively to accept drafter responses when **Use Complexity Thresholds** is disabled.
189189

190-
- **0.5-0.6**: Very aggressive (maximum cost savings, ~80-90% acceptance)
191-
- **0.7** (default): Balanced (good quality + savings, ~70-80% acceptance)
192-
- **0.8-0.9**: Conservative (highest quality, ~50-60% acceptance)
190+
Defaults to **0.4** to match the `simple` tier in CascadeFlow's default per-complexity thresholds.
191+
192+
If you enable **Use Complexity Thresholds** (default), acceptance is driven by:
193+
- trivial: 0.25
194+
- simple: 0.4
195+
- moderate: 0.55
196+
- hard: 0.7
197+
- expert: 0.8
193198

194199
Lower threshold = more cost savings, higher threshold = better quality assurance.
195200

@@ -292,7 +297,7 @@ cascadeflow provides detailed logging of every cascade decision directly in n8n'
292297

293298
The logs provide complete visibility into the cascade decision-making process, showing exactly which path was taken for each request.
294299

295-
> **ℹ️ 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.
300+
> **ℹ️ 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`.
296301
297302
---
298303

@@ -329,7 +334,7 @@ The logs provide complete visibility into the cascade decision-making process, s
329334
**Configuration:**
330335
- Drafter: Claude 3.5 Haiku
331336
- Verifier: Claude 3.5 Sonnet
332-
- Quality Threshold: 0.75
337+
- Quality Threshold (if complexity thresholds are disabled): 0.75
333338

334339
---
335340

@@ -396,7 +401,7 @@ The logs provide complete visibility into the cascade decision-making process, s
396401
**Configuration:**
397402
- Drafter: Ollama qwen2.5:3b (local, free)
398403
- Verifier: GPT-4o (cloud)
399-
- Quality Threshold: 0.7
404+
- Quality Threshold (if complexity thresholds are disabled): 0.7
400405
- Savings: ~99% on drafter calls
401406

402407
---
@@ -503,6 +508,7 @@ You can connect models from different providers:
503508

504509
### 5. Use Different Thresholds for Different Use Cases
505510

511+
If you disable **Use Complexity Thresholds**, you can tune **Quality Threshold** per workflow:
506512
- **Customer support**: 0.75 (prioritize quality)
507513
- **Content drafts**: 0.6 (prioritize speed/cost)
508514
- **Code review**: 0.7 (balance)
@@ -517,7 +523,7 @@ You can connect models from different providers:
517523
```
518524
Drafter: Claude 3.5 Haiku
519525
Verifier: GPT-4o
520-
Quality Threshold: 0.7
526+
Use Complexity Thresholds: enabled (default)
521527
Expected Savings: ~73% average
522528
Why: Haiku's fast drafts + GPT-4o's reasoning
523529
```
@@ -527,7 +533,7 @@ Why: Haiku's fast drafts + GPT-4o's reasoning
527533
```
528534
Drafter: GPT-4o-mini
529535
Verifier: GPT-4o
530-
Quality Threshold: 0.7
536+
Use Complexity Thresholds: enabled (default)
531537
Expected Savings: ~85% average
532538
Why: Both from same provider, excellent efficiency
533539
```
@@ -547,7 +553,7 @@ Why: Consistent Anthropic quality
547553
```
548554
Drafter: Ollama qwen2.5:3b (local, free)
549555
Verifier: GPT-4o (cloud)
550-
Quality Threshold: 0.7
556+
Use Complexity Thresholds: enabled (default)
551557
Expected Savings: ~99% on accepted drafts
552558
Note: Requires Ollama installed locally
553559
```
@@ -574,11 +580,11 @@ Note: Requires Ollama installed locally
574580

575581
### Issue: "This node cannot be connected" when connecting to AI Agent
576582

577-
**Solution:** This is expected. cascadeflow does **not work with AI Agent nodes** because n8n only allows whitelisted models for Agent inputs. Use cascadeflow with:
583+
**Solution:** Use the **CascadeFlow Agent** node for agent workflows. Use the **CascadeFlow (Model)** node for Chain/LLM workflows.
578584
- ✅ Basic LLM Chain
579585
- ✅ Chain
580586
- ✅ Other nodes that accept Language Model connections
581-
- ❌ AI Agent (not supported)
587+
- ✅ CascadeFlow Agent (agent workflows)
582588

583589
### Issue: Always escalating to verifier
584590

packages/integrations/n8n/N8N_COMPATIBILITY_VALIDATION.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
- **Implementation:** ✅ VALIDATED
4848
- Dynamic import of `@cascadeflow/ml` with try/catch
4949
- Falls back to simple validation if unavailable
50-
- Configurable via node properties (boolean toggle)
5150
- Does not crash n8n if package missing
5251
- **N8N Compatibility:** ✅ Full compatibility - graceful degradation verified
5352

@@ -89,9 +88,8 @@
8988
- **Status:** ✅ VALIDATED
9089
- **Properties Added:**
9190
1. `qualityThreshold` (number, 0-1): Quality threshold configuration ✅
92-
2. `useSemanticValidation` (boolean): Semantic ML validation toggle ✅
93-
3. `useAlignmentScoring` (boolean): Query-response alignment toggle ✅
94-
4. `useComplexityRouting` (boolean): Complexity-based routing toggle ✅
91+
2. `useAlignmentScoring` (boolean): Query-response alignment toggle ✅
92+
3. `useComplexityRouting` (boolean): Complexity-based routing toggle ✅
9593
- **N8N Compatibility:** ✅ All properties use standard n8n types (number, boolean)
9694

9795
### Metadata in Response
@@ -165,6 +163,7 @@
165163
- ✅ Optional dependencies handled gracefully (no hard failure when `@cascadeflow/core` is absent).
166164

167165
### Agent Validation
166+
-`CascadeFlow Agent` provides an `ai_agent` output for n8n agent workflows.
168167
- ✅ Cascade routing works with n8n's dual-input model graph (drafter + verifier).
169168
- ✅ Lazy-loading for verifier model remains intact for performance.
170169
- ✅ Domain routing and noted limitations are documented and stable.

packages/integrations/n8n/README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The cascadeflow node is a **Language Model sub-node** that sits between your AI
6161

6262
**Result:** 70-80% of queries accept the drafter, saving 40-85% on costs.
6363

64-
> **ℹ️ 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.
6565
6666
## Installation
6767

@@ -99,12 +99,12 @@ RUN cd /usr/local/lib/node_modules/n8n && npm install @cascadeflow/n8n-nodes-cas
9999
2. **Add the cascadeflow node**
100100
- Connect the drafter model to the **Drafter** input
101101
- Connect the verifier model to the **Verifier** input
102-
- Adjust the **Quality Threshold** (default: 0.7)
102+
- Optionally adjust the **Quality Threshold** (default: 0.4, and per-complexity thresholds are enabled by default)
103103

104104
3. **Connect to a Chain node**
105105
- The cascadeflow node outputs a Language Model connection
106106
- Connect it to nodes that accept AI models (Basic LLM Chain, Chain, etc.)
107-
- **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).
108108

109109
### Example Workflow
110110

@@ -120,7 +120,7 @@ RUN cd /usr/local/lib/node_modules/n8n && npm install @cascadeflow/n8n-nodes-cas
120120
│ gpt-4o-mini │ │ cascadeflow │ ┌──────────────────┐
121121
└──────────────────┘ │ Node │──────►│ Basic LLM Chain │
122122
│ │ │ │
123-
┌──────────────────┐ │ Threshold: 0.7 │ └──────────────────┘
123+
┌──────────────────┐ │ Threshold: 0.4 │ └──────────────────┘
124124
│ OpenAI Model │──────►│ │
125125
│ gpt-4o │ └──────────────────┘
126126
└──────────────────┘
@@ -132,11 +132,16 @@ RUN cd /usr/local/lib/node_modules/n8n && npm install @cascadeflow/n8n-nodes-cas
132132

133133
#### Quality Threshold (0-1)
134134

135-
Controls how aggressively to accept drafter responses:
135+
Controls how aggressively to accept drafter responses when **Use Complexity Thresholds** is disabled.
136136

137-
- **0.5-0.6**: Very aggressive (maximum cost savings, ~80-90% acceptance)
138-
- **0.7** (default): Balanced (good quality + savings, ~70-80% acceptance)
139-
- **0.8-0.9**: Conservative (highest quality, ~50-60% acceptance)
137+
Defaults to **0.4** to match the `simple` tier in CascadeFlow's default per-complexity thresholds.
138+
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
140145

141146
Lower threshold = more cost savings, higher threshold = better quality assurance.
142147

@@ -400,7 +405,7 @@ Note: Requires Ollama installed locally
400405

401406
The logs provide complete visibility into the cascade decision-making process, showing exactly which path was taken for each request.
402407

403-
> **ℹ️ 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`.
404409
405410
## Compatibility
406411

@@ -433,11 +438,11 @@ The logs provide complete visibility into the cascade decision-making process, s
433438

434439
### Issue: "This node cannot be connected" when connecting to AI Agent
435440

436-
**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.
437442
- ✅ Basic LLM Chain
438443
- ✅ Chain
439444
- ✅ Other nodes that accept Language Model connections
440-
- ❌ AI Agent (not supported)
445+
- ✅ CascadeFlow Agent (agent workflows)
441446

442447
### Issue: Always escalating to verifier
443448

0 commit comments

Comments
 (0)