# n8n WhatsApp AI agent memory: which Session ID to use (and the one that merges every user)

*Updated 2026-10-29.*

**Symptom:** you connect Simple Memory to an AI Agent behind a **WhatsApp Trigger** and the memory node fails with `No session ID found ... Expected to find the session ID in an input field called 'sessionId'`. Or the error is gone, but the bot repeats one customer's details to another. Both come from the same setting: the memory node's **Session ID**. This page is only about WhatsApp. If you use the Chat Trigger, Postgres errors or LangGraph, see the related pages at the end.

*Disclosure: I work on MemorySync (I'm Mohammed, the founder). I drafted this page with AI assistance and checked it against the source thread and the official docs listed under Sources on Oct 28, 2026. I read the threads and docs; I didn't run a WhatsApp workflow for this page.*

## The question

In the n8n forum thread ["Simple memory issue"](https://community.n8n.io/t/simple-memory-issue/259690) (Feb 3, 2026), a beginner using the WhatsApp Trigger got this on the Simple Memory node:

```text
No session ID found
Expected to find the session ID in an input field called 'sessionId' (this is what the chat trigger node outputs). To use something else, change the 'Session ID' parameter
```

The only reply said that with a WhatsApp Trigger "you should reference a Session ID" and pointed to a screenshot. The thread closed automatically after 90 days with no accepted answer. An earlier thread, ["Connect Simple Memory to WhatsApp Trigger error"](https://community.n8n.io/t/connect-simple-memory-to-whatsapp-trigger-error/160944), shows the same failure and two different keys, and only one of them is right for a bot that talks to many people.

**Status (checked Oct 28, 2026):** both threads are closed (auto-closed 90 days after the last reply), neither has a marked solution.

## Why it happens

Per n8n's [Simple Memory common issues](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memorybufferwindow/common-issues) page, the `sessionId` is normally read from the On Chat Message trigger, and if you're not using that trigger "you'll need to manage sessions manually." The WhatsApp Trigger doesn't output a `sessionId` field, so the default "Connected Chat Trigger Node" setting finds nothing.

## The fix: key memory on the sender

In Simple Memory (or Postgres/Redis Chat Memory), set **Session ID** to **Define below** and use the sender's WhatsApp ID. This is the expression the original poster in the second thread confirmed worked:

```text
{{ $('WhatsApp Trigger').item.json.contacts[0].wa_id }}
```

Per Meta's [webhook payload reference](https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/reference/messages), `contacts[].wa_id` is the customer's WhatsApp ID and `messages[].from` is the sender, so `{{ $('WhatsApp Trigger').item.json.messages[0].from }}` identifies the same person.

## Example: the memory node config

This is the Postgres Chat Memory node with the WhatsApp sender as the key, written as n8n workflow JSON. The parameter names (`sessionIdType: "customKey"` is the **Define below** option, `sessionKey`, `tableName`, `contextWindowLength`) come from the n8n source (`packages/@n8n/nodes-langchain/nodes/memory/descriptions.ts` and `MemoryPostgresChat.node.ts`). The expression is the one from the forum thread. *I didn't import or run this. Check it against your n8n version.*

```json
{
  "name": "Postgres Chat Memory",
  "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
  "parameters": {
    "sessionIdType": "customKey",
    "sessionKey": "={{ $('WhatsApp Trigger').item.json.contacts[0].wa_id }}",
    "tableName": "n8n_chat_histories",
    "contextWindowLength": 10
  }
}
```

In the UI that's **Session ID: Define below** and **Key:** `{{ $('WhatsApp Trigger').item.json.contacts[0].wa_id }}`. Simple Memory uses the same Session ID setting, without the table name.

## The trap: `metadata.phone_number_id`

The other suggestion in that thread was `{{ $node["WhatsApp Trigger"].json.metadata.phone_number_id }}`. It clears the error, but per Meta's reference `metadata.phone_number_id` identifies **your business number**, not the person writing to it. Every contact then shares one session, so the bot mixes up what different people told it. For a companion bot that's the worst failure: it "remembers" one user's details in another user's chat.

n8n's docs make the same point about static keys: a fixed key like `my_test_session` is fine for testing, but set up real session management before publishing.

## Checklist

1. **Session ID = sender** (`contacts[0].wa_id` or `messages[0].from`), not `metadata.*`.
2. **Agent prompt = the message text**, for example `{{ $('WhatsApp Trigger').item.json.messages[0].text.body }}`. Non-text messages (images, audio, status updates) won't have `text.body`, so filter or branch on `messages[0].type` first.
3. **Test with two phones.** If the second number sees anything from the first, the key is shared.
4. **Plan for restarts.** Simple Memory lives in the n8n process. For memory that survives restarts, use Postgres or Redis Chat Memory with the same Session ID expression.
5. **Several memory nodes?** n8n's docs say all Simple Memory nodes share one memory instance by default unless you set different session IDs.

If you're on the Chat Trigger instead of WhatsApp, the same error is covered in [n8n AI Agent memory per user](https://memorysync.hashnode.dev/n8n-ai-agent-memory-per-user).

## Common questions

**Why does it work in the editor but not from WhatsApp?**
Usually because the test used a pinned or static session value. Live WhatsApp executions only carry what the trigger outputs, so the Session ID must be an expression on the trigger's data.

**Should I use the phone number as the key?**
`wa_id` is the stable per-contact identifier WhatsApp gives you, which is what memory needs. It is also personal data, so treat the memory table accordingly.

**Does the bot remember facts across weeks, or only the last messages?**
Chat Memory nodes keep a window of recent messages for that session. Remembering durable facts about a person (name, preferences) beyond that window needs a separate long-term memory step.

## If you want long-term memory per contact

The [MemorySync n8n guide](https://docs.memorysync.io/guides/n8n?utm_source=hashnode&utm_medium=organic_page&utm_campaign=v5_oct25&utm_content=pseo_n8n-whatsapp-ai-agent-memory-session-id) documents a MemorySync Chat Memory sub-node for the AI Agent's Memory port, with a **Session ID** (your conversation key) and an **End User ID** (the person chatting). Every MemorySync operation is scoped by End User ID, and the guide says to use the same value across Add, Search and Recall. For WhatsApp, the same `wa_id` expression can fill both fields. MemorySync extracts durable facts from the user's turns, and those facts are shared with every other MemorySync surface for that user. It's community nodes from npm, so per the guide it needs a self-hosted n8n instance for now (n8n Cloud verification is in progress). The package source is [memorysyncio/n8n-nodes-memorysync](https://github.com/memorysyncio/n8n-nodes-memorysync?utm_source=hashnode&utm_medium=organic_page&utm_campaign=v5_oct25&utm_content=tpl_n8n-nodes-memorysync). I haven't tested it with the WhatsApp Trigger. Read the [guide](https://docs.memorysync.io/guides/n8n?utm_source=hashnode&utm_medium=organic_page&utm_campaign=v5_oct25&utm_content=pseo_n8n-whatsapp-ai-agent-memory-session-id) first. To see save and recall in your browser, try the [MemorySync playground](https://memorysync.io/try?utm_source=hashnode&utm_medium=organic_page&utm_campaign=v5_oct25&utm_content=pseo_n8n-whatsapp-ai-agent-memory-session-id).

## Related pages

- [n8n Postgres Chat Memory: fixing 'Got unexpected type: user'](https://memorysync.hashnode.dev/n8n-postgres-chat-memory-unexpected-type-user)
- [LangGraph AsyncPostgresSaver: 'the connection is closed' in FastAPI](https://memorysync.hashnode.dev/langgraph-asyncpostgressaver-connection-is-closed-fastapi)
- [Codex CLI persistent memory with AGENTS.md and MCP](https://memorysync.hashnode.dev/codex-cli-persistent-memory-agents-md-mcp)

## Sources

- community.n8n.io/t/simple-memory-issue/259690 (closed, no accepted answer; read 2026-10-28)
- community.n8n.io/t/connect-simple-memory-to-whatsapp-trigger-error/160944 (closed; read 2026-10-28)
- n8n docs: Simple Memory node common issues
- Meta for Developers: WhatsApp Cloud API webhooks notification payload reference
- MemorySync docs: docs.memorysync.io/guides/n8n
