| name | n8n-syntax-ai-nodes |
| description | Use when building AI or LLM workflows in n8n v1.x (v1.19.4+). Prevents incorrect sub-node wiring by mismatching NodeConnectionTypes. Covers agent nodes (6 types), chain nodes, tool nodes, memory backends (8 types), vector stores (11 types), output parsers, text splitters, retrievers, AI sub-node connections (12 NodeConnectionTypes), langchain integration, RAG patterns, and human-in-the-loop. Keywords: n8n, AI nodes, LLM, langchain, RAG, vector store, agents.
|
| license | MIT |
| compatibility | Designed for Claude Code. Requires n8n v1.x (v1.19.4+ for AI features). |
| metadata | {"author":"OpenAEC-Foundation","version":"1.0"} |
n8n AI/LLM Cluster Node System
n8n integrates with LangChain to provide advanced AI capabilities via a cluster node architecture โ root nodes connected to specialized sub-nodes through typed connectors. Requires n8n v1.19.4+.
Quick Reference
Cluster Node Architecture
AI workflows in n8n use root nodes (agents, chains) connected to sub-nodes (models, memory, tools) through typed AI connectors. Root nodes NEVER work alone โ they ALWAYS require at least one Chat Model sub-node.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ROOT NODE (Agent/Chain) โ
โ โโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโโ โ
โ โai_languageโai_memory โai_tool โai_output โ โ
โ โModel โ โ โParser โ โ
โ โโโโโโฌโโโโโโดโโโโโฌโโโโโโดโโโโโฌโโโโโโดโโโโโโฌโโโโโโ โ
โโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโ
โ โ โ โ
โโโโโโผโโโโโ โโโโผโโโโ โโโโโผโโโโโ โโโโโผโโโโโโโ
โChat โ โMemoryโ โTool โ โOutput โ
โModel โ โNode โ โNode(s) โ โParser โ
โโโโโโโโโโโ โโโโโโโโ โโโโโโโโโโ โโโโโโโโโโโโ
AI Node Type Reference
| Category | Nodes | Purpose |
|---|
| Agents | Conversational, OpenAI Functions, Plan and Execute, ReAct, SQL, Tools Agent | Autonomous reasoning + tool use |
| Chains | Basic LLM, Summarization, Retrieval QA | Linear prompt-response pipelines |
| Specialized | Information Extractor, Text Classifier, Sentiment Analysis, LangChain Code | Task-specific AI operations |
| Chat Models | OpenAI, Anthropic, Azure OpenAI, Google Gemini, Groq, Ollama, Mistral, + more | LLM provider connections |
| Memory | Simple, Window Buffer, Token Buffer, Summary, PostgresChat, Redis, Xata, Zep | Conversation state persistence |
| Vector Stores | Pinecone, Qdrant, Supabase, PGVector, Chroma, Weaviate, In-Memory, Milvus, MongoDB Atlas, Azure AI Search, Redis | Vector similarity search backends |
| Embeddings | OpenAI, Cohere, Google, HuggingFace, Mistral, Ollama, Azure OpenAI | Text-to-vector conversion |
| Text Splitters | Character, Recursive Character, Token | Document chunking for RAG |
| Output Parsers | Structured, Auto-fixing, Item List | Response format enforcement |
| Retrievers | Vector Store, MultiQuery, Contextual Compression, Workflow | Document retrieval strategies |
| Tools | Calculator, Custom Code Tool, SearXNG, SerpApi, Wikipedia, Wolfram Alpha, Vector Store Q&A | Agent capabilities |
Sub-Node Connection Types (NodeConnectionType)
| Connection Type | Constant | Connects To |
|---|
ai_agent | NodeConnectionTypes.AiAgent | Agent sub-nodes |
ai_chain | NodeConnectionTypes.AiChain | Chain sub-nodes |
ai_document | NodeConnectionTypes.AiDocument | Document loaders |
ai_embedding | NodeConnectionTypes.AiEmbedding | Embedding models |
ai_languageModel | NodeConnectionTypes.AiLanguageModel | Chat/LLM models |
ai_memory | NodeConnectionTypes.AiMemory | Memory backends |
ai_outputParser | NodeConnectionTypes.AiOutputParser | Output parsers |
ai_retriever | NodeConnectionTypes.AiRetriever | Retrievers |
ai_reranker | NodeConnectionTypes.AiReranker | Reranking models |
ai_textSplitter | NodeConnectionTypes.AiTextSplitter | Text splitters |
ai_tool | NodeConnectionTypes.AiTool | Agent tools |
ai_vectorStore | NodeConnectionTypes.AiVectorStore | Vector stores |
Decision Trees
Which Agent Type to Use
Need autonomous AI reasoning?
โโ YES: Does the task require tool use?
โ โโ YES: Which provider?
โ โ โโ OpenAI with function calling โ OpenAI Functions Agent
โ โ โโ Any provider, general tools โ Tools Agent (RECOMMENDED default)
โ โ โโ Need step-by-step planning โ Plan and Execute Agent
โ โโ NO: Simple conversation?
โ โโ YES โ Conversational Agent
โ โโ NO: Need reasoning trace? โ ReAct Agent
โโ Database queries? โ SQL Agent
โโ NO: Simple prompt-response?
โโ Single prompt โ Basic LLM Chain
โโ Summarize text โ Summarization Chain
โโ Q&A over documents โ Retrieval QA Chain
Rule: ALWAYS start with Tools Agent unless you have a specific reason to use another type. It is the most flexible and works with any chat model provider.
Which Memory Type to Use
Need conversation memory?
โโ NO โ Skip memory sub-node entirely
โโ YES: Persistence required?
โ โโ NO (in-memory only):
โ โ โโ Simple buffer โ Simple Memory (default 5 exchanges)
โ โ โโ Token-limited โ Token Buffer Memory
โ โโ YES (survives restarts):
โ โโ PostgreSQL available โ PostgresChat Memory
โ โโ Redis available โ Redis Chat Memory
โ โโ Need summarization โ Summary Memory
โ โโ Managed service โ Zep or Xata Memory
Which Vector Store to Use
Need vector similarity search?
โโ Testing/prototyping โ In-Memory Vector Store
โโ Production:
โ โโ Managed cloud service:
โ โ โโ Pinecone (fully managed, scalable)
โ โ โโ Qdrant (open-source, self-hostable)
โ โ โโ Weaviate (hybrid search)
โ โ โโ Azure AI Search (Azure ecosystem)
โ โโ Existing database:
โ โ โโ PostgreSQL โ PGVector
โ โ โโ Supabase โ Supabase Vector Store
โ โ โโ MongoDB โ MongoDB Atlas
โ โ โโ Redis โ Redis Vector Store
โ โโ Self-hosted โ Chroma or Milvus
Core Patterns
Pattern 1: Basic Agent Workflow
[Trigger] โ [Tools Agent]
โโโ ai_languageModel โ [OpenAI Chat Model]
โโโ ai_memory โ [Simple Memory]
โโโ ai_tool โ [Calculator]
[Wikipedia]
[Custom Code Tool]
ALWAYS connect at least one Chat Model sub-node. NEVER leave the ai_languageModel connector empty.
Pattern 2: RAG Data Insertion
[Trigger] โ [Get Documents] โ [Vector Store (Insert Documents)]
โโโ ai_embedding โ [OpenAI Embeddings]
โโโ ai_document โ [Default Data Loader]
โโโ ai_textSplitter โ [Recursive Character Text Splitter]
ALWAYS use a text splitter when inserting documents. NEVER insert full documents without splitting โ it degrades retrieval quality.
Text splitting guidance:
- ALWAYS use Recursive Character Text Splitter as the default choice
- Use chunk sizes of 200-500 tokens for fine-grained retrieval
- ALWAYS set overlap (10-20% of chunk size) to preserve context across boundaries
Pattern 3: RAG Retrieval via Agent
[Chat Trigger] โ [Tools Agent]
โโโ ai_languageModel โ [OpenAI Chat Model]
โโโ ai_memory โ [Postgres Chat Memory]
โโโ ai_tool โ [Vector Store Q&A Tool]
โโโ ai_vectorStore โ [Pinecone]
โโโ ai_embedding โ [OpenAI Embeddings]
Pattern 4: RAG Retrieval via Chain
[Chat Trigger] โ [Retrieval QA Chain]
โโโ ai_languageModel โ [OpenAI Chat Model]
โโโ ai_retriever โ [Vector Store Retriever]
โโโ ai_vectorStore โ [PGVector]
โโโ ai_embedding โ [OpenAI Embeddings]
Pattern 5: Human-in-the-Loop
[Chat Trigger] โ [Tools Agent]
โโโ ai_languageModel โ [Chat Model]
โโโ ai_tool โ [Tool with Approval]
โโโ Approve โ [Execute Action]
โโโ Deny โ [Notify User]
- 9 notification channels: Chat, Slack, Discord, Telegram, Microsoft Teams, Gmail, WhatsApp, Google Chat, Microsoft Outlook
- Access tool context:
$tool.name (tool identifier), $tool.parameters (AI-determined values)
- Use
$fromAI() for dynamic parameter specification in tool nodes
- ALWAYS include human review information in the system prompt so the AI understands the approval workflow
Critical Rules
ALWAYS
- ALWAYS connect a Chat Model sub-node to every agent and chain root node
- ALWAYS use the same embedding model for insertion AND retrieval in RAG workflows
- ALWAYS use Recursive Character Text Splitter unless you have a specific reason not to
- ALWAYS set chunk overlap when splitting documents for RAG
- ALWAYS use Tools Agent as the default agent type
- ALWAYS include a system prompt that describes available tools and expected behavior
- ALWAYS test AI workflows with pinned data before activating in production
NEVER
- NEVER mix embedding models between insertion and retrieval โ vectors become incompatible
- NEVER skip text splitting when inserting documents into vector stores
- NEVER connect sub-nodes to incompatible connector types (e.g., a memory node to an
ai_tool connector)
- NEVER use Basic LLM Chain when you need tool use โ use an Agent instead
- NEVER store sensitive data in AI memory without considering data retention policies
- NEVER use In-Memory Vector Store in production โ data is lost on restart
- NEVER assume AI agent output is deterministic โ ALWAYS validate critical outputs
Sub-Node Connection Rules
| Root Node Type | Required Connections | Optional Connections |
|---|
| Tools Agent | ai_languageModel | ai_memory, ai_tool, ai_outputParser |
| OpenAI Functions Agent | ai_languageModel (OpenAI only) | ai_memory, ai_tool, ai_outputParser |
| Conversational Agent | ai_languageModel | ai_memory, ai_tool, ai_outputParser |
| ReAct Agent | ai_languageModel | ai_memory, ai_tool, ai_outputParser |
| Plan and Execute Agent | ai_languageModel | ai_memory, ai_tool, ai_outputParser |
| SQL Agent | ai_languageModel | ai_memory |
| Basic LLM Chain | ai_languageModel | ai_outputParser, ai_memory |
| Summarization Chain | ai_languageModel | โ |
| Retrieval QA Chain | ai_languageModel, ai_retriever | โ |
| Vector Store (Insert) | ai_embedding, ai_document | โ |
| Vector Store (Retrieve) | ai_embedding | โ |
supplyData() Method
AI sub-nodes implement supplyData() instead of execute(). This method returns the LangChain object (model, memory, tool, etc.) that the root node consumes:
async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {
const memory = new BufferMemory({ });
return { response: memory };
}
Root nodes call getInputConnectionData() to retrieve sub-node outputs:
const model = await this.getInputConnectionData('ai_languageModel', itemIndex);
const memory = await this.getInputConnectionData('ai_memory', itemIndex);
const tools = await this.getInputConnectionData('ai_tool', itemIndex);
LangChain Code Node
The LangChain Code node provides special built-in methods for custom LangChain operations. These methods are ONLY available in the LangChain Code node, NOT in regular Code nodes.
Use the LangChain Code node when:
- Built-in AI nodes do not cover your use case
- You need custom LangChain chain composition
- You need advanced prompt engineering beyond what the UI supports
Reference Links