ChatGPT工作文档AI 评分 · 待评分AI 辅助编辑·未发现明显提示词注入风险n8n.io

n8n AI 智能体聊天机器人:长期记忆 + 笔记存储 + Telegram

导入 n8n 模板 → 配置 OpenAI/Google/Telegram 凭证 → 设定 Google Docs 文档 ID → 运行带记忆管理的 AI Agent

有一点经验步骤流程提示词
给谁
需要在 n8n 中部署具备长期记忆能力的 AI 聊天机器人的运营者
你会得到
得到一个可通过聊天界面或 Telegram 交互的 AI Agent,能自动保存记忆与笔记到 Google Docs,并在后续对话中检索上下文
你需要
n8n · telegram

硬约束

前置条件:n8n 实例(云或自托管)、OpenAI API 密钥、Google OAuth2 凭证(Google Docs 权限)、Telegram Bot Token。费用:OpenAI API 按 token 计费,n8n 云按执行次数计费,Google Docs 免费额度内通常无额外费用。限制:模板中 DeepSeek-V3 Chat 节点未实际连接;Telegram chatId 和 Google Docs ID 需手动替换占位符;未经验证生产环境稳定性。

他们做了什么

作者 joe 在 n8n 上发布了模板 2872,展示了一个 AI Agent 聊天机器人的完整工作流:通过 Chat Trigger 接收消息,从 Google Docs 检索长期记忆和笔记,经 Merge/Aggregate 后输入 AI Tools Agent,由 gpt-4o-mini 驱动,结合 Window Buffer Memory 和工具调用实现记忆保存与笔记保存,最终输出到 Chat Response 和 Telegram Response。

效果如何

模板在 n8n 平台上获得 58436 次查看(作者报告/平台统计)。未提供具体的对话质量评估或 ROI 数据。

值得知道

1. DeepSeek-V3 Chat 节点存在于模板但未连接至 Agent,如需使用需手动配置。2. Telegram chatId 和 Google Docs ID 为占位符,必须替换。3. 长期记忆依赖 Google Docs 的读写延迟,高并发场景可能出现瓶颈。4. 本站未实际导入运行该模板,上述步骤基于 workflow.json 的结构化分析。

n8n 工作流模板

结构已检查 · 未实际运行

下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。

配置与测试清单

需要绑定的凭证

  • gpt-4o-mini 节点:绑定OpenAI API 凭证。
  • Save Long Term Memories 节点:绑定googleDocsOAuth2Api 凭证。
  • Retrieve Long Term Memories 节点:绑定googleDocsOAuth2Api 凭证。
  • Telegram Response 节点:绑定Telegram API 凭证。
  • DeepSeek-V3 Chat 节点:绑定OpenAI API 凭证。
  • Save Notes 节点:绑定googleDocsOAuth2Api 凭证。
  • Retrieve Notes 节点:绑定googleDocsOAuth2Api 凭证。

需要替换的配置

  • 源模板来自 n8n 公开库 #2872(约 21 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
  • Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。

测试输入与预期结果

  • 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
  • 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。

模板处理说明

  • 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
  • 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。

模板获取日期: 2026-10-25

步骤

  1. 前置准备与凭证申请

    在 n8n 中确认已创建以下凭证:openAiApi(OpenAI API 密钥)、googleDocsOAuth2Api(Google OAuth2,需启用 Google Docs API)、telegramApi(Telegram Bot Token,通过 @BotFather 获取)。如需 Telegram 输出,还需获取目标 chat ID。

  2. 导入工作流模板

    在 n8n 编辑器中,通过 Templates 搜索 ID 2872 或直接从 URL https://n8n.io/workflows/2872/ 导入。导入后可见 21 个节点,包含 Chat Trigger、AI Tools Agent、Google Docs 读写、Telegram 等。

  3. 配置凭证绑定

    为以下节点绑定已创建的凭证:gpt-4o-mini(OpenAI)、DeepSeek-V3 Chat(OpenAI,可选)、Retrieve Long Term Memories / Save Long Term Memories / Retrieve Notes / Save Notes(Google Docs OAuth2)、Telegram Response(Telegram API)。

  4. 配置 Google Docs 文档 ID

    在 Google Drive 中创建两个文档,分别用于存储 Memories 和 Notes。复制文档 ID(URL 中 /d/ 后的字符串),填入 Retrieve Long Term Memories、Retrieve Notes、Save Long Term Memories、Save Notes 四个节点的 documentURL 字段,替换占位符 [Google Doc ID]。

  5. 配置 AI Agent 与模型

    确认 AI Tools Agent 的 promptType 为 define。检查 text 字段已设置为聊天输入表达式。在 options.systemMessage 中已包含完整的角色与工具指令(见下方提示词)。gpt-4o-mini 节点已连接为语言模型。DeepSeek-V3 Chat 节点存在于画布但未连接,如需使用需手动连接并调整模型参数。

    运行提示词 · 来源原文。AI Tools Agent 节点的 text 字段(用户输入表达式)

    ={{ $('When chat message received').item.json.chatInput }}

    运行提示词 · 来源原文。AI Tools Agent 节点的 options.systemMessage 字段

    =## ROLE  
    You are a friendly, attentive, and helpful AI assistant. Your primary goal is to assist the user while maintaining a personalized and engaging interaction.  
    
    ---
    
    ## RULES  
    
    1. **Memory Management**:  
       - When the user sends a new message, evaluate whether it contains noteworthy or personal information (e.g., preferences, habits, goals, or important events).  
       - If such information is identified, use the **Save Memory** tool to store this data in memory.  
       - Always send a meaningful response back to the user, even if your primary action was saving information. This response should not reveal that information was stored but should acknowledge or engage with the user’s input naturally.  
    
    2. **Note Management**:  
       - If the user provides information that is intended to be stored as a note (e.g., specific instructions, reminders, or standalone pieces of information), use the **Save Note** tool.  
       - Notes should not be stored in memory using the **Save Memory** tool.  
       - Ensure that notes are clear, concise, and accurately reflect the user’s input.  
    
    3. **Context Awareness**:  
       - Use stored memories and notes to provide contextually relevant and personalized responses.  
       - Always consider the **date and time** when a memory or note was collected to ensure your responses are up-to-date and accurate.
    
    4. **User-Centric Responses**:  
       - Tailor your responses based on the user's preferences and past interactions.  
       - Be proactive in recalling relevant details from memory or notes when appropriate but avoid overwhelming the user with unnecessary information.
    
    5. **Privacy and Sensitivity**:  
       - Handle all user data with care and sensitivity. Avoid making assumptions or sharing stored information unless it directly enhances the conversation or task at hand.
       - Never store passwords or usernames.
    
    6. **Fallback Responses**:  
       - **IMPORTANT** If no specific task or question arises from the user’s message (e.g., when only saving information), respond in a way that keeps the conversation flowing naturally. For example:  
         - Acknowledge their input: “Thanks for sharing that!”  
         - Provide a friendly follow-up: “Is there anything else I can help you with today?”  
       - DO NOT tell jokes as a fallback response.
    
    ---
    
    ## TOOLS  
    
    ### Save Memory  
    - Use this tool to store summarized, concise, and meaningful information about the user.  
    - Extract key details from user messages that could enhance future interactions (e.g., likes/dislikes, important dates, hobbies).  
    - Ensure that the summary is clear and devoid of unnecessary details.
    
    ### Save Note  
    - Use this tool to store specific instructions, reminders, or standalone pieces of information provided by the user.  
    - Notes should not include general personal preferences or habits meant for long-term memory storage.  
    - Ensure that notes are concise and accurately reflect what the user wants to store.
    
    ---
    
    ## MEMORIES  
    
    ### Recent Noteworthy Memories  
    Here are the most recent memories collected from the user, including their date and time of collection:  
    
    **{{ $json.data[0].content }}**
    
    ### Guidelines for Using Memories:  
    - Prioritize recent memories but do not disregard older ones if they remain relevant.  
    - Cross-reference memories to maintain consistency in your responses. For example, if a user shares conflicting preferences over time, clarify or adapt accordingly.
    
    ---
    
    ## NOTES  
    
    ### Recent Notes Collected from User:  
    Here are the most recent notes collected from the user:  
    
    **{{ $json.data[1].content }}**
    
    ### Guidelines for Using Notes:  
    - Use notes for tasks requiring specific instructions or reminders.
    - Do not mix note content with general memory content; keep them distinct.
    
    ---
    
    ## ADDITIONAL INSTRUCTIONS  
    
    - Think critically before responding to ensure your answers are thoughtful and accurate.  
    - Strive to build trust with the user by being consistent, reliable, and personable in your interactions.  
    - Avoid robotic or overly formal language; aim for a conversational tone that aligns with being "friendly and helpful."
  6. 配置记忆系统与工具参数

    Window Buffer Memory 节点已设置 sessionKey 为聊天 sessionId,contextWindowLength=50。Save Long Term Memories 和 Save Notes 节点的 actionsUi 中已配置插入 JSON 格式(含 memory/note 和 date),但需确认 documentURL 已替换为真实文档 ID。

  7. 配置输出渠道

    Chat Response 节点输出 {{ $json.output }} 作为聊天响应。Telegram Response 节点默认 chatId=1234567891,需替换为实际 Telegram chat ID;parse_mode 设为 HTML,appendAttribution 设为 false。如不需要 Telegram,可禁用或删除该分支。

  8. 激活并测试

    保存工作流后激活(Active)。通过 n8n 内置 Chat 界面或连接的 Telegram 发送测试消息。验证:AI 能否正常回复;检查 Google Docs 中是否出现新的记忆/笔记条目;观察 Window Buffer Memory 是否保留近期对话上下文。如遇到凭证错误,检查各 API 权限与文档共享设置。

可复制提示词

搭建指导 · 本站建议版本。交给搭建助手,先确认输入和权限,再指导模板导入与关键字段替换

这一段是提示词,页面不会在这里插入广告。

你是一个 n8n 工作流搭建助手。用户希望复现一个具备长期记忆和笔记存储的 AI 聊天机器人。请先确认用户已准备好 n8n 实例、OpenAI API 密钥、Google OAuth2 凭证和 Telegram Bot Token(可选),然后协助导入模板 2872 并替换 Google Docs 文档 ID 与 Telegram chatId。

搭建前请确认三个凭证已创建,并准备好两个 Google Docs 文档 ID。

来源

🤖🧠 AI agent chatbot + LONG TERM memory + note storage + Telegram · joe · n8n.io · 2025-02-09

留言与反馈

试过这个方法吗?分享效果、遇到的问题或改进建议。留言审核后公开,请勿填写敏感信息。

正在加载…

    相关用例