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:
- Reference earlier parts of the conversation
- Maintain user preferences and profile data
- Avoid repeating questions
- Build rapport through continuity
Memory Types in n8n AI Agent Node
n8n's AI Agent node supports four memory types:
| Memory Type | Retention | Best For | Complexity |
|---|---|---|---|
| **Window Buffer** | Last N messages | Simple chat, short sessions | Low |
| **Summary** | Compressed history | Long conversations, token savings | Medium |
| **Vector Store** | Semantic search over history | Knowledge retrieval, long-term recall | High |
| **PostgreSQL / Redis** | Full persistence | Production apps, multi-session | High |
1. Window Buffer Memory
Simplest option — keeps the last N message pairs in context.
When to Use
- Simple chatbots with short conversations
- Low token budget
- No need for long-term recall
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
- Window Size = 5 means the agent sees the last 5 user messages and 5 assistant responses
- Larger windows increase token usage linearly
- For token-constrained models (GPT-3.5), keep window ≤ 5
2. Summary Memory
Compresses older messages into a running summary, keeping recent messages verbatim.
When to Use
- Long conversations where you want token efficiency
- Agents that need high-level context but not verbatim history
- Reducing token costs on long sessions
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
- Agents that need to recall specific facts from long ago
- Knowledge-intensive conversations (support, research)
- When you need semantic relevance, not just recency
Prerequisites
- Vector store node configured (Pinecone, Qdrant, Chroma, PostgreSQL+pgvector, Weaviate, etc.)
- Embedding model configured (OpenAI text-embedding-3-small, Cohere, etc.)
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
- Use session_id metadata to isolate memory per user/conversation
- Set similarity threshold to 0.7-0.8 to avoid noise
- Combine with Window Buffer for recent context + vector for long-term
4. PostgreSQL / Redis Memory (Persistent)
Full conversation persistence using a database.
When to Use
- Production applications requiring durability
- Multi-session agents (user returns days later)
- Audit and compliance requirements
- Analytics on conversation history
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:
| Combination | Use Case |
|---|---|
| Window Buffer + Vector Store | Recent context + long-term knowledge |
| Summary + Vector Store | Token-efficient recent + semantic recall |
| Postgres + Vector | Full 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
| Scenario | Recommended Memory |
|---|---|
| Customer support chat | Window Buffer (5-10) |
| Personal assistant | Vector Store + Window Buffer |
| Long-running research agent | Summary + Vector Store |
| Production support bot | Postgres + Vector Store |
| Quick prototype | Window Buffer |
| Cost-sensitive high volume | Summary (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
| Issue | Cause | Fix |
|---|---|---|
| Agent forgets context | Window too small | Increase window size |
| Token limit exceeded | Window too large or no summary | Reduce window or add Summary |
| Irrelevant memories retrieved | Vector threshold too low | Increase similarity threshold |
| Memory not persisting | Postgres/Redis not configured | Check credentials and table |
| Memory leaking between users | Missing session_id filter | Add session_id metadata filter |
Related Guides
- n8n AI Agent Node Tutorial - Complete n8n agent tutorial
- No Code RAG Agent Builder - Vector store setup
- Self Hosted No Code AI Agent Builder - Self-hosted n8n setup