Adding chat memory to an n8n agent with MemorySync
说明与用途
本文说明如何将 MemorySync 社区节点连接到 n8n AI Agent,以在执行之间持久化聊天历史并检索长期事实。
问题
n8n’s AI Agent node only remembers conversation history while the workflow runs; after a workflow ends the chat history is lost, preventing long‑term context and fact lookup.
结果
The workflow persists chat history and user facts across executions, allowing the AI Agent to resume conversations and retrieve long‑term facts via MemorySync tools.
工作流
- Install the n8n-nodes-memorysync community node via Settings → Community Nodes → Install.
- Add a MemorySync API credential with a valid API key.
- Create a two‑node smoke test: Manual Trigger → MemorySync (Add Memory) with End User ID "alice" and a fact, then MemorySync (Search Memories) querying "what does Alice eat?".
- Build the AI Agent workflow: Chat Trigger → AI Agent, set the Memory port to MemorySync Chat Memory, configure Session ID and End User ID, leave Context Window Length at 10.
- Attach a MemorySync Search Memories node as a tool under the agent’s Tools, using the same End User ID expression.
- Optionally use the Recall Context operation in non‑agent workflows to fetch a single context block for a prompt.
证据
n8n's AI Agent node remembers a conversation only as long as its memory sub-node does.
The simplest option, Simple Memory, "stores a customizable length of chat history for the current session".
It moves the agent's chat history into MemorySync, so a conversation can pick up again in a later execution.
The node is marked as usable as a tool, so the agent can decide on its own when to look something up.
- 记录日期: 2026-10-20T17:56:27.234Z