Your AI Agent Is Probably Forgetting Everything
Your AI Agent Is Probably Forgetting Everything
Most people who set up AI agents hit the same wall around day two.
The agent was working. Tasks were getting done. It remembered what you told it, knew the project names, held context across a conversation. Then something changed — a session reset, a context limit hit, a container restart — and now it's asking questions it should know the answers to. Referring to projects by the wrong name. Treating completed tasks as open.
The degradation is subtle at first. You think it's a fluke. You re-explain. It performs again. Then the next reset, same thing.
This isn't a model problem. The model is doing exactly what it's designed to do: attend to the context it has. If that context doesn't contain your project history, your preferences, or the decisions made last week — it has nothing to work with. The session is fresh. The agent is starting over.
Why Agent Memory Breaks
There are three layers to this problem.
Sessions. By default, OpenClaw resets daily or on idle timeout. That's intentional — a session that never resets accumulates stale context and costs more to run. The problem is what happens to the information in that session when it ends. If the agent hasn't written anything down before the reset, everything it learned is gone. Most default configurations don't have a memory flush, which means the agent can hit its context limit or idle timeout and silently discard the entire session.
Bootstrap truncation. OpenClaw injects bootstrap files — AGENTS.md, SOUL.md, your operating rules — into the agent's context at every session start. If the total size of those files exceeds bootstrapMaxChars, OpenClaw truncates them silently. The truncation rule is 70% from the head, 20% from the tail, 10% for a marker. In practice: the bottom of your AGENTS.md gets dropped. The security rules, the escalation tiers, the instructions added after initial setup — gone. The agent appears to ignore rules that are clearly in the file. This is the most common cause of "my agent is behaving wrong" after everything seemed to be working.
No write target. Most agents have nowhere to store persistent facts even when they try. They'll produce a summary in a final message. The session ends. The summary isn't stored anywhere the next session can read.
The Architectural Fix
The fix has three components, and all three are required.
Set bootstrapMaxChars explicitly. In openclaw.json, under agents.defaults:
"bootstrapMaxChars": 15000
Without this, OpenClaw uses its own default, which is lower. Keep AGENTS.md under 6,000 characters and load supplementary context conditionally via memory reads — not by injecting everything into the bootstrap.
Enable memoryFlush. In the compaction block:
"memoryFlush": {
"enabled": true,
"softThresholdTokens": 905000,
"prompt": "Append lasting notes to memory/YYYY-MM-DD.md (append only). Update MEMORY.md with durable facts only. Reply NO_REPLY if nothing to store.",
"systemPrompt": "Session nearing compaction. Store durable memories now."
}
This fires when the agent approaches the context limit. Instead of silently compacting and losing everything, the agent writes lasting notes to its daily memory file first. That's the difference between an agent that degrades after 24 hours and one that maintains continuity across sessions.
Build the memory hierarchy. The agent needs explicit places to write:
MEMORY.md— durable facts that survive session resetsmemory/YYYY-MM-DD.md— daily session logs- Instructions in AGENTS.md to write immediately after any task completion or state change, not at session end
The instruction I use: "The test: if the session reset right now, would this be lost? If yes, write it before doing anything else."
Without that instruction, an agent that works fine in isolation will quietly drop context every 24 hours. With it, what the agent learned on Monday is available on Friday.
One Command Worth Running Now
If you have an existing OpenClaw setup, run this:
docker exec [CONTAINER_NAME] openclaw sessions get main --bootstrap | wc -c
It returns the character count of what's actually being injected into the agent's context at session start. If the number is at or near your bootstrapMaxChars limit, you have silent truncation. The rules you think the agent is running — it isn't.
This single command explains a significant portion of "why is my agent ignoring this?" Run it before you debug anything else.
The full setup guide — VPS provisioning, Syncthing sync, subagent architecture, model selection, and the complete working openclaw.json — is available now: https://gumroad.com/l/alfred-stack
It covers the architecture above in full, plus the things that went wrong during setup and exactly how they failed. Eight to twelve hours of debugging documented as specific, reproducible steps. If you're building this to run something real, the guide gets you past the parts that aren't documented anywhere else.