AI Agent Chatbot with Long-Term Memory and Note Storage via Telegram - n8n Workflow

Deploy a powerful AI Agent chatbot using this advanced n8n workflow. Integrates LangChain memory, Google Docs for long-term data storage, and Telegram communication for personalized, contextual interactions.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Automation Specialists needing complex, stateful AI solutions.
Users looking for high-performance n8n templates for AI chatbots.
Developers requiring custom long-term memory storage mechanisms (Google Docs, databases).
Businesses aiming to create personalized customer service or internal knowledge retrieval agents.

Overview

This sophisticated n8n workflow demonstrates how to build a robust, conversational AI agent that maintains long-term memory and specific user notes, allowing for truly personalized interactions. Unlike simple chatbots, this architecture uses Google Docs as a persistent data store for memory and notes, ensuring the AI retains context across sessions. The system is initiated by a user message through a chat service (like Telegram). Before responding, the n8n automation retrieves all relevant historical context, feeds it into the AI Tools Agent n8n node, and then allows the AI to decide whether to simply respond, or use the Save Memory or Save Note tools. This approach makes this specific n8n workflow highly effective for retaining personal preferences, objectives, and ongoing project details. If you are searching for complex n8n templates that showcase the full power of LangChain integration within n8n, this solution is ideal.

How it Works

The core of this n8n workflow revolves around robust context management and intelligent tooling:


  1. Trigger and Retrieval: The process begins with the When chat message received n8n trigger, capturing a user's incoming message (likely from Telegram). Immediately, the workflow executes two parallel paths: Retrieve Long Term Memories and Retrieve Notes from Google Docs.

  2. Context Assembly: The retrieved memories and notes are consolidated with the current user message using the Merge and Aggregate n8n nodes, ensuring all historical context is presented to the AI.

  3. AI Agent Decision Making: The aggregated data flows into the AI Tools Agent n8n node. This agent, governed by detailed system instructions, uses the context, short-term conversational history (via the Window Buffer Memory n8n node), and its available Large Language Models (gpt-4o-mini or DeepSeek-V3 Chat) to formulate a plan.

  4. Tool Usage: Based on the user's input and the defined rules, the agent can decide to use its internal tools:

Save Long Term Memories: Used if the input contains generalized personal information (preferences, habits).
Save Notes: Used if the input is a specific instruction or reminder.

  1. Response Delivery: The AI Agent’s final textual response is captured by the Chat Response n8n node and then transmitted back to the user via the Telegram Response n8n node. This full loop ensures that the current conversation contributes to the long-term context stored in the persistent memory documents, making this a highly adaptive n8n workflow.

Installation Guide

To deploy this comprehensive n8n workflow, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON data and paste it into your n8n canvas using the 'New' -> 'Import from JSON' option.

  2. Set Up Credentials: You will need to configure three primary credentials:

LangChain Chat Trigger: Configure the credentials for the chat service initiating the workflow (e.g., Telegram).
OpenAI/API Key: Set up credentials for the Large Language Models (gpt-4o-mini or DeepSeek-V3 Chat). Note that DeepSeek uses an OpenAI API-compatible interface.
* Google Docs: Set up OAuth2 credentials for Google Docs, ensuring the account has write access to the documents.

  1. Configure Google Docs URLs: In the Retrieve Long Term Memories, Retrieve Notes, Save Long Term Memories, and Save Notes n8n nodes, replace the placeholder [Google Doc ID] with the actual Document IDs where memories and notes are stored. These documents serve as the database for the n8n workflow.

  2. Configure Telegram: Update the chatId field in the Telegram Response n8n node with your specific target chat ID.

  3. Activate: Save the n8n workflow and toggle the status to 'Active'. The When chat message received n8n trigger will now be listening for new messages.

Node Details

When chat message received (LangChain Chat Trigger): The starting n8n trigger for the entire automation. It listens for incoming chat messages to initiate the AI conversation sequence.
Retrieve Long Term Memories / Retrieve Notes (Google Docs Node): These n8n nodes are crucial for persistent memory. They perform a Get operation to fetch the existing conversational history and user notes from their respective Google Docs files, which are then injected into the AI context.
AI Tools Agent (LangChain Agent Node): This is the central brain of the n8n workflow. It uses a complex systemMessage defining its personality, rules, and how it must interact with the memory system and tools. It decides whether to generate a response or utilize one of the connected tools.
Window Buffer Memory (LangChain Memory Node): Provides short-term context for the current conversation session. It is configured to use the sessionId provided by the initial n8n trigger.
gpt-4o-mini / DeepSeek-V3 Chat (LangChain LLM Nodes): These models serve as the Large Language Model engine for the AI agent, providing the generative capabilities needed to process requests and utilize tools.
Save Long Term Memories / Save Notes (Google Docs Tool Node): These n8n nodes act as custom tools for the AI agent. They perform an Insert operation to append new, summarized memory or note data into the designated Google Docs file based on the agent's decision ($fromAI('memory')), effectively managing the long-term state of the n8n workflow.


  • Telegram Response (Telegram Node): The final action n8n node, responsible for sending the AI's generated response back to the user via Telegram.

Related n8n Workflows

Free

Nodes: 11 Nodes
Updated: December 26 2025
View all
Created by
Joseph LePage
Joseph LePage

As an AI Automation consultant based in Canada, I partner with forward-thinking organizations to implement AI solutions that streamline operations and drive growth.

Featured*