Skip to content
AI Agent How-To

Home › Framework how-tos

n8n AI Agent Memory: How to Make Your Agent Remember (and Fix It When It Doesn't)

Intermediate ~3 min read Last tested October 2026

Updated 2026-10-15

By default, an n8n AI Agent node has no memory: each execution starts fresh. You fix that by attaching a memory sub-node. The most common bug is not the memory node itself but the session key.

Prerequisites

  • n8n (Cloud or self-hosted), a recent 1.x version
  • An AI Agent workflow with a chat model attached (OpenAI, Anthropic, etc.)

Steps

1. Pick a memory type

NodeStores data inUse it when
Simple Memory (formerly Window Buffer Memory)n8n process memoryTesting, single-instance setups. Lost on restart, not shared in queue mode.
Postgres Chat MemoryPostgres tableProduction, survives restarts
Redis Chat MemoryRedisProduction, fast, optional TTL

There are also memory nodes for other stores (e.g. MongoDB, Zep, Motorhead) depending on your n8n version.

2. Attach the memory node

  1. Open the AI Agent node’s canvas. Below it are connectors for Chat Model, Memory and Tool.
  2. Click + under Memory and choose Simple Memory (or Postgres Chat Memory).
  3. Set Context Window Length, the number of past interactions to keep (e.g. 10).

3. Set the session key (the important part)

The session key decides whose conversation is loaded.

  • With the Chat Trigger (n8n’s built-in chat), the default Connected Chat Trigger Node uses sessionId automatically.
  • With any other trigger (Telegram, WhatsApp, Webhook, Slack), switch Session ID to Define below and use an expression that is unique per user, for example:
Telegram:  {{ $('Telegram Trigger').item.json.message.chat.id }}
Webhook:   {{ $json.body.user_id }}
Slack:     {{ $('Slack Trigger').item.json.channel }}

Without this, every user shares one memory, or memory is empty on each run.

4. Use Postgres for production

  1. Add a Postgres Chat Memory node instead of Simple Memory.
  2. Create a Postgres credential.
  3. Leave Table Name at the default (n8n_chat_histories) and n8n creates it on first run.
  4. Use the same session key expression as above.

5. Test

Open the chat panel, say “My name is Sam”, then ask “What’s my name?” In the execution log, the memory node should show the earlier messages being loaded.

Common errors / fixes

Agent forgets everything between messages: the session key is different on each run (e.g. uses an execution ID) or empty. Check the memory node’s input in the execution log.

No session ID found: you’re not using the Chat Trigger but left Session ID on Connected Chat Trigger Node. Switch to Define below.

Memory works in the editor, not in production (queue mode): Simple Memory lives in one worker’s RAM. Use Postgres or Redis memory.

Memory leaks between users: the session key is a constant. Make it per user or per chat.

Context gets too long and costs spike: lower Context Window Length.