LangChain Integration & AI Nodes
Relevant source files
The following files were used as context for generating this wiki page:
- packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts
- packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts
- packages/@n8n/ai-workflow-builder.ee/src/code-builder/prompts/index.ts
- AGENTS.md
- packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/content-generation.ts
- packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/data-analysis.ts
The LangChain integration provides a suite of specialized nodes that enable Artificial Intelligence (AI) capabilities within n8n workflows. This module allows you to build complex AI systems such as chatbots, autonomous agents, and Retrieval-Augmented Generation (RAG) pipelines by leveraging Large Language Models (LLMs) from various providers.
The integration is primarily housed in the @n8n/nodes-langchain package and utilizes a "sub-node" architecture. In this structure, a primary node—such as an AI Agent—connects to multiple specialized sub-nodes that provide chat models, memory, tools, and output parsers.
Sources: AGENTS.md:129, packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:49-65
AI Agent Architecture
The AI Agent node serves as the orchestrator for AI reasoning and task execution. It uses LLMs to determine which tools to use and how to process information based on a system prompt.
Component Relationships
AI Agents require specific sub-nodes to function. These sub-nodes connect via specialized connection types (e.g., ai_languageModel, ai_tool, ai_memory).
This diagram shows the modular connection pattern where an AI Agent acts as the central hub for specialized sub-nodes.
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:49-65, packages/@n8n/ai-workflow-builder.ee/src/code-builder/prompts/index.ts:316-340
Multi-Agent Systems
You can build "teams of agents" by nesting agents. The AI Agent Tool allows a main agent to call a complete sub-agent through the ai_tool connection. Each nested agent requires its own dedicated Chat Model.
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:50-65
Knowledge Base & RAG Pipelines
Knowledge Base implementation in n8n follows the Retrieval-Augmented Generation (RAG) pattern. This system allows LLMs to retrieve and use private data from vector databases to answer user queries with high factual accuracy.
Retrieval-Augmented Generation Flow
This diagram illustrates the separation between the document indexing process and the active retrieval query flow.
Sources: packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts:7-14, packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts:25-40
Processing Requirements
- Text Splitting: Documents must be split into chunks (recommended: 500-1000 characters) with 10-15% overlap to preserve context.
- Consistent Embeddings: You MUST use the same embedding model (e.g.,
text-embedding-ada-002) for both indexing and retrieval. - Vector Dimensions: The vector store index dimensions must match the embedding model output (e.g., 1536 dimensions for OpenAI).
Sources: packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts:27-31, packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts:98-103
Core AI Node Types
| Node Name | Purpose | Configuration Requirements |
|---|---|---|
| AI Agent | Orchestrates reasoning and tool use. | Requires Chat Model. Optional: Memory, Tools, Output Parser. |
| Vector Store | Stores/retrieves text embeddings for RAG. | Required: Embeddings sub-node. Mode: Insert/Retrieve. |
| Chat Model | Provides the LLM logic (OpenAI, Anthropic, Gemini). | Requires Credentials for the specific provider. |
| Structured Output Parser | Forces AI to output valid JSON. | Requires a JSON schema or example object. |
| Text Splitter | Divides large text into chunks for indexing. | Configures chunk size and overlap. |
| Embeddings | Converts text into numerical vectors. | Must match model used in Vector Store. |
| Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:49-65, packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts:60-90 |
Best Practices and Constraints
Model Selection
- OpenAI Chat Model: Generally preferred for low friction in new workflows.
- Anthropic Chat Model: Used for Claude models.
- Google Gemini: Used for multi-modal tasks including image and video generation (e.g., Nano Banana).
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:49-53, packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/content-generation.ts:32-35
Multi-Modal Tasks
If a user request involves creating media, specific model-level nodes are required rather than the general AI Agent:
- Image Generation: DALL-E (OpenAI), Imagen (Google Gemini).
- Video Generation: Sora (OpenAI), Runway, Pika.
- Text-to-Speech (TTS): ElevenLabs, OpenAI TTS.
Sources: packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/content-generation.ts:16-30
Operational Logic
- Linear Item Processing: n8n executes nodes once per input item. When an AI node (like a Google Drive loader) returns multiple documents, every downstream node runs once for each item unless aggregated.
- Temperature Control: For factual Q&A or data extraction, set temperature 0-0.3. For creative generation, set temperature 0.7-1.0.
- Memory Depth: 3-5 message turns are typically sufficient for conversation history in
Window Buffer Memory.
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:18-20, packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts:42-45, packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts:88-90
Conclusion
The LangChain Integration & AI Nodes enable n8n to move beyond simple automation into autonomous decision-making and specialized data processing. By correctly chaining agents, models, and vector stores, you can create scalable AI applications that safely leverage internal data through RAG and multi-modal generative models.