Build Custom AI Agent with LangChain & Gemini (Self-Hosted) — n8n Workflow

Low complexity Trigger4 nodes🏷️ Miscellaneous👁 4,410 viewsby shepard

Overview

Overview
This workflow leverages the LangChain code node to implement a fully customizable conversational agent. Ideal for users who need granular control over their agent's prompts while reducing unnecessary token consumption from reserved tool-calling functionality (compared to n8n's built-in Conversation Agent).

Setup Instructions
Configure Gemini Credentials: Set up your Google Gemini API key (Get API key here if needed). Alternatively, you may use other AI provider nodes.
Interacti

Nodes used

LangChain CodeSimple MemoryGoogle Gemini Chat Model

Workflow Preview

👇 Prompt Engineering
- Define agent personality and conversation structur
- ⚠️ Template must preserve `{chat_history}` and
Setup Instructions
1. Configure Gemini Credentials: Set up your Google Gem
👆 Interface Settings
Configure chat UI elements (e.g., title) in the `When C
👆 Model Selection
Swap language models through the `language model` input
👆 Memory Control
Adjust conversation history length in the `Store Conver
modelmemorymemory
W
When chat message received
Google Gemini Chat Model
Store conversation history
Construct & Execute LLM …
4 nodes4 edges

How it Works

  1. 1

    Trigger

    The workflow starts with a trigger trigger.

  2. 2

    Process

    Data flows through 4 nodes, connecting chattrigger, code, lmchatgooglegemini.

  3. 3

    Output

    The workflow completes its automation and delivers the result to the configured destination.

Node Details (4)

LA

LangChain Code

n8n-nodes-langchain.code

#1
SI

Simple Memory

n8n-nodes-langchain.memoryBufferWindow

#2
GO

Google Gemini Chat Model

n8n-nodes-langchain.lmChatGoogleGemini

#3

How to Import This Workflow

  1. 1Click Download JSON button on the right to save the workflow file.
  2. 2Open your n8n instance. Go to Workflows → New → Import from file.
  3. 3Select the downloaded build-custom-ai-agent-with-langchain-gemini-self-hosted file and click Import.
  4. 4Set up credentials for each service node (API keys, OAuth, etc.).
  5. 5Click Test Workflow to verify everything works, then activate it.

Or paste directly in n8n → Import from JSON:

{ "name": "Build Custom AI Agent with LangChain & Gemini (Self-Hosted)", "nodes": [...], ...}

Integrations

chattriggercodelmchatgooglegeminimemorybufferwindow

Get This Workflow

Download and import in one click

Download JSONView on n8n.io
Nodes4
Complexitylow
Triggertrigger
Views4,410

Created by

shepard

shepard

@shepard

Tags

chattriggercodelmchatgooglegeminimemorybufferwindow

New to n8n?

n8n is a free, open-source workflow automation tool. Self-host it or use the cloud version.

Get n8n Free →

Related Miscellaneous Workflows