n8n v2 Integration Strategy (Planning Only)
Research limitations
External access to docs.n8n.io and GitHub-hosted n8n docs is blocked in this environment (HTTP 403 via proxy). This plan is based on:
- The current cascadeflow n8n node implementation and documentation in this repo.
- General knowledge of n8n’s AI/LangChain architecture.
Action required: validate all “v2 capability” claims against the official n8n v2 documentation once network access is available.
1) n8n v2 capabilities overview (to validate)
Based on n8n’s current AI/LangChain architecture (and expectations for v2), the following capabilities matter most for cascadeflow:
- AI Chat Model nodes as first-class building blocks feeding Chain / Prompt / Tools nodes.
- AI Agent nodes (LangChain-based) with tool integration and orchestration.
- Native AI nodes for prompt templating, memory, document loaders, vector stores, and agent execution.
- Model registry / provider selection surfaced via credentials and model-specific nodes.
- Execution logs + metadata for observability (request/response data, token usage, costs when available).
Validate in v2:
- Whether AI Agent nodes still restrict model inputs to a whitelist and whether custom community models can be attached.
- Whether v2 introduces a “model provider” abstraction or AI node SDK for exposing custom models/tools with richer metadata.
- Any official support for per-step cost breakdown or model routing visualization in the UI.
2) Current n8n integration (baseline)
What we have now
- Node type: Language Model sub-node that accepts Verifier and Drafter model connections, and optional domain-model inputs. This places cascadeflow between model nodes and downstream chain nodes. 【F:packages/integrations/n8n/README.md†L31-L43】【F:packages/integrations/n8n/nodes/LmChatCascadeFlow/LmChatCascadeFlow.node.ts†L12-L81】
- Agent limitation: The current node does not work with n8n AI Agent nodes due to whitelisted model restrictions. 【F:packages/integrations/n8n/README.md†L64-L67】
- Domain routing: 16 supported domains with UI toggles and per-domain routing. 【F:packages/integrations/n8n/nodes/LmChatCascadeFlow/LmChatCascadeFlow.node.ts†L12-L81】
- Observability: Detailed logs in the n8n UI show cascade decisions, confidence, cost savings, and latency breakdowns. 【F:packages/integrations/n8n/README.md†L200-L244】
Relevant core capability notes
- Alignment scoring version: TypeScript alignment scorer is based on Python v10; missing v14 improvements. 【F:packages/core/src/alignment.ts†L1-L37】
3) Gap analysis (current vs needed)
A) n8n v2 capability gaps (TBD by validation)
Agent compatibility
- Current: Not supported due to whitelist. 【F:packages/integrations/n8n/README.md†L64-L67】
- Needed: A pathway for cascadeflow to participate in AI Agent workflows (either as a model or as a tool/agent node).
Model metadata visibility
- Current: Logs show selected model path and costs, but not a standardized UI indicator in node connections. 【F:packages/integrations/n8n/README.md†L200-L244】
- Needed: UI-level “model used” indicator + cost breakdown at execution step/trace granularity.
Native AI node integration
- Current: Works as Language Model sub-node in Chain nodes, not native AI Agent nodes. 【F:packages/integrations/n8n/README.md†L64-L67】
- Needed: Seamless compatibility with native AI nodes and LangChain agents (see section 6).
B) Python SDK feature gaps for n8n (priority list)
Feature gaps called out in the request, with current TS status:
Alignment scorer v14
- Current TS: v10 in TypeScript. 【F:packages/core/src/alignment.ts†L1-L37】
- Gap: Port Python v14 features and thresholds to TS.
All 16 domains support
- Current n8n: 16 domain constants exist, but only a subset exposed as toggles in UI (e.g., code, math, data, creative, legal, medical, financial, science). 【F:packages/integrations/n8n/nodes/LmChatCascadeFlow/LmChatCascadeFlow.node.ts†L12-L81】【F:packages/integrations/n8n/nodes/LmChatCascadeFlow/LmChatCascadeFlow.node.ts†L988-L1068】
- Gap: Surface full 16-domain toggles + descriptions and allow connections for all.
Confidence thresholds (per complexity tier + domain-specific)
- Current TS: Supported in core; n8n node exposes a single quality threshold and optional domain thresholds. 【F:packages/integrations/n8n/README.md†L124-L144】【F:packages/integrations/n8n/nodes/LmChatCascadeFlow/LmChatCascadeFlow.node.ts†L618-L623】
- Gap: Expose full confidence-threshold table and complexity-aware routing in UI.
Cost tracking
- Current: Logs show cost savings; cost tracking is in TS core and LangChain integration, but n8n does not surface a standardized per-model cost panel. 【F:packages/integrations/n8n/README.md†L200-L244】
- Gap: Add UI surfaced fields / JSON metadata for downstream nodes to read cost breakdowns.
4) Architecture options (model vs agent vs both)
Option A — “Model” node only (current pattern)
Description: Continue exposing cascadeflow as a Language Model node, used by Chain and non-agent AI nodes.
Pros
- Compatible with current n8n architecture (sub-node model connector). 【F:packages/integrations/n8n/README.md†L31-L43】
- Minimal disruption; aligns with current implementation.
Cons
- Blocks AI Agent node usage due to model whitelist. 【F:packages/integrations/n8n/README.md†L64-L67】
- Harder to show cascade decisions beyond logs.
Option B — “Agent” node
Description: Expose cascadeflow as an AI Agent node that orchestrates drafter/verifier models internally (and optionally tools).
Pros
- First-class integration with n8n AI Agent workflows.
- Can surface cascade routing as part of agent trace (if v2 supports it).
Cons
- Requires alignment with n8n’s agent model contract and tool call expectations.
- Must implement tool interaction semantics carefully to preserve downstream agent behavior.
Option C — Both (recommended)
Description:
- Keep the Model node for Chain and generic AI nodes.
- Add an Agent node for agent workflows and tool orchestration.
Pros
- Covers all n8n AI flows (native AI nodes + agents + LangChain chains).
- Gives users choice and a migration path.
Cons
- More surface area to maintain.
Option D — “Routing service” node (non-model)
Description: A standalone node that receives text input, routes internally, and outputs text + metadata.
Pros
- Works with all n8n workflows, regardless of AI node constraints.
Cons
- Loses Language Model connector semantics (tool calls, streaming, token tracking via n8n’s LM pipeline).
5) UI/UX for model tracking & cost visibility
Goals
- Visible model used (drafter vs verifier vs domain model).
- Cost breakdown per step (drafter cost, verifier cost, total, savings).
- Cascade decision visibility (why did it escalate?).
Proposed UI/UX patterns
Execution log summary block
- Add a concise, structured log summary at end of each run:
selected_model, fallback_model, domain, confidence, threshold, costs.
- Use log formatting in n8n to enable quick scan (already partially implemented). 【F:packages/integrations/n8n/README.md†L200-L244】
Output metadata fields
- Include JSON metadata in the node output data structure:
cf.model_used, cf.domain, cf.confidence, cf.costs, cf.savings.
- Downstream nodes can render in UI or export.
UI indicators (if v2 supports)
- Use node badges for “Drafter” vs “Verifier” used.
- Link to a “Cascade Trace” panel in execution view.
6) Working with native AI nodes and LangChain agents
A) Native AI nodes
- Model node path: Keep
LmChatCascadeFlow as the sub-node for AI Chat Model inputs.
- Compatibility with prompt/chain nodes: Continue ensuring it meets
BaseChatModel expectations. 【F:packages/integrations/n8n/N8N_COMPATIBILITY_VALIDATION.md†L17-L43】
B) LangChain agents
- Short term: Provide a “routing service” node alternative for agent workflows that can accept text input and return text + metadata.
- Long term: Implement a dedicated AI Agent node, if v2 provides an extension point for community agent nodes.
C) Dual-mode strategy (if v2 supports)
- Add a Model node for LM workflows.
- Add an Agent node for agent workflows with tool routing.
- Add a shared config for model/cost/routing settings to keep consistency.
7) Implementation roadmap (planning only)
Phase 0 — Validation & discovery (1-2 weeks)
- Validate n8n v2 AI node architecture and any SDKs/extension points.
- Confirm agent model whitelist behavior and any changes in v2.
- Identify available UI hooks for cost/trace visualization.
Phase 1 — Feature parity (2-4 weeks)
- Port alignment scorer v14 from Python to TS.
- Expose all 16 domains in n8n UI with per-domain config.
- Add per-tier confidence thresholds in node config.
- Emit structured output metadata for costs and model usage.
Phase 2 — Agent integration (3-6 weeks)
- Add cascadeflow AI Agent node (if v2 allows custom agent nodes).
- Implement tool-call compatibility and streaming behavior.
- Ensure metadata flows into agent execution traces.
Phase 3 — UX polish & docs (1-2 weeks)
- Create UI usage guide for model tracking + cost visibility.
- Update n8n integration docs with v2 capabilities and examples.
- Add sample workflows (model-only + agent + mixed).
8) Recommendation
Recommended approach: Option C (Model + Agent) with a staged rollout:
- Immediate: Improve Model node parity (alignment v14, full 16 domains, confidence thresholds, cost metadata).
- Short term: Add a routing service node as a stopgap for AI Agent workflows.
- Mid term: Implement a dedicated AI Agent node once n8n v2 extension points are confirmed.
This ensures cascadeflow remains the best-in-class model routing solution for both traditional chain workflows and agent-based flows as n8n v2 evolves.
1---2name: 412-n8n-v2-integration-plan-a9bba2df3description: n8n v2 Integration Strategy (Planning Only)4---5# n8n v2 Integration Strategy (Planning Only)67## Research limitations89External access to `docs.n8n.io` and GitHub-hosted n8n docs is blocked in this environment (HTTP 403 via proxy). This plan is based on:1011- The current cascadeflow n8n node implementation and documentation in this repo.12- General knowledge of n8n’s AI/LangChain architecture.1314**Action required:** validate all “v2 capability” claims against the official n8n v2 documentation once network access is available.1516## 1) n8n v2 capabilities overview (to validate)1718Based on n8n’s current AI/LangChain architecture (and expectations for v2), the following capabilities matter most for cascadeflow:1920- **AI Chat Model nodes** as first-class building blocks feeding Chain / Prompt / Tools nodes.21- **AI Agent nodes** (LangChain-based) with tool integration and orchestration.22- **Native AI nodes** for prompt templating, memory, document loaders, vector stores, and agent execution.23- **Model registry / provider selection** surfaced via credentials and model-specific nodes.24- **Execution logs + metadata** for observability (request/response data, token usage, costs when available).2526**Validate in v2:**2728- Whether AI Agent nodes still restrict model inputs to a whitelist and whether custom community models can be attached.29- Whether v2 introduces a **“model provider” abstraction** or **AI node SDK** for exposing custom models/tools with richer metadata.30- Any official support for **per-step cost breakdown** or **model routing visualization** in the UI.3132## 2) Current n8n integration (baseline)3334### What we have now3536- **Node type:** Language Model sub-node that accepts **Verifier** and **Drafter** model connections, and optional domain-model inputs. This places cascadeflow between model nodes and downstream chain nodes. 【F:packages/integrations/n8n/README.md†L31-L43】【F:packages/integrations/n8n/nodes/LmChatCascadeFlow/LmChatCascadeFlow.node.ts†L12-L81】37- **Agent limitation:** The current node **does not work with n8n AI Agent nodes** due to whitelisted model restrictions. 【F:packages/integrations/n8n/README.md†L64-L67】38- **Domain routing:** 16 supported domains with UI toggles and per-domain routing. 【F:packages/integrations/n8n/nodes/LmChatCascadeFlow/LmChatCascadeFlow.node.ts†L12-L81】39- **Observability:** Detailed logs in the n8n UI show cascade decisions, confidence, cost savings, and latency breakdowns. 【F:packages/integrations/n8n/README.md†L200-L244】4041### Relevant core capability notes4243- **Alignment scoring version:** TypeScript alignment scorer is based on Python v10; missing v14 improvements. 【F:packages/core/src/alignment.ts†L1-L37】4445## 3) Gap analysis (current vs needed)4647### A) n8n v2 capability gaps (TBD by validation)48491. **Agent compatibility**50 - **Current:** Not supported due to whitelist. 【F:packages/integrations/n8n/README.md†L64-L67】51 - **Needed:** A pathway for cascadeflow to participate in AI Agent workflows (either as a model or as a tool/agent node).52532. **Model metadata visibility**54 - **Current:** Logs show selected model path and costs, but not a standardized UI indicator in node connections. 【F:packages/integrations/n8n/README.md†L200-L244】55 - **Needed:** UI-level “model used” indicator + cost breakdown at execution step/trace granularity.56573. **Native AI node integration**58 - **Current:** Works as Language Model sub-node in Chain nodes, not native AI Agent nodes. 【F:packages/integrations/n8n/README.md†L64-L67】59 - **Needed:** Seamless compatibility with native AI nodes and LangChain agents (see section 6).6061### B) Python SDK feature gaps for n8n (priority list)6263Feature gaps called out in the request, with current TS status:64651. **Alignment scorer v14**66 - **Current TS:** v10 in TypeScript. 【F:packages/core/src/alignment.ts†L1-L37】67 - **Gap:** Port Python v14 features and thresholds to TS.68692. **All 16 domains support**70 - **Current n8n:** 16 domain constants exist, but only a subset exposed as toggles in UI (e.g., code, math, data, creative, legal, medical, financial, science). 【F:packages/integrations/n8n/nodes/LmChatCascadeFlow/LmChatCascadeFlow.node.ts†L12-L81】【F:packages/integrations/n8n/nodes/LmChatCascadeFlow/LmChatCascadeFlow.node.ts†L988-L1068】71 - **Gap:** Surface full 16-domain toggles + descriptions and allow connections for all.72733. **Confidence thresholds (per complexity tier + domain-specific)**74 - **Current TS:** Supported in core; n8n node exposes a single quality threshold and optional domain thresholds. 【F:packages/integrations/n8n/README.md†L124-L144】【F:packages/integrations/n8n/nodes/LmChatCascadeFlow/LmChatCascadeFlow.node.ts†L618-L623】75 - **Gap:** Expose full confidence-threshold table and complexity-aware routing in UI.76774. **Cost tracking**78 - **Current:** Logs show cost savings; cost tracking is in TS core and LangChain integration, but n8n does not surface a standardized per-model cost panel. 【F:packages/integrations/n8n/README.md†L200-L244】79 - **Gap:** Add UI surfaced fields / JSON metadata for downstream nodes to read cost breakdowns.8081## 4) Architecture options (model vs agent vs both)8283### Option A — “Model” node only (current pattern)8485**Description:** Continue exposing cascadeflow as a Language Model node, used by Chain and non-agent AI nodes.8687**Pros**88- Compatible with current n8n architecture (sub-node model connector). 【F:packages/integrations/n8n/README.md†L31-L43】89- Minimal disruption; aligns with current implementation.9091**Cons**92- Blocks AI Agent node usage due to model whitelist. 【F:packages/integrations/n8n/README.md†L64-L67】93- Harder to show cascade decisions beyond logs.9495### Option B — “Agent” node9697**Description:** Expose cascadeflow as an AI Agent node that orchestrates drafter/verifier models internally (and optionally tools).9899**Pros**100- First-class integration with n8n AI Agent workflows.101- Can surface cascade routing as part of agent trace (if v2 supports it).102103**Cons**104- Requires alignment with n8n’s agent model contract and tool call expectations.105- Must implement tool interaction semantics carefully to preserve downstream agent behavior.106107### Option C — Both (recommended)108109**Description:**110- Keep the **Model node** for Chain and generic AI nodes.111- Add an **Agent node** for agent workflows and tool orchestration.112113**Pros**114- Covers all n8n AI flows (native AI nodes + agents + LangChain chains).115- Gives users choice and a migration path.116117**Cons**118- More surface area to maintain.119120### Option D — “Routing service” node (non-model)121122**Description:** A standalone node that receives text input, routes internally, and outputs text + metadata.123124**Pros**125- Works with all n8n workflows, regardless of AI node constraints.126127**Cons**128- Loses Language Model connector semantics (tool calls, streaming, token tracking via n8n’s LM pipeline).129130## 5) UI/UX for model tracking & cost visibility131132### Goals133134- **Visible model used** (drafter vs verifier vs domain model).135- **Cost breakdown per step** (drafter cost, verifier cost, total, savings).136- **Cascade decision visibility** (why did it escalate?).137138### Proposed UI/UX patterns1391401. **Execution log summary block**141 - Add a concise, structured log summary at end of each run:142 - `selected_model`, `fallback_model`, `domain`, `confidence`, `threshold`, `costs`.143 - Use log formatting in n8n to enable quick scan (already partially implemented). 【F:packages/integrations/n8n/README.md†L200-L244】1441452. **Output metadata fields**146 - Include JSON metadata in the node output data structure:147 - `cf.model_used`, `cf.domain`, `cf.confidence`, `cf.costs`, `cf.savings`.148 - Downstream nodes can render in UI or export.1491503. **UI indicators (if v2 supports)**151 - Use node badges for “Drafter” vs “Verifier” used.152 - Link to a “Cascade Trace” panel in execution view.153154## 6) Working with native AI nodes and LangChain agents155156### A) Native AI nodes157158- **Model node path:** Keep `LmChatCascadeFlow` as the sub-node for AI Chat Model inputs.159- **Compatibility with prompt/chain nodes:** Continue ensuring it meets `BaseChatModel` expectations. 【F:packages/integrations/n8n/N8N_COMPATIBILITY_VALIDATION.md†L17-L43】160161### B) LangChain agents162163- **Short term:** Provide a “routing service” node alternative for agent workflows that can accept text input and return text + metadata.164- **Long term:** Implement a dedicated **AI Agent** node, if v2 provides an extension point for community agent nodes.165166### C) Dual-mode strategy (if v2 supports)167168- Add a **Model node** for LM workflows.169- Add an **Agent node** for agent workflows with tool routing.170- Add a **shared config** for model/cost/routing settings to keep consistency.171172## 7) Implementation roadmap (planning only)173174### Phase 0 — Validation & discovery (1-2 weeks)175176- Validate n8n v2 AI node architecture and any SDKs/extension points.177- Confirm agent model whitelist behavior and any changes in v2.178- Identify available UI hooks for cost/trace visualization.179180### Phase 1 — Feature parity (2-4 weeks)181182- Port **alignment scorer v14** from Python to TS.183- Expose all **16 domains** in n8n UI with per-domain config.184- Add **per-tier confidence thresholds** in node config.185- Emit structured output metadata for costs and model usage.186187### Phase 2 — Agent integration (3-6 weeks)188189- Add cascadeflow **AI Agent node** (if v2 allows custom agent nodes).190- Implement tool-call compatibility and streaming behavior.191- Ensure metadata flows into agent execution traces.192193### Phase 3 — UX polish & docs (1-2 weeks)194195- Create UI usage guide for model tracking + cost visibility.196- Update n8n integration docs with v2 capabilities and examples.197- Add sample workflows (model-only + agent + mixed).198199## 8) Recommendation200201**Recommended approach:** **Option C (Model + Agent)** with a staged rollout:2022031. **Immediate:** Improve Model node parity (alignment v14, full 16 domains, confidence thresholds, cost metadata).2042. **Short term:** Add a routing service node as a stopgap for AI Agent workflows.2053. **Mid term:** Implement a dedicated AI Agent node once n8n v2 extension points are confirmed.206207This ensures cascadeflow remains the best-in-class model routing solution for both traditional chain workflows and agent-based flows as n8n v2 evolves.