For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

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.

Feature availability

LangSmith tracing is available on:

  • Self-hosted: All editions

It isn't available on n8n Cloud.

To connect n8n to LangSmith:

  1. Log in to LangSmith and get your API key.

  2. Set the following environment variables in the environment where you host n8n:

    Variable
    Value

    LANGCHAIN_ENDPOINT

    https://api.smith.langchain.com

    LANGCHAIN_TRACING_V2

    true

    LANGCHAIN_API_KEY

    Your LangSmith API key

    LANGCHAIN_PROJECT

    Optional project name. Defaults to default

    LANGCHAIN_CALLBACKS_BACKGROUND

    true to upload traces asynchronously

  3. Restart 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:

Last updated

Was this helpful?