LangChain in n8n
n8n's AI nodes implement LangChain's JavaScript framework. Each node is configurable: choose your own agent, LLM, memory, and other components. You can connect any other n8n node to your LangChain nodes as normal, so you can combine LangChain logic with any other data source or service n8n supports.
This page is for readers who already know LangChain and want to see how its concepts map onto n8n. If you're new to AI concepts, start with Understand AI components instead.
How LangChain concepts map to n8n nodes
n8n represents most LangChain concepts as cluster nodes: a root node that defines the cluster's main functionality, with one or more sub-nodes attached to extend it.
Vector store
Root node
Memory sub-nodes only attach to the AI Agent root node. Unlike LangChain, none of n8n's chain nodes support memory, so they can't reference earlier messages in a conversation. If your workflow needs to do that, use an agent instead of a chain.
The examples above aren't exhaustive. For the full, up-to-date list of nodes in each category, browse the root nodes and sub-nodes libraries. n8n also provides the Chat Trigger node to start a workflow from a chat message, and the LangChain Code node, which lets you write LangChain JavaScript code directly for functionality that doesn't have a dedicated n8n node yet.
Use LangSmith with a self-hosted n8n instance
LangSmith is a developer platform from the LangChain team. Connect a self-hosted n8n instance to LangSmith to record and monitor n8n executions, the same way you'd trace a LangChain application.
To connect n8n to LangSmith:
Log in to LangSmith and get your API key.
Set the following environment variables in the environment where you host n8n:
VariableValueLANGCHAIN_ENDPOINThttps://api.smith.langchain.comLANGCHAIN_TRACING_V2trueLANGCHAIN_API_KEYYour LangSmith API key
LANGCHAIN_PROJECTOptional project name. Defaults to
defaultLANGCHAIN_CALLBACKS_BACKGROUNDtrueto upload traces asynchronouslyRestart n8n.
LangSmith creates a project named default after n8n sends its first trace, unless you set LANGCHAIN_PROJECT to a different name. Every trace then goes to that project instead. Traces can arrive with a short delay, because LANGCHAIN_CALLBACKS_BACKGROUND uploads them asynchronously by default. Set it to false for synchronous uploads when you're debugging.
For information on using LangSmith itself, refer to LangSmith's documentation.
Learn more about LangChain
You don't need to know LangChain to use n8n, but these resources can help if you want to go deeper:
The LangChain documentation covers key concepts and use cases. Choose LangChain | Python or LangChain | JavaScript for quickstarts, code examples, and API documentation. LangChain also provides code templates for Python and JavaScript, with ideas for common patterns and use cases.
What's LangChain? explains LangChain terminology in plain language, for a general audience.
This YouTube series by Greg Kamradt works through the LangChain documentation with code examples.
Join the n8n Discord to discuss LangChain and share your projects with the n8n community.
Last updated
Was this helpful?