Why your OpenClaw agent loses WhatsApp conversations (and how to fix it)
Your agent says it has no history? Loses context between messages? We explain the real causes and the solutions we apply in production.
If your OpenClaw WhatsApp agent responds as if every message is the first one, loses the thread of conversation, or directly says "I have no context from previous conversations," this article is for you.
The real problem
OpenClaw keeps conversation context in the Node.js process RAM. This means every time the gateway restarts, all active context is lost. The agent starts each session from scratch.
Cause 1: Frequent gateway restarts
Every time you run `openclaw gateway restart`, the agent loses its entire context window. If the agent also has permissions to restart the gateway itself (via `openclaw doctor --fix` or other commands), it may be erasing its own memory without knowing.
**Solution**: Add an explicit rule in AGENTS.md: "NEVER execute openclaw gateway restart without approval." Restarts must be controlled and planned.
Cause 2: Incorrect dmScope
With `dmScope: "main"` (the default), all WhatsApp conversations share the same session. The agent mixes contexts between users โ it responds to Maria with Juan's information.
**Solution**: Configure `session.dmScope: "per-channel-peer"`. This creates an isolated session for each WhatsApp contact.
Cause 3: The model does not retain history
Some AI models have smaller context windows or handle history differently. With Kimi K2.5, for example, message history may not load correctly in all sessions.
**Solution**: Use models with large context windows (GPT-5.4, Claude Sonnet) and configure `compaction.mode: "safeguard"` with `reserveTokensFloor: 40000` to prevent silent context loss during compaction.
Cause 4: No memory instructions
The agent needs explicit instructions to save important information in persistent files. Without them, it relies solely on the context window which is lost on every restart.
**Solution**: Add instructions in AGENTS.md for the agent to write to `memory/YYYY-MM-DD.md` after important interactions, and read those files when starting each session.
The trick nobody tells you: JSONL transcripts
OpenClaw saves complete transcripts of all conversations in `~/.openclaw/agents/main/sessions/*.jsonl`. These files survive restarts and contain everything: sent messages, received messages, phone numbers, timestamps.
The agent can read these files with the `read` tool to check its own history before contacting someone. It is the most robust solution for memory persistence.
Recommended configuration
For a production sales agent, these are the values we use:
- `session.dmScope`: "per-channel-peer"
- `channels.whatsapp.dmHistoryLimit`: 50
- `agents.defaults.compaction.mode`: "safeguard"
- `agents.defaults.compaction.reserveTokensFloor`: 40000
- AGENTS.md with memory instructions and transcript access
With this configuration, the agent maintains consistent context even after gateway restarts.
Need help with your OpenClaw agent?
We configure, optimize and manage WhatsApp sales agents.
Contact us