Building with LangChain Nodes
Relevant source files
The following files were used as context for generating this wiki page:
- packages/@n8n/nodes-langchain/nodes/agents/Agent/Agent.node.ts
- packages/@n8n/nodes-langchain/nodes/chains/ChainLLM/ChainLlm.node.ts
- packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.ts
- packages/@n8n/nodes-langchain/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.ts
- packages/@n8n/nodes-langchain/package.json
- packages/frontend/editor-ui/src/constants.ts
The @n8n/n8n-nodes-langchain package provides a comprehensive suite of nodes for integrating Large Language Model (LLM) and AI capabilities directly into n8n workflows. It leverages the LangChain framework to offer a modular and extensible system for building complex AI-powered applications, from simple text generation to sophisticated autonomous agents.
This package encapsulates various components of the LangChain ecosystem as individual n8n nodes. These nodes can be connected to create powerful chains and agents that can reason, process information, and interact with other services. The integration is designed to be seamless, allowing developers to combine the power of LLMs with the extensive connectivity of the n8n platform.
Core Concepts
The LangChain integration is built around a set of specialized node categories, each representing a core component of an AI application. These categories are defined within the n8n frontend and correspond to the different types of nodes available in the package.
Sources: packages/frontend/editor-ui/src/constants.ts:320-336, packages/@n8n/nodes-langchain/package.json:44-142
Package Dependencies
The functionality of the LangChain nodes relies on a set of key external libraries. The core dependency is langchain, along with various provider-specific packages from @langchain/* for services like OpenAI, Cohere, Anthropic, and vector databases like Pinecone and Qdrant.
The diagram below illustrates the key dependencies of the @n8n/n8n-nodes-langchain package.
Node Categories
LangChain nodes are organized into distinct categories within the n8n UI to facilitate workflow creation. These categories group nodes by their function, such as handling language models, managing memory, or providing tools to an agent.
This diagram shows the main categories of LangChain nodes available for building AI workflows.
The table below lists the primary AI node categories and their purpose.
| Category | Description | Node Examples | Node Type Constant |
|---|---|---|---|
| Agents | Nodes for creating autonomous agents that use LLMs to decide which actions to take. | Agent, OpenAiAssistant | AGENT_NODE_TYPE |
| Chains | Nodes for creating sequences of calls to LLMs or other utilities. | LLM, Retrieval QA | BASIC_CHAIN_NODE_TYPE |
| Language Models | Nodes that provide interfaces to various LLMs like OpenAI, Anthropic, and Cohere. | ChatOpenAI, ChatAnthropic | OPEN_AI_NODE_TYPE |
| Memory | Nodes for adding state and memory to chains and agents. | Buffer Window Memory, Zep Memory | AI_CATEGORY_MEMORY |
| Vector Stores | Nodes for storing and searching vector embeddings. | In-Memory, Pinecone, Qdrant | AI_CATEGORY_VECTOR_STORES |
| Tools | Nodes that agents can use to perform specific tasks, like calculations or web searches. | Calculator, HTTP Request, SerpApi | AI_CATEGORY_TOOLS |
| Retrievers | Nodes for fetching documents to be used in chains, often from vector stores. | Vector Store Retriever | AI_CATEGORY_RETRIEVERS |
| Embeddings | Nodes for creating vector representations of text using various models. | OpenAI Embeddings, Cohere Embeddings | AI_CATEGORY_EMBEDDING |
| Document Loaders | Nodes for loading data from various sources into a standardized document format. | JSON, GitHub | AI_CATEGORY_DOCUMENT_LOADERS |
| Text Splitters | Nodes for splitting large documents into smaller chunks for processing. | Recursive Character, Token Splitter | AI_CATEGORY_TEXT_SPLITTERS |
Sources: packages/@n8n/nodes-langchain/package.json:44-142, packages/frontend/editor-ui/src/constants.ts:169-336
Node Identification
Each LangChain node is uniquely identified by a type name, which follows the pattern @n8n/n8n-nodes-langchain.<NodeName>. These identifiers are defined as constants in the frontend for easy reference.
| Node Name | Constant |
|---|---|
| Agent | AGENT_NODE_TYPE |
| LLM Chain | BASIC_CHAIN_NODE_TYPE |
| Retrieval QA Chain | QA_CHAIN_NODE_TYPE |
| OpenAI Model | OPEN_AI_NODE_TYPE |
| OpenAI Assistant | OPEN_AI_ASSISTANT_NODE_TYPE |
| Manual Chat Trigger | MANUAL_CHAT_TRIGGER_NODE_TYPE |
Sources: packages/frontend/editor-ui/src/constants.ts:170-176
Typical Workflow Architecture
A common pattern for a Retrieval-Augmented Generation (RAG) workflow using LangChain nodes involves several stages, from loading data to generating a response.
The following flowchart illustrates a typical RAG pipeline constructed with n8n LangChain nodes.
- Document Loading: Data is ingested using a
Document Loadernode (e.g.,DocumentGithubLoader). - Text Splitting: The loaded documents are broken into smaller chunks by a
Text Splitternode. - Embedding: An
Embeddingnode (e.g.,EmbeddingsOpenAi) converts the text chunks into numerical vectors. - Vector Storage: The embeddings are stored in a
Vector Storenode (e.g.,VectorStoreInMemoryorVectorStorePinecone). - Retrieval: When a user provides input, a
Retrievernode (e.g.,RetrieverVectorStore) searches the vector store for relevant document chunks. - Generation: A
Chainnode (e.g.,ChainRetrievalQa) takes the user's query and the retrieved documents, passes them to anLLM, and generates a final answer.
Conclusion
The @n8n/n8n-nodes-langchain package provides a powerful and flexible toolkit for developers to build sophisticated AI-driven automations. By representing LangChain's modular components as distinct n8n nodes, it allows for the visual construction of complex AI systems, such as RAG pipelines and autonomous agents. This integration combines the advanced capabilities of modern language models with n8n's robust workflow automation and extensive integration library.
Sources: packages/@n8n/nodes-langchain/package.json, packages/frontend/editor-ui/src/constants.ts