AI & LangChain Nodes
Relevant source files
The following files were used as context for generating this wiki page:
- packages/@n8n/nodes-langchain/README.md
- packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts
- packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts
- packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/content-generation.ts
- packages/@n8n/ai-workflow-builder.ee/src/code-builder/prompts/index.ts
- packages/frontend/editor-ui/src/experiments/readyToRunWorkflowsV2/workflows/ai-workflow-v6.ts
Introduction
AI & LangChain nodes within n8n provide a specialized framework for building advanced AI-powered workflows. These nodes leverage the LangChain library to enable complex reasoning, text analysis, and multi-modal content generation. The system is designed to allow developers to construct "AI Agents" that can interact with various tools, memory systems, and language models to perform tasks ranging from simple text classification to sophisticated document processing and Retrieval-Augmented Generation (RAG).
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:63-75, packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts:1-20
Architecture and Core Components
The architecture follows a modular approach where a central AI Agent or Chain node acts as an orchestrator, connecting to various specialized sub-nodes via specific AI connection types. These connections define the capabilities of the agent, such as its "brain" (Language Model), "memory" (Chat Memory), and "skills" (Tools).
Connection Types
The system uses distinct connection types to manage data flow between AI components:
ai_languageModel: Connects LLM providers (e.g., OpenAI, Anthropic).ai_tool: Connects tools for the agent to perform actions (e.g., Calculator, Google Sheets).ai_memory: Maintains conversation context.ai_vectorStore: Facilitates document retrieval.ai_outputParser: Handles structured data extraction from AI responses.
Sources: packages/@n8n/ai-workflow-builder.ee/src/code-builder/prompts/index.ts:310-330, packages/testing/playwright/expectations/workflow-builder/1768236115215-unknown-host-POST-_v1_messages-343a818e.json:52-65
Multi-Agent Systems
The system supports "AgentTools," allowing a main AI Agent to call sub-agents. This creates a hierarchical "team of agents" structure where each sub-agent can have its own specific model and toolset.
The following diagram illustrates the relationship between a main agent and its sub-components:
This diagram shows a multi-agent pattern where a Main AI Agent orchestrates specialized tools that are themselves agents.
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:77-90
Key Node Categories
1. AI Agents and Chains
The AI Agent node is the primary interface for AI reasoning. It uses models and tools to decide the best course of action based on user input. For simpler, linear tasks, Basic LLM Chains are used.
| Node Name | Purpose | Key Parameters |
|---|---|---|
AI Agent | Complex reasoning and tool use | promptType, hasOutputParser, text |
Chain Summarization | Condensing large text blocks | options |
Information Extractor | Structured data extraction | schema |
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:63-75, packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/data-extraction.ts:70-85
2. Language Models (LLMs)
LLM nodes provide the underlying intelligence. Users can specify models directly, and the system supports major providers through specialized nodes.
- OpenAI: Used for chat, DALL-E (images), and Whisper (transcription).
- Anthropic: Recommended for Claude models due to streaming and token management.
- Google Gemini: Used for image/video generation (Nano Banana/Imagen).
- xAI Grok: Conversational AI capabilities.
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:250-260, packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/content-generation.ts:40-60
3. Knowledge Base and Vector Stores
For Retrieval-Augmented Generation (RAG), the system utilizes Vector Stores and Document Loaders.
This diagram depicts a standard RAG flow where documents are loaded into a store which then acts as a tool for the AI Agent.
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:225-235, packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts:1-15
Best Practices for AI Workflows
Data Transformation and Output
- Structured Output Parser: Crucial when AI output needs to be used programmatically (e.g., saving to a database or routing in a Switch node).
- Filtering: irrelvant content should be filtered before sending data to the LLM to minimize token usage and costs.
- Memory: For chatbots,
Window Buffer Memoryis recommended to maintain a sliding window of recent conversation history (typically 3-5 turns).
Sources: packages/@n8n/ai-workflow-builder.ee/src/prompts/agents/discovery.prompt.ts:65-75, packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/data-analysis.ts:25-35, packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/knowledge-base.ts:70-80
Multi-Modal Implementation
When workflows require media generation, provider-specific nodes must be used:
- Video: Sora (OpenAI) or Nano Banana (Google).
- Image: DALL-E (OpenAI) or Imagen (Google).
- Audio: ElevenLabs or OpenAI TTS.
Sources: packages/@n8n/workflow-sdk/src/prompts/best-practices/guides/content-generation.ts:15-35
Implementation Example: News Agent Chatbot
The following snippet demonstrates a typical AI Agent configuration using n8n's ready-to-run template structure, involving a Chat Model, Memory, and multiple Tools (RSS and Google Sheets).
// AI Agent configuration excerpt
{
type: '@n8n/n8n-nodes-langchain.agent',
position: [192, 64],
parameters: {
options: {
systemMessage: 'You are a concise, factual news assistant...'
}
},
connections: {
ai_languageModel: [{ node: 'OpenAI Model' }],
ai_memory: [{ node: 'Simple Memory' }],
ai_tool: [
{ node: 'Hackernews' },
{ node: 'TheVerge' },
{ node: 'BBC News' }
]
}
}
Sources: packages/frontend/editor-ui/src/experiments/readyToRunWorkflowsV2/workflows/ai-workflow-v6.ts:1-150
Conclusion
The AI & LangChain nodes provide a robust environment for integrating LLMs into n8n's automation platform. By utilizing the modular agent-tool-model architecture, developers can build reliable, context-aware applications that handle complex data extraction, content generation, and knowledge retrieval tasks with high technical accuracy.