n8n AI Agent Memory Setup

📝 Blog⏱ 5 min read

n8n AI Agent Memory Setup

Memory is what turns a single-turn LLM call into a conversational AI agent that remembers context across messages. In n8n, the AI Agent node supports multiple memory types so you can choose the right balance of simplicity, cost, and retention for your use case. This guide walks through every memory option, when to use each, and how to configure them step by step.

Why Memory Matters

Without memory, every message is treated as an isolated prompt. With memory, your agent can:

Memory Types in n8n AI Agent Node

n8n's AI Agent node supports four memory types:

Memory TypeRetentionBest ForComplexity
**Window Buffer**Last N messagesSimple chat, short sessionsLow
**Summary**Compressed historyLong conversations, token savingsMedium
**Vector Store**Semantic search over historyKnowledge retrieval, long-term recallHigh
**PostgreSQL / Redis**Full persistenceProduction apps, multi-sessionHigh

1. Window Buffer Memory

Simplest option — keeps the last N message pairs in context.

When to Use

Setup Steps

1. Open the AI Agent node 2. In the Memory section, select Window Buffer 3. Set Window Size (number of message pairs to keep) - Recommended: 5-10 for most chat use cases - Each pair = 1 user message + 1 assistant response 4. Save and test

Configuration Tips

2. Summary Memory

Compresses older messages into a running summary, keeping recent messages verbatim.

When to Use

Setup Steps

1. Select Summary memory type 2. Configure: - Summary Interval: How often to summarize (e.g., every 4 messages) - Recent Messages to Keep: Number of recent messages to keep verbatim (default: 2) - Summary Prompt: Custom prompt for summarization (optional) 3. Save and test

How It Works

Every N messages, the agent: 1. Takes the conversation so far 2. Sends it to the LLM with a summarization prompt 3. Stores the summary + recent messages 4. Next turn uses summary + recent messages as context

3. Vector Store Memory

Semantic search over conversation history using embeddings.

When to Use

Prerequisites

Setup Steps

1. Add a Vector Store node to your workflow (before or as sub-node) 2. Configure the vector store: - Index name, embedding model, credentials 2. In AI Agent node, select Vector Store memory 3. Select your vector store node 3. Configure: - Top K: How many past messages to retrieve (default: 4) - Similarity Threshold: Minimum relevance score (0.0-1.0, default: 0.7) - Filter: Optional metadata filter (e.g., by session_id) 4. Save and test

How It Works

Each conversation turn: 1. User message is embedded 2. Vector store searches for similar past messages 3. Top K results are injected into agent context 4. Agent response is stored for future retrieval

Pro Tips

4. PostgreSQL / Redis Memory (Persistent)

Full conversation persistence using a database.

When to Use

PostgreSQL Setup

1. Add Postgres node with credentials 2. Run the memory table migration (n8n provides SQL): ``sql CREATE TABLE n8n_ai_memory ( session_id TEXT PRIMARY KEY, messages JSONB NOT NULL, updated_at TIMESTAMP DEFAULT NOW() ); `` 2. In AI Agent node, select Postgres memory 2. Select your Postgres node 3. Configure table name and session key expression

Redis Setup

1. Add Redis node with credentials 2. In AI Agent node, select Redis memory 2. Configure key prefix and TTL (optional)

Combining Memory Types

You can combine memory types for best results:

CombinationUse Case
Window Buffer + Vector StoreRecent context + long-term knowledge
Summary + Vector StoreToken-efficient recent + semantic recall
Postgres + VectorFull audit trail + semantic search

To combine: add multiple memory configurations in the AI Agent node's memory section (n8n v1.0+ supports multiple).

Choosing the Right Memory

ScenarioRecommended Memory
Customer support chatWindow Buffer (5-10)
Personal assistantVector Store + Window Buffer
Long-running research agentSummary + Vector Store
Production support botPostgres + Vector Store
Quick prototypeWindow Buffer
Cost-sensitive high volumeSummary (reduces tokens)

Testing Memory

1. Start a conversation with the agent 2. Ask a question, then reference it later: "What did I just ask?" 3. Check the Execution Log in n8n 4. Open the AI Agent node execution → Memory tab 4. Verify stored messages match expectations 6. Adjust window size, top K, or threshold as needed

Common Issues

IssueCauseFix
Agent forgets contextWindow too smallIncrease window size
Token limit exceededWindow too large or no summaryReduce window or add Summary
Irrelevant memories retrievedVector threshold too lowIncrease similarity threshold
Memory not persistingPostgres/Redis not configuredCheck credentials and table
Memory leaking between usersMissing session_id filterAdd session_id metadata filter

Related Guides

Frequently Asked Questions

Window Buffer keeps the last N message pairs verbatim (recency-based). Vector Store embeds messages and retrieves semantically similar ones (relevance-based). Window Buffer is simpler and cheaper; Vector Store enables long-term semantic recall.

Use a session_id variable (from webhook, chat trigger, or expression) and configure metadata filters on Vector Store or Postgres memory to isolate conversations per session/user.

Yes. Use PostgreSQL or Redis memory for full persistence. The agent will remember conversations even after workflow restarts or days later when the user returns.

Summary memory uses the fewest tokens because it compresses older messages into a concise summary, keeping only the most recent messages verbatim.

Yes, n8n v1.0+ supports multiple memory configurations in a single AI Agent node. Common combinations: Window Buffer + Vector Store, or Summary + Vector Store.

Advertisement

Related Articles