Session ID Type to "Define below" → expression: {{ $('Telegram Trigger').item.json.message.chat.id }} (or chat.id from your channel). Other 13%: memory port wired to main input instead of the bottom Memory port, Window Buffer too small (default k=5), or no DB persistence on container restart.If your n8n AI Agent keeps forgetting the last message, losing context between runs, or responding like every chat is brand new — it's almost always one of four wiring issues. Here's how to diagnose and fix it in under 10 minutes.
{{ $json.id }} from the trigger and that id changes every execution (like a new webhook UUID), memory resets every run. Fix: use the chat/user ID from your channel (Telegram chat_id, WhatsApp phone number, Slack thread_ts) — not the execution ID.sessionIdType is "Define below" with a stable expression.n8n_chat_histories table exists and rows are being written.Rule of thumb: if the bot needs to remember a user tomorrow, you need a database-backed memory node — period.
I've debugged dozens of broken n8n agents for San Diego clients and the pattern is almost always the same: someone followed a YouTube tutorial, dropped in a Window Buffer Memory node, left the sessionId as "Take from previous node automatically" — and the trigger is a webhook that generates a new execution ID each call. Every message looks like a brand new conversation to the agent.
The fix is a one-liner in the memory sub-node. Set Session ID to something stable like {{ $('Telegram Trigger').item.json.message.chat.id }} or {{ $json.from }} for WhatsApp. That single change fixes memory for most agents I see.
Sometimes memory is wired correctly — you can see prior messages in the agent's input — but the model still "forgets." That's a prompt engineering issue, not an n8n bug. Add an explicit system prompt: "You have access to the full conversation history below. Reference it when answering follow-up questions." Smaller models (Haiku, Gemini Flash, GPT-4o-mini) especially need to be told to use the memory they've been given.
I fix broken n8n AI agents for San Diego businesses — no retainer, flat $100/hr, and most memory issues I solve inside the first hour. Text me the workflow screenshot and I'll tell you what's wrong before you even hire me.
Send a screenshot of your workflow. I'll diagnose it free and quote a fix — usually under 2 hours at $100/hr.
Text 858-461-8054Don't see what you were looking for?
Text PJ a sentence about what you actually need — I'll build you a free custom shareable on the house. No email, no funnel, no SOW.
📲 Text PJ — free shareable87% of the time, the sessionId is dynamic — you're passing {{ $json.id }} or {{ $execution.id }} from the trigger, which generates a new value every run, so memory resets every message. Fix: in the memory sub-node, set Session ID Type to 'Define below' and use a stable identifier from the channel — {{ $('Telegram Trigger').item.json.message.chat.id }} for Telegram, or {{ $json.user_id }} for a custom webhook.
The memory sub-node does NOT connect to the main flow input. It plugs into the small dot underneath the AI Agent node, labeled 'Memory'. If you connected it to the regular flow input arrow, the agent runs with zero memory every execution. Open the AI Agent node — there are 3 sub-input ports (Chat Model, Memory, Tools). Memory must connect to the Memory port specifically.
Window Buffer Memory: in-memory only, dies on workflow restart — use for prototyping only. Postgres Chat Memory: best default for production — free, persistent, easy to query. Redis Chat Memory: faster, good for high-traffic bots. If the bot needs to remember a user tomorrow, you need a database-backed node — period.
Two common causes: (1) Window Buffer k value too low — defaults to 5 interactions, so message 6 drops message 1. Bump k to 10-20 for short chats, or switch to Postgres + summarization for long ones. (2) Token overflow — your model's context window is full and older messages get silently truncated. Switch to Claude Sonnet (200k context) or add a summarization step before the agent.
You're using Window Buffer Memory (in-process only) on a Docker container without a persistent volume. Window Buffer lives in process memory, not SQLite, so it doesn't survive restarts. Fix: switch to Postgres Chat Memory and point it at a Postgres instance (can be a sibling Docker container with a mounted volume). Postgres is the right answer for any production n8n deployment.