AI Agent: Enhance Chatbots with Long-Term Memory & Tool Integration
detail.loadingPreview
Empower your AI chatbot with n8n! Integrate long-term memory via Google Docs and leverage OpenAI tools for advanced conversational AI. Automate memory saving, retrieval, and notifications.
🚀Ready to Deploy This Workflow?
About This Workflow
How it works
This n8n workflow empowers AI agents with long-term memory capabilities by leveraging Langchain and various n8n nodes.
It starts with a chatTrigger to receive messages and an OpenAI Chat Model for initial processing. A memoryBufferWindow stores short-term context. The core logic is handled by the agent node, which uses a systemMessage to guide its behavior and offers tools for memory management.
A switch node acts as a router, directing the flow based on the agent's requested action: save_long_term_memory, retrieve_long_term_memory, send_memories_to_telegram, or send_memories_to_gmail.
- Saving Memories: The
save_long_term_memorytool uses agoogleDocsnode to append new memories (date and content) to a specified Google Doc. - Retrieving Memories: The
retrieve_long_term_memorytool also uses agoogleDocsnode to fetch existing memories from the same document. - Sending Memories: For notifications, memories are formatted into plain text for Telegram (
chainLlmthentelegramnode) or an HTML table for Gmail (chainLlmthengmailnode).
The workflow is designed to be triggered by other workflows or directly via a chat interface.
Key Features
- AI Agent with contextual awareness
- Long-term memory storage and retrieval using Google Docs
- Seamless integration with OpenAI for advanced LLM capabilities
- Real-time notifications via Telegram and Email
- Dynamic tool routing for memory management and communication
How To Use
- Configure Credentials: Ensure your OpenAI API Key, Google Docs OAuth2 credentials, and Telegram Bot Token are set up in n8n.
- Set Google Docs URL: Update the
documentURLparameter in theSave Long Term MemoriesandRetrieve Long Term Memoriesnodes with your target Google Doc ID. - Set Telegram Chat ID: Configure the
chatIdparameter in theSend Success Message to Telegramnode using an environment variable (e.g.,$env.TELEGRAM_CHAT_ID). - Set Email Address: Configure the
sendToparameter in theEmail Workflow Statsnode using an environment variable (e.g.,$env.EMAIL_ADDRESS_JOE). - Trigger the Workflow: Execute the workflow either directly or via another n8n workflow.
- Interact with the Agent: Send messages to the
chatTriggerwebhook URL. The AI agent will respond based on its instructions and memory.
Apps Used
Workflow JSON
{
"id": "b76edd1c-a69b-4cbb-96dd-f255614ef873",
"name": "AI Agent: Enhance Chatbots with Long-Term Memory & Tool Integration",
"nodes": 0,
"category": "AI & LLM",
"status": "active",
"version": "1.0.0"
}Note: This is a sample preview. The full workflow JSON contains node configurations, credentials placeholders, and execution logic.
Get This Workflow
ID: b76edd1c-a69b...
About the Author
Free n8n Workflows Official
System Admin
The official repository for verified enterprise-grade workflows.
Statistics
Related Integrations
- Google Sheets + Schedule Trigger(394 workflows)
- Telegram + Telegram Trigger(362 workflows)
- Google Sheets + Split Out(277 workflows)
- Gmail + Schedule Trigger(270 workflows)
- Google Sheets + Slack(268 workflows)
- Gmail + Google Sheets(245 workflows)
- Google Drive + Google Sheets(203 workflows)
- Form Trigger + Google Sheets(163 workflows)
- Schedule Trigger + Telegram(152 workflows)
- Google Drive + Google Drive Trigger(135 workflows)
Related Workflows
Discover more workflows you might like
DeepSeek AI Agent: Build Long-Term Memory Telegram Bots with OpenAI API
Automate Telegram bots with DeepSeek AI, OpenAI API, and long-term memory. Build intelligent agents that learn and personalize interactions.
Auto-Transcribe YouTube Videos to Text with AI
Instantly get YouTube video transcriptions. Input a URL, and this workflow uses Supadata and OpenAI to deliver accurate, structured text, saving you time.
Automate Blog Post Generation from Google Sheets to WordPress with AI
Effortlessly create and publish blog content by automating AI-powered content generation from your Google Sheet directly to WordPress. Save hours weekly!
Translate Telegram Audio to Text & Speech with AI in 55 Languages
Automate Telegram audio translation! This n8n workflow transcribes voice messages, translates them using AI, and replies with text and speech in 55+ languages.
Automate YouTube Video Summarization with AI & Google Sheets
Save hours weekly! Auto-summarize YouTube video transcripts using DeepSeek AI and sync key insights to Google Sheets. Perfect for researchers and content managers.
Auto-Transcribe YouTube Videos to Text with Supadata & OpenAI
Instantly get transcribed text from YouTube videos using Supadata API and OpenAI for structuring. Save hours on content review.