Skip to content
AI Agent How-To

Home ›Framework how-tos

n8n AI Agent Memory: Setup & Fixes

Intermediate ~4 min read Last tested November 2026

Updated 2026-11-11

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. Pair memory with channel guides such as Connect an AI agent to Slack, WhatsApp, or HubSpot in n8n so each user keeps their own thread.

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 (n8n warns against using Simple Memory when the instance runs 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 (n8n AI agent memory not working)

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 or cap agent steps the way Fix: AI agent stuck in a loop describes for code-first agents.

FAQ

Why does my n8n AI agent forget the previous message?

The session key is empty or changes on every run. If the trigger is not the Chat Trigger, set Session ID to Define below and use an expression that stays the same for one user.

Which memory node survives a restart?

Postgres Chat Memory or Redis Chat Memory. Simple Memory lives in the n8n process. It is lost on restart and it is not shared in queue mode.

What table does Postgres Chat Memory use?

The default table name is n8n_chat_histories. n8n creates it on the first run.