π§ Build custom AI agent with LangChain & Gemini (self-hosted)
β‘ 5,873 views Β· π§ Miscellaneous
Description
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).
ζͺε±20250327 17.53.50.png
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.
- 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 Receivednode
Customization Options
- Interface Settings: Configure chat UI elements (e.g., title) in the
When Chat Message Receivednode - Prompt Engineering:
- Define agent personality and conversation structure in the
Construct & Execute LLM Promptnodeβs template variable - β οΈ Template must preserve
{chat_history}and{input}placeholders for proper LangChain operation
- Define agent personality and conversation structure in the
- Model Selection: Swap language models through the
language modelinput field inConstruct & Execute LLM Prompt - Memory Control: Adjust conversation history length in the
Store Conversation Historynode
Requirements:
β οΈ This workflow uses the LangChain Code node, which only works on self-hosted n8n.
(Refer to LangChain Code node docs)
π Nodes Used
LangChain Code, Simple Memory, Chat Trigger, Google Gemini Chat Model
π₯ Import
Download workflow.json and import into n8n:
Workflow menu β Import from File