
n8n + LangChain Integration: Build RAG, Tool and Memory Workflows
n8n and LangChain together solve a problem most teams hit eventually: you want AI agents that connect to real data and trigger real actions, but wiring LangChain in Python means maintaining a whole application stack. n8n's native LangChain nodes let you drag-and-drop agents, chains, memory, and vector stores into visual workflows, then connect them to 400+ integrations without writing SDK code.
This page is the LangChain integration reference, centered on node mapping, RAG, vector stores, tools, and memory. If you want a beginner project walkthrough instead, build the two complete examples in our n8n AI agents tutorial.
What You Get: n8n's LangChain Node Library
n8n ships with over 70 AI nodes that implement LangChain concepts as visual building blocks. Instead of importing langchain in Python and gluing modules together, you connect nodes on a canvas. Here's the full breakdown:
| Node Category | What It Does | Key Nodes |
|---|---|---|
| Root Nodes | Core AI logic (the "brain") | AI Agent, Basic LLM Chain, Q&A Chain, Summarization Chain |
| Chat Models | LLM connections | OpenAI, Anthropic Claude, Google Gemini, Ollama, Groq, Mistral, DeepSeek |
| Memory | Conversation persistence | Simple Memory, Redis, Postgres, MongoDB, Zep |
| Vector Stores | Document storage + retrieval | Pinecone, Qdrant, Supabase, Chroma, Weaviate, PGVector, In-Memory |
| Embeddings | Text-to-vector conversion | OpenAI, Cohere, HuggingFace, Ollama, AWS Bedrock |
| Tools | External capabilities for agents | Calculator, SerpAPI, Wikipedia, Custom Code, MCP Client, Workflow Tool |
| Output Parsers | Structured response formatting | Auto-fixing, Structured, Item List |
| Text Splitters | Document chunking | Character, Recursive Character, Token |
The architecture uses what n8n calls cluster nodes, a root node (like the AI Agent) connects to sub-nodes (chat model, memory, tools) that extend its capabilities. Think of it as LangChain's module system, but visual.
How n8n Maps to LangChain Concepts
If you've used LangChain in code, n8n's mapping is straightforward:
| LangChain Concept | n8n Equivalent | When to Use |
|---|---|---|
ChatOpenAI() | OpenAI Chat Model sub-node | Any workflow needing an LLM |
ConversationBufferMemory() | Simple Memory / Redis Memory | Multi-turn conversations |
RetrievalQA.from_chain_type() | Q&A Chain + Vector Store Retriever | Document question-answering |
AgentExecutor with tools | AI Agent node (Tools Agent type) | Dynamic tool selection |
RecursiveCharacterTextSplitter() | Recursive Character Text Splitter sub-node | Chunking documents for RAG |
FAISS.from_documents() | Simple Vector Store (Insert Documents) | Storing embeddings locally |
The critical difference? In code, you write 50-100 lines to wire these together. In n8n, you connect 4-6 nodes on a canvas and configure them through dropdown menus.
Building a Document Q&A Pipeline (RAG)
Let's build something real. This workflow ingests PDF documents, stores them in a vector database, and answers questions about their content. It's a classic RAG (Retrieval-Augmented Generation) pattern, the single most useful LangChain workflow for business teams.
Step 1: Set Up the Data Ingestion Workflow
Create a new workflow for loading documents. You'll run this once whenever you have new documents to add.
Nodes to add:
- Manual Trigger, Click to run the ingestion
- Google Drive node (or HTTP Request, Read Binary File), Fetches your source documents
- Simple Vector Store, Set operation to Insert Documents
- OpenAI Embeddings sub-node, Connects to the Vector Store, converts text to vectors
- Default Data Loader sub-node, Parses document content into chunks
- Recursive Character Text Splitter sub-node, Splits content into ~500 token chunks with 50-token overlap
Configuration details for the Vector Store:
- Operation:
Insert Documents - Memory Key: Give it a descriptive name like
company-docs(this is how you'll reference it later) - The Data Loader connects as a sub-node and handles PDF/text parsing automatically
Configuration for the Text Splitter:
- Chunk Size: 500 (tokens)
- Chunk Overlap: 50 (ensures context isn't lost at boundaries)
- Split method: Recursive Character (handles Markdown, HTML, and plain text intelligently)
Step 2: Build the Q&A Agent Workflow
Now create a second workflow, this is the one users interact with.
Nodes to add:
- Chat Trigger, Provides the chat interface for questions
- AI Agent (Tools Agent type), The brain that decides what to do
- OpenAI Chat Model sub-node, Connect GPT-4o or GPT-4o-mini
- Simple Memory sub-node, Remembers the conversation context
- Vector Store Tool sub-node, Gives the agent access to your documents
Configuration for the AI Agent node:
- Agent Type: Tools Agent (the most flexible option, it decides when and how to use tools)
- System Prompt:
You are a helpful assistant that answers questions based on our company documents. Always cite which document you found the answer in. If the information isn't in the documents, say so clearly.
Configuration for the Vector Store Tool:
- Name:
search_documents - Description:
Search the company knowledge base for relevant information. Use this tool when the user asks about company policies, procedures, or documentation. - Vector Store: Select your Simple Vector Store
- Embedding model: Same OpenAI Embeddings model you used during ingestion
- Top K: 4 (number of relevant chunks to retrieve)
That description matters more than you'd think. The agent uses it to decide when to call the tool versus answering from its own knowledge. Be specific.
Step 3: Test and Refine
Click Chat in the bottom panel to open n8n's built-in chat interface. Ask a question about your documents. Watch the execution trace, n8n shows you exactly which nodes fired, what the agent's reasoning was, and which document chunks were retrieved.
Common issues at this stage:
- Agent doesn't use the tool: Your tool description is too vague. Make it specific about what knowledge the tool contains.
- Retrieves irrelevant chunks: Increase chunk overlap or decrease chunk size. Try 300 tokens with 100 overlap.
- Slow responses: Switch to GPT-4o-mini for the chat model. It's 10x cheaper and fast enough for most Q&A tasks.
Building a Tool-Calling Agent
The Q&A pipeline above is great for documents. But what about an agent that can search the web, run calculations, query databases, AND answer from documents? That's where the Tools Agent really shines.
The Workflow Setup
- Chat Trigger, User input
- AI Agent (Tools Agent), Routes to the right tool
- OpenAI Chat Model, GPT-4o for complex reasoning
- Simple Memory, Conversation history
- Multiple tools connected:
- SerpAPI Tool, Web search capability
- Calculator Tool, Math operations
- Vector Store Tool, Your document knowledge base
- Custom Code Tool, Any JavaScript function you write
- Workflow Tool, Triggers another n8n workflow as a tool
The Workflow Tool is n8n's secret weapon. It lets you wrap any n8n workflow as a tool the agent can call. Got a workflow that checks inventory? Make it a tool. One that sends Slack messages? Tool. One that queries your CRM? Tool. This is where n8n's 400+ integration nodes become available to your AI agent.
System Prompt for Multi-Tool Agents
Your system prompt needs to tell the agent about its capabilities:
You are a research assistant with access to the following tools:
- search_documents: Search our internal knowledge base
- web_search: Search the internet for current information
- calculator: Perform mathematical calculations
- send_notification: Send a Slack message to the team
For factual questions about our company, always check search_documents first.
For current events or external data, use web_search.
Show your reasoning before giving a final answer.This prompt pattern directly controls how the agent routes between tools. Vague prompts lead to agents using web search when they should check your documents first.
Choosing the Right Agent Type
n8n offers six agent types. Here's when to pick each one:
| Agent Type | Best For | Supports Tools? | Notes |
|---|---|---|---|
| Tools Agent | Most use cases | Yes | Default choice, flexible, reliable |
| Conversational Agent | Simple chatbots | Yes | Less capable but lighter weight |
| ReAct Agent | Complex reasoning chains | Yes | Shows explicit reasoning steps |
| OpenAI Functions Agent | OpenAI-specific features | Yes | Uses OpenAI's function calling API |
| Plan and Execute Agent | Multi-step tasks | Yes | Plans first, then executes, good for complex workflows |
| SQL Agent | Database queries | Limited | Generates and runs SQL against your database |
For most teams, Tools Agent is the right starting point. It handles multi-tool routing well, works with any LLM provider, and you can always switch later. If you're comparing this to building agents in code with frameworks like LangGraph or CrewAI, the advantage here is zero deployment overhead, your agent runs inside n8n's infrastructure.
Adding Memory That Persists
By default, the Simple Memory sub-node keeps conversation history in memory, it disappears when the workflow restarts. For production use, you'll want persistent memory.
Your options:
| Memory Type | Persistence | Setup Effort | Best For |
|---|---|---|---|
| Simple Memory | Session only | None | Testing, prototyping |
| Redis Chat Memory | Persistent, fast | Medium (need Redis) | Production chatbots |
| Postgres Chat Memory | Persistent, queryable | Medium (need Postgres) | When you want to analyze conversations |
| MongoDB Chat Memory | Persistent, flexible | Medium (need MongoDB) | Document-oriented storage |
| Zep Memory | Persistent + summarization | Medium (need Zep) | Long conversations that exceed context windows |
Zep is worth highlighting if you're building anything with long conversation histories. It automatically summarizes older messages so your agent doesn't blow through the context window on turn 50 of a conversation.
To add persistent memory, just swap the Simple Memory sub-node for Redis/Postgres/Zep. The rest of your workflow stays identical.
Connecting to Different LLM Providers
Every root node that needs an LLM accepts a Chat Model sub-node. Swapping providers is a one-node change:
| Provider | Node Name | Models Available | Notes |
|---|---|---|---|
| OpenAI | OpenAI Chat Model | GPT-4o, GPT-4o-mini, o1, o3-mini | Most widely tested with n8n |
| Anthropic | Anthropic Chat Model | Claude 3.5 Sonnet, Claude 3 Opus | Strong for analysis and long context |
| Google Gemini Chat Model | Gemini 1.5 Pro, Gemini Flash | Good free tier | |
| Ollama | Ollama Chat Model | Llama 3, Mistral, Phi-3 | Fully local, no API costs |
| Groq | Groq Chat Model | Llama 3, Mixtral | Extremely fast inference |
| AWS Bedrock | AWS Bedrock Chat Model | Claude, Titan, Llama | Enterprise AWS integration |
For local development and testing, Ollama is the zero-cost option, run models on your machine and connect n8n to localhost:11434. For production, most teams use OpenAI or Anthropic depending on the task.
Real-World Workflow Recipes
Here are three production-ready patterns you can build in under 30 minutes:
Recipe 1: Automated Support Ticket Classification
Trigger: New email arrives (Gmail/Outlook node) Chain: Basic LLM Chain with a classification prompt Output: Routes to different Slack channels based on category
The prompt does the heavy lifting: Classify this support email into exactly one category: billing, technical, feature_request, or other. Respond with only the category name.
Recipe 2: Weekly Content Digest
Trigger: Schedule (every Monday at 9am) Agent: Tools Agent with SerpAPI + Custom Code Tool Memory: Not needed (one-shot task) Output: Summarized report sent to Slack/Email
The agent searches for industry news, summarizes the top 5 articles, and formats a digest. The Custom Code Tool handles any formatting logic that's easier in JavaScript than in a prompt.
Recipe 3: Document-Grounded Slack Bot
Trigger: Slack message in a specific channel Agent: Tools Agent with Vector Store Tool Memory: Redis Chat Memory (keyed by Slack thread ID) Output: Reply to the Slack thread
This is the Q&A pipeline from earlier, but triggered by Slack instead of a chat UI. The thread-based memory key means each Slack conversation gets its own context.
For teams exploring which RAG tools to use alongside n8n, the vector store choice matters less than your chunking strategy. Start with the Simple (In-Memory) Vector Store for prototyping, then move to Pinecone or Qdrant for production.
Common Mistakes and How to Avoid Them
After building dozens of n8n AI workflows, these are the pitfalls that trip people up:
1. Skipping the system prompt. The AI Agent node works without a system prompt, but poorly. Always define the agent's role, available tools, and preferred behavior. Ten minutes on the prompt saves hours of debugging weird responses.
2. Using one giant workflow. Split ingestion and querying into separate workflows. The ingestion workflow runs occasionally (when new docs arrive). The query workflow runs constantly. Mixing them creates execution conflicts.
3. Choosing the wrong chunk size. Default chunking (1000 characters) works for general content. For technical docs, drop to 300-500 tokens. For legal documents, increase to 800-1000 tokens with higher overlap. There's no universal "right" chunk size, test with your actual documents.
4. Ignoring the execution log. n8n shows the complete execution trace for every workflow run. When an agent gives a wrong answer, check which tool it called (or didn't call), which chunks were retrieved, and what reasoning it showed. The log tells you exactly where things went wrong.
5. Paying for GPT-4o when you don't need it. For classification, summarization, and simple Q&A, GPT-4o-mini is 90% as good at 10% of the cost. Reserve GPT-4o or Claude for complex multi-step reasoning.
How Techsy Approaches n8n AI Automation
We've built n8n AI workflows for clients ranging from 3-person startups to enterprise teams. Our process:
- Map the decision flow, Before opening n8n, we diagram every decision point and data source
- Prototype with Simple Vector Store, Get the core logic working with in-memory storage
- Test with real data early, Synthetic test data hides chunking and retrieval problems
- Add memory and persistence, Only after the core Q&A or agent logic is validated
- Monitor and iterate, Track which tool calls succeed, which chunks get retrieved, and where users get frustrated
If you're building AI agents for business workflows and want help designing the architecture, reach out for a free consultation.
Frequently Asked Questions
Do I need to know LangChain to use n8n's AI nodes?
No. n8n abstracts LangChain into visual nodes with dropdown configurations. Understanding LangChain concepts (agents, chains, memory, retrievers) helps you make better design decisions, but you never write LangChain code unless you choose to use the LangChain Code node.
Can I use local LLMs with n8n instead of OpenAI?
Yes. Connect the Ollama Chat Model sub-node to any model running on your machine (Llama 3, Mistral, Phi-3, etc.). Point it at http://localhost:11434 and you have a fully private, zero-cost AI workflow. Groq is another option for fast inference without managing your own hardware.
What's the difference between a Chain and an Agent in n8n?
A chain follows a fixed sequence, input goes through step A, then B, then C. An agent decides dynamically which tools to call based on the input. Use chains for predictable tasks (summarization, classification). Use agents when the workflow needs to make decisions about what to do next.
How many documents can the Simple Vector Store handle?
The Simple (In-Memory) Vector Store works fine for prototyping with a few hundred documents. For production with thousands of documents, switch to Pinecone, Qdrant, Supabase, or Chroma. The workflow stays the same, you just swap the vector store node.
Can I trigger n8n AI workflows from external apps?
Yes. Use the Webhook Trigger node to expose your AI workflow as an API endpoint. Any app that can make HTTP requests can send data to your agent and get a response. This is how you integrate n8n AI workflows into existing products.
Is n8n free for AI workflows?
n8n Community Edition is fully open source and free to self-host. All LangChain nodes are included. The Cloud plans start at $24/month if you don't want to manage infrastructure. The LLM API costs (OpenAI, Anthropic, etc.) are separate and billed by the provider.
How does n8n handle errors in AI agent workflows?
n8n has built-in error handling at the node level. You can set retry logic, fallback paths, and error workflows. For AI-specific issues (like LLM timeouts or rate limits), add a retry with exponential backoff on the Chat Model sub-node. The execution log shows exactly where failures occur.
Can I use n8n's AI workflows with my own API keys?
Yes. Every LLM node requires you to create a credential with your own API key. n8n stores credentials encrypted. If you're self-hosting, the keys never leave your infrastructure.
What's the LangChain Code node for?
The LangChain Code node lets you write custom JavaScript that uses LangChain modules directly. It's an escape hatch for when n8n's visual nodes don't cover your exact use case, maybe you need a custom retriever, a specific prompt template, or a LangChain module that n8n hasn't wrapped yet.
How do I share n8n AI workflows with my team?
Export the workflow as JSON (Ctrl+Shift+E) and share the file. Anyone can import it into their n8n instance. For team collaboration, n8n Cloud includes shared workspaces with version history. You can also commit workflow JSON files to Git for version control.