Mindket

LangChain Code node examples: a chain and a Wikipedia tool

Newversion 1 · updated

Overview

An n8n workflow with two small LangChain demos in Code nodes: a hand-written chain that answers “Tell me a joke”, and an agent with a hand-written Wikipedia tool that answers what year Einstein was born.

LangChain Code node examples: a chain and a Wikipedia tool is an n8n workflow in the Developer category, listed by Mindket. It is free. This is version 1, last updated on . Download it on this page or copy its JSON, then import it into an n8n canvas. Nothing runs until you activate it in n8n.

At a glance

Runs in
  • n8n Cloud: import the file into a new workflow there
  • Your own n8n server: the same file and steps
  • Your own prompts: edit the two Set nodes that hold the questions
  • Another trigger: replace the manual trigger with a webhook, a chat or a schedule

Platform

Connects 2 apps

How it works

Trigger

Manual run

It starts when you press Execute workflow, and one press runs both demos with:

  • A request for a joke, set in the Set node
  • A question about Einstein, set in the Set1 node

Actions

  1. A Code node writes a prompt from the first question and pipes it into an OpenAI chat model
  2. The chain’s answer comes back as text in an output field
  3. An AI Agent takes the second question, with a Wikipedia tool that a second Code node supplies
  4. The agent looks the answer up and replies in its output field

Result

Two answers in the run: a joke from the hand-written chain, and Einstein’s birth year from the agent

Integrations

What you need before you start.

OpenAI

Language model

Runs gpt-5.6-terra for the hand-written chain and a chat model, gpt-5-mini by default, for the agent.

NeedsOpenAI API key, in an OpenAI credential

Wikipedia

Knowledge lookup

Answers the agent’s searches through the Wikipedia tool that the second Code node supplies.

NeedsNo sign-in

Workflow check

Checked by Mindket on 13 Nov 2026

Steps
5 steps, starting by hand
AI
2 steps call an AI model: Custom - LLM Chain Node and Agent
Sign-ins
Signs in to: OpenAI
API keys
No API key is left in the file
Step types
Mindket’s checker reads 2 of its 4 step types. It does not read: Code and AI Agent

Read from the workflow’s file, not from a run.

About

What it is

This n8n workflow shows how to write LangChain steps yourself in n8n’s LangChain Code node. One press of Execute workflow starts two demos side by side. In the first, a Code node builds a prompt from the question “Tell me a joke”, pipes it into an OpenAI chat model and returns the answer. In the second, an AI Agent gets a Wikipedia tool that a second Code node supplies, and answers “What year was Einstein born?”. Eight nodes do the work, beside two sticky notes that name the demos.

Who it suits

Developers who know some JavaScript and want a working pattern for custom LangChain code inside n8n before they write their own. Skip it if you want a finished business workflow. It holds two fixed questions and no output beyond the run.

Who uses it, and how
IndustryWho uses itHow they use itExample
SoftwareBackend developersCopy the chain’s code as the start of a custom prompt flowA developer changes the prompt line and keeps the rest.
AI engineeringPrototype buildersAdd a tool the agent can call, written as a Code nodeAn engineer swaps the Wikipedia class for a call to the company’s own search.
TrainingCourse authorsShow how n8n lets code join its AI nodesAn instructor runs both demos live in a workshop.
ConsultingAutomation consultantsFind where the built-in nodes stop and code has to take overA consultant reads the chain’s code before proposing a custom step.

You need some n8n and some JavaScript: import a file, add one OpenAI credential in two places and read two short scripts.

Where to use it

Any n8n that can reach OpenAI’s API and has the LangChain Code node will run it. Wikipedia needs no key.

  • n8n Cloud: import the file into a new workflow there
  • Your own n8n server: the same file and steps
  • Your own prompts: edit the two Set nodes that hold the questions
  • Another trigger: replace the manual trigger with a webhook, a chat or a schedule

Setup

Download saves a zip with workflow.json and Mindket’s setup notes in your downloads folder. The same OpenAI key serves both demos.

What you need first
NeedDetail
n8nOn n8n Cloud or on a server of your own, with the LangChain Code node
OpenAIAn API key for an OpenAI credential. The chain’s model is gpt-5.6-terra, and the agent’s is the node’s default
  1. In n8n, create a workflow, open its menu, choose Import from File and pick workflow.json.
  2. Add an OpenAI credential and select it in OpenAI Chat Model and in Chat OpenAI.
  3. Open Set and Set1 to read the two questions. Change them if you like.
  4. Press Execute workflow. Open the chain’s Code node for the joke and Agent for the Einstein answer.

How to use it

Press Execute workflow and both demos run from the same trigger. Each Code node can write to the browser’s console with console.log, and the tool’s Code node logs a line when the agent calls it.

What to change for a different result
To changeWhere
The questionsinput in Set and in Set1
The chain’s stepsThe code in the chain’s Code node
The agent’s toolThe code in the tool’s Code node
The modelsOpenAI Chat Model for the chain, Chat OpenAI for the agent

Example

A developer runs it unchanged, with “Tell me a joke” in Set and “What year was Einstein born?” in Set1.

The chain’s Code node returns an item whose output holds the model’s joke as text. Agent returns an output that gives Einstein’s birth year, 1879. A model can also answer that from memory without calling the tool.

For newcomers and experts

If you are new. n8n draws a workflow as boxes joined by lines, and each box, a node, does one job. LangChain is a toolkit for building apps around language models, and n8n’s AI nodes run on it. The LangChain Code node lets you write that code by hand. Run the file as it is first, then change one question.

For experts. The chain’s node reads whichever model is connected, so swapping the model node needs no code change.

Where to look closer
NodeWhat it doesWhat to know
The chain’s Code nodeA LangChain Code node in execute mode, with a main input and one required language model inputIt reads the model with getInputConnectionData, pipes the prompt into it and returns output
The tool’s Code nodeA LangChain Code node in supply data mode, with an AI tool outputIt returns a WikipediaQueryRun object for the agent to call
AgentAI Agent 1, a conversational agent by defaultIt reads its question from input, the field Set1 writes

Good to know

The original copy called a model that is gone, and its imports no longer exist.

  • Model: the original copy used n8n’s OpenAI Model node, whose default is gpt-3.5-turbo-instruct. OpenAI shut that model down on 28 September 2026. Its named replacement, gpt-5.6-terra, does not take the old completions endpoint, so Mindket’s copy uses a chat model node set to gpt-5.6-terra and the chain returns the reply’s content. OpenAI’s deprecations and model pages were read on 12 November 2026
  • Imports: the original code imported langchain/prompts and langchain/tools. The starter code in n8n’s current Code node, read on 12 November 2026, imports @langchain/core/prompts and @langchain/community/tools/wikipedia_query_run, and Mindket’s copy uses those
  • The agent’s model: Chat OpenAI leaves its model at the node’s default, gpt-5-mini. OpenAI’s page gives 11 December 2026 for its shutdown, with gpt-5.6-terra as the replacement
  • Curly braces: the chain treats the question as a prompt template, so a question with { and } in it is read as a variable
  • Billing: OpenAI bills one call for the chain and at least one for the agent
  • Your data: both questions go to OpenAI, and the agent’s search terms go to Wikipedia
  • Credentials: the JSON holds none

README and files

README

LangChain Code node examples: a chain and a Wikipedia tool

An n8n workflow with two small demos of n8n's LangChain Code node. In the first, hand-written code builds a prompt for
"Tell me a joke", pipes it into an OpenAI chat model and returns the answer. In the second, an AI Agent answers "What
year was Einstein born?" with a Wikipedia tool that a second Code node supplies.

What is inside

  • workflow.json: the workflow as n8n exports it, ten nodes. Eight do the work and two are sticky notes that name the
    demos ("Self-coded LLM Chain Node" and "Self-coded Tool Node"). It holds no credential.
  • README.md: these notes.

What we changed from the original copy

  • The first demo's model was n8n's OpenAI Model node, a completions model. With no model set it used
    gpt-3.5-turbo-instruct, which OpenAI shut down on 28 September 2026. The replacement OpenAI names,
    gpt-5.6-terra, does not take the legacy completions endpoint. The node is now an OpenAI Chat Model, version 1.2,
    named OpenAI Chat Model, with gpt-5.6-terra in its ID field.
  • A chat model returns a message, not plain text, so the chain's code now ends with (await chain.invoke()).content.
    The output is the reply's text, as before.
  • The chain imported langchain/prompts and the tool imported langchain/tools. n8n's own starter code for the node,
    read on 12 November 2026, imports @langchain/core/prompts and @langchain/community/tools/wikipedia_query_run, so
    the copy uses those paths. Its loader rewrites the old langchain/tools path but not langchain/prompts.
  • Both model nodes were linked to a credential in their author's n8n. The links are gone, so select your own.
  • The workflow's tag and its ids are gone.
  • Nothing else. The questions, the agent and the layout are the file's own.

Before you start

  • An n8n instance with the LangChain Code node, on n8n Cloud or your own server.
  • An OpenAI API key, for an OpenAI credential. Wikipedia needs no key.
  • Some JavaScript, to read the two scripts.

Set it up

  1. In n8n, create a workflow, open its menu and choose Import from File. Pick workflow.json.
  2. Add an OpenAI credential and select it in OpenAI Chat Model and in Chat OpenAI.
  3. Open Set and Set1 to read the two questions. Change them if you like.
  4. Press Execute workflow. Open Custom - LLM Chain Node for the joke and Agent for the Einstein answer.

How a run goes

  1. The manual trigger starts both demos. It feeds Set and Set1, which write one input field each.
  2. Custom - LLM Chain Node (LangChain Code, execute mode) has one main input and one required language model input.
    Its code builds a prompt with PromptTemplate.fromTemplate from input, reads the connected model with
    getInputConnectionData('ai_languageModel', 0), pipes the prompt into it and returns an item with output.
  3. Agent (AI Agent 1, a conversational agent by default) reads its question from input. It uses Chat OpenAI, whose
    model is left at the node's default, and Custom - Wikipedia.
  4. Custom - Wikipedia (LangChain Code, supply data mode, an AI tool output) logs a line and returns a
    WikipediaQueryRun object. The agent calls it when it wants to look something up.

Change the look

  • Questions: the input value in Set and Set1.
  • Chain: the code in Custom - LLM Chain Node. Chain more steps after the prompt, or parse the answer.
  • Tool: the code in Custom - Wikipedia. Return any LangChain tool object, such as one that calls your own search.
  • Models: OpenAI Chat Model for the chain and Chat OpenAI for the agent. The chain reads whichever model is
    connected, so swapping the node needs no code change.
  • Debugging: console.log inside a Code node writes to the browser's console.

Good to know

  • The chain treats the question as a prompt template, so a question with { and } in it is read as a variable.
  • Chat OpenAI leaves its model at the node's default, gpt-5-mini. OpenAI's deprecations page, read on 12 November
    2026, shuts that model down on 11 December 2026, with gpt-5.6-terra as the replacement.
  • A model can answer the Einstein question from memory and skip the tool. Watch the console for the line the tool
    logs to see whether it ran.
  • OpenAI bills one call for the chain and at least one for the agent.
  • Both questions go to OpenAI, and the agent's search terms go to Wikipedia.
  • The file holds no credential and no key.
Files
NOTICE.md  611 B
README.md  4 KB
workflow.json  6 KB

3 files, 11 KB, downloaded as a zip.

What’s new

  • Version 1 · 2026-11-12

Reviews

No ratings yet

Write a review

No reviews yet.

More from Mindket

See all from Mindket

Nanosaur2-670M

well9472 · Kit

Makes illustrations from text prompts with a small 670M-parameter diffusion model, run through ComfyUI. Built as a low-budget research model for people who wan…

New

Reads handwritten Arabic text from images and returns it as text. A fine-tuned PaddleOCR-VL model for people digitizing Arabic handwriting.

New

Makes video clips from a text prompt or an image plus text, at up to 720P and 24 frames per second, in the Diffusers format for a single consumer GPU.

New

Similar in Developer

See all in Developer

Wan2.2-S2V-14B

Wan-AI · Kit

Generates cinematic video of a character driven by an audio track, and can also lip-sync existing video. For video creators, animators and researchers with a l…

New

Wan2.2-Animate-14B

Wan-AI · Kit

Animates a character or swaps one into a video by copying a performer's movement and expressions, as one model from the Wan2.2 video family. Use only faces and…

New

d3-turbo

vllm-sr · Kit

Answers choice, yes-or-no, score, box and tracking questions about text, images or video in one call, with a probability for each answer. For people building r…

New