Now inviting automation leaders: publish your playbook as a skill, under your own name. Publish yours →
Automation Skills
All skills/n8n ai nodes official/MEMORY
Reference · n8n ai nodes official

MEMORY

Part of n8n ai nodes official. Install the skill and your agent reads this page when it needs the depth.

Agent memory

Memory is wired as a sub-node on the Agent. Without it, every invocation is stateless. With it, the agent holds a conversation across turns (and across executions, depending on type) keyed by a sessionId.

n8n memory node availability shifts between versions, so check what's installed on the target instance with search_nodes({ queries: ['memory'] }).

The non-negotiables

  1. Plumb a stable key through. Memory buckets by whatever expression you bind to sessionKey. The chat trigger fills sessionId automatically. For other triggers, derive a stable identifier (Slack thread_ts, a webhook conversation ID, a generated UUID, a multi-tenant composite) and forward it to memory and any session-keyed tools. Without consistency across the same conversation, memory never matches.
  2. Default to memoryBufferWindow. It persists across executions via n8n's internal store, keyed on whatever you bind to sessionKey, and is the right choice for nearly every chat agent. Reach for memoryPostgres / memoryRedis only when memory needs to be queried or read outside the agent (your own UI displaying chat history, analytics, sharing memory across systems).

The memory types

memoryBufferWindow

In-execution memory of the last N turns. The default for "remember the last few exchanges in this conversation."

const bufferMemory = memory({
    type: '@n8n/n8n-nodes-langchain.memoryBufferWindow',
    config: {
        parameters: {
            contextWindowLength: 50,
        },
    },
})

contextWindowLength is the number of exchanges retained. The default is 5, which is very low for modern chat expectations, where users typically assume a conversation feels close to endless. 50 is a reasonable starting point for most chat agents. Higher = more context, more tokens.

Messages past the window are removed from memory entirely. Once the buffer fills, the oldest exchanges are dropped and the agent can't recall, search, or know they ever existed. If a user said something 60 turns ago and the window is 50, that information is gone from the agent's perspective. For recall beyond the window, raise contextWindowLength, or persist key facts in a Data Table that's read and injected into the system prompt.

Persistence: keeps the last N messages per memory key and persists across executions via n8n's internal store. With sessionIdType: 'customKey', you bind the key to any expression: {{ $json.sessionId }} from a chat trigger, a Slack thread_ts, a multi-tenant composite, etc. Multiple users / threads / contexts each get their own memory bucket. The "window" is the sliding cap on how many messages stay in context, not a scope on persistence.

Right for: the default for chat memory. Nearly every user-facing chat agent.

Postgres / Redis stores (when memory needs to be readable outside the agent)

Reach for these when memory needs to be queried or read outside the agent: displaying conversation history in your own UI, analytics on past chats, sharing memory across systems, or migrating to a different n8n instance cleanly. Not necessary just to make chat survive across executions, since memoryBufferWindow already does that.

const postgresMemory = memory({
    type: '@n8n/n8n-nodes-langchain.memoryPostgresChat',
    config: {
        parameters: {
            sessionIdType: 'customKey',
            sessionKey: '={{ $json.sessionId }}',
        },
        // ...connection config via credentials
    },
})

Right for: chat history exposed to non-agent code (your own UI, analytics, multi-system queries).

Wrong for: the default chat agent case. memoryBufferWindow is the cleaner pick.

Custom memory patterns (Memory Manager)

Most agents don't need this. The default memoryBufferWindow with a sensible contextWindowLength covers the vast majority of chat use cases. But when a fixed window isn't enough, the Chat Memory Manager node (@n8n/n8n-nodes-langchain.memoryManager) is a powerful lever for building custom patterns on top of any memory backend.

The node operates against any wired memory sub-node (BufferWindow, Postgres, Redis, etc.) and exposes three modes:

Pattern: rolling summarization

When a conversation runs long and you want the agent to retain the gist of older turns instead of dropping them entirely past the window:

  1. After each turn, load the buffer contents.
  2. If the buffer is approaching the cap, route to a summarizer branch (otherwise no-op).
  3. Run the older turns through an LLM that produces a concise summary.
  4. delete everything in the buffer.
  5. insert the summary back as a single message, plus optionally the most recent few turns to keep continuity.

The agent now sees [summary of turns 1-40] + [most recent 5 turns] instead of [turns 1-50], paying for far fewer input tokens while still having access to long-history context.

Other patterns built the same way

These are plausible patterns, but the Memory Manager node is more recent than the rest of n8n's memory tooling. Verify the modes you intend to use against your installed version before relying on them in production.

Session ID handling

Where the session ID comes from depends on the trigger:

Chat Trigger

Sets sessionId automatically. Wire it:

Webhook trigger

You manage it:

Either way, the session ID must be consistent across the whole conversation, including across reconnections.

Manual / scheduled

Usually no session. Use a stable identifier per "conversation" if one exists (Slack thread ID, ticket ID), otherwise memory adds nothing and should be omitted.

Memory and tools

When a tool is invoked, the tool's sub-workflow does NOT see conversation memory. Memory is the agent's context, not the tool's input. Pass needed context through fromAi parameters explicitly.

For tools that need session-keyed state, pass sessionId and have the tool look up state from a Data Table or storage keyed by session.

Memory and binary

Memory stores text turns. Binary uploaded mid-conversation is NOT in memory. It's in the chat trigger's files[] for that turn's input.

If the agent should remember "the user uploaded a file last turn":

In practice, inject the session's file inventory into the system prompt every turn (loaded by sessionId).

Common mistakes

Operational notes

Cross-references

Publish your skill

Copy this prompt into Claude Code, Codex or any agent. It walks you through your first skill in about 20 minutes, with you as the author.

Click to copy.