Skip to main content

Build custom AI agent with LangChain & Gemini (self-hosted)

Workflow preview

Workflow preview
100%
Build custom AI agent with LangChain & Gemini (self-hosted) preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow 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 unnecessa...

Best for

  • Miscellaneous automation workflows
  • AI Chatbot automation workflows
  • intermediate n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.chattrigger, @n8n/n8n-nodes-langchain.lmchatgooglegemini, n8n-nodes-base.stickynote, @n8n/n8n-nodes-langchain.memorybufferwindow, @n8n/n8n-nodes-langchain.code

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by shepard.

Original n8n.io source

1.1 Workflow description

Title
Build custom AI agent with LangChain & Gemini (self-hosted)
Workflow name
Build custom AI agent with LangChain & Gemini (self-hosted)

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

  1. Configure Gemini Credentials: Set up your Google Gemini API key (Get API key here if needed). Alternatively, you may use other AI provider nodes.
  2. Interaction Methods:
    • Test directly in the workflow editor using the "Chat" button
    • Activate the workflow and access the chat interface via the URL provided by the When Chat Message Received node

Customization Options

  1. Interface Settings: Configure chat UI elements (e.g., title) in the When Chat Message Received node
  2. Prompt Engineering:
    • Define agent personality and conversation structure in the Construct & Execute LLM Prompt node's template variable
    • ⚠️ Template must preserve {chat_history} and {input} placeholders for proper LangChain operation
  3. Model Selection: Swap language models through the language model input field in Construct & Execute LLM Prompt
  4. Memory Control: Adjust conversation history length in the Store Conversation History node

Requirements:

⚠️ This workflow uses the LangChain Code node, which only works on self-hosted n8n.
(Refer to LangChain Code node docs)

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.1

Block 2 - Google Gemini Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 3 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 4 - Store conversation history

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

Block 5 - Construct & Execute LLM Prompt

Type / Role
@n8n/n8n-nodes-langchain.code - code
Config choices
Version 1

Block 6 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 7 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 8 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 9 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

3. Summary Table

Workflow Build custom AI agent with LangChain & Gemini (self-hosted)
Complexity intermediate
Nodes 9
Categories Miscellaneous, AI Chatbot
Author shepard
Published 26 Mar 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/3326/3326.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Build custom AI agent with LangChain & Gemini (self-hosted) do?

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 unnecessa...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Miscellaneous, AI Chatbot use case.