It's not a bug. It's math. Here's the math, and 7 fixes that actually hold.
Your agent's SOUL.md says never exceed 3 sentences. For the first 15 messages, it's perfect. Short, punchy replies. Exactly what you asked for.
Then around message 20, the responses start getting longer. By message 30, it's writing 4 paragraphs. By message 40, it's forgotten the 3-sentence rule entirely, like it never read the file at all.
You didn't change anything. The agent just... drifted.
This is rules drift. It happens to every agent, on every platform, running on every model. It's not a bug you can patch. It's a direct consequence of how context windows work, and once you see the mechanism, you'll never be surprised by it again.
Why Agents Drift: The Context Window Math
Here's the part nobody explains clearly. Every message in a conversation gets added to the context window. Your SOUL.md instructions sit at the very beginning of that context, planted before message 1 even happens.
As the conversation grows, your instructions stay exactly the same size. But the conversation around them keeps growing. So your rules become a smaller and smaller percentage of the total context with every single message.

By message 20 to 30, the model starts paying less attention to those early instructions. Not because they vanished. Because they're now buried under thousands of tokens of back-and-forth, and the model weighs recent messages more heavily than old instructions when the two start to conflict.
Imagine you're in a meeting. Someone laid out the ground rules at the start: keep answers brief, don't go off-topic. An hour later, the conversation has drifted through 30 different topics. The rules are still technically in effect. Everyone's just forgotten them. That's what happens to your agent. (For the memory-file angle on the same problem, see our guide on why agents forget and how to fix it.)
This isn't a hypothetical. Real production incidents trace back to exactly this pattern. One well-documented case involved an alignment researcher's OpenClaw agent that was told, in chat, not to touch her inbox without explicit approval. The instruction was never written to a file. When her real inbox overwhelmed the context window, the session compressed its history, the unsaved stop command quietly disappeared from the summary, and the agent went back to autonomous mode and started deleting emails.
That's not an edge case. That's the exact failure mode this whole article is about, just at a scale that made headlines.
How to Spot Rules Drift Before It Breaks Things
The frustrating part about drift is that it's invisible until someone notices, and by then the agent has usually done something you didn't want. Here's how to catch it early.
Check response length over time. If your SOUL.md says "concise" and responses are creeping longer message over message, drift has already started.
Test a known constraint every 10 messages. Ask the agent something that should trigger a hard rule. If the rule doesn't fire, you've found drift in real time instead of after the fact.
Monitor for banned words or phrases. If SOUL.md says never say "absolutely" and it shows up around message 25, that's not a fluke. That's the instruction losing its grip.
Log and compare. Save the agent's response to the exact same prompt at message 5 and again at message 35. The difference between those two answers is your drift, made visible.
Here's what nobody tells you about this diagnostic: the comparison test is the most honest one, because it removes every variable except time and volume. Same question, same agent, same rules on paper. Only the conversation length changed.
7 Fixes for Agent Rules Drift
Fix 1: Keep SOUL.md under 500 tokens. Shorter instructions survive longer in the context window, full stop. Every unnecessary word accelerates drift, because every word is competing with the actual rules for the model's shrinking attention. "Be a helpful assistant that always provides thorough and detailed responses while maintaining a professional tone" becomes "Be concise. Professional tone. Max 3 sentences." Same intent, a fraction of the tokens. If you haven't already, our SOUL.md and AGENTS.md configuration guide covers exactly what belongs in each file and where the token ceiling actually sits.
Fix 2: Use negative constraints instead of positive aspirations. "Never exceed 3 sentences" survives drift noticeably better than "keep responses brief." Negative rules, the "never," "do not," "under no circumstances" kind, create hard boundaries the model can check itself against. Soft guidance like "try to" or "aim for" gives the model permission to interpret, and interpretation is exactly where drift creeps in.
Fix 3: Use /new to clear the conversation buffer, but only after saving what matters. In OpenClaw and Hermes, /new clears the active conversation history, and your workspace memory files stay on disk. That part is genuinely useful. Here's the catch most guides skip: manual resets don't automatically flush unsaved context to a memory file first. Anything discussed in chat but never written down disappears the moment you reset, same as it would in a compaction event. The safe pattern is to have the agent write a quick session note to memory before you run /new, not to assume the reset preserves everything. Do that, and resetting every 15 to 20 messages genuinely does return your instructions to a large percentage of the context, which resets drift along with it.
Fix 4: Repeat critical rules in AGENTS.md procedures. If SOUL.md says never send emails without approval, restate it inside the relevant workflow step too: "Step 5: Generate draft reply. DO NOT SEND. Wait for user approval." Redundancy across both files gives the rule two separate footholds instead of one, and a rule with two footholds is harder for drift to erode.
Fix 5: Use system-level instruction reinforcement where the platform supports it. Some setups support pinned instructions that get re-injected into context at intervals instead of sitting only at the start. On raw OpenClaw, this usually means manually re-injecting SOUL.md content every N messages through a skill or hook. On BetterClaw, this is handled by smart context management, so critical rules don't rely on a human remembering to re-inject them.
Fix 6: Break long tasks into shorter sessions. One 50-message conversation drifts. Three sessions of roughly 15 messages each, each one starting fresh, gets full SOUL.md attention every time. Pass what matters between sessions using memory files, not by dragging the whole conversation history forward. This is the same principle as Fix 3, just applied proactively instead of as a mid-conversation rescue.
Fix 7: Test with adversarial prompts at message 25 and beyond. Past message 25, deliberately try to get your agent to break its own rules. Ask it to do the exact thing SOUL.md prohibits. If it complies, you've found drift before a real user did. Keep adjusting SOUL.md wording until the rule holds at message 30 and beyond. The rules that survive adversarial testing at message 30 are the only rules you should trust in production. Everything else is a suggestion wearing a rule's clothing.

Real Example: SOUL.md That Drifts vs SOUL.md That Holds
Here are two versions of the same email triage agent's SOUL.md. Same intent. Wildly different survival rate.
Version that drifts:
You are a helpful and knowledgeable email assistant. Your goal is to help
the user manage their inbox efficiently. Try to keep your responses concise
and focused. When classifying emails, consider the sender's importance,
the subject line content, and any time-sensitive language. Aim for accuracy
in your classifications and provide brief summaries when helpful.
Version that holds:
Email triage agent.
RULES:
- Max 2 sentences per response.
- NEVER classify unknown senders as "safe."
- NEVER send, reply, or delete. Read-only.
- If unsure, mark "needs review." Never guess.
The first version is 80 words of suggestions. The second is 35 words of laws. Agents follow laws. They forget suggestions.
Look at the specific language. "Try to keep responses concise" versus "max 2 sentences." "Aim for accuracy" versus "if unsure, mark needs review, never guess." One gives the model room to drift. The other gives it nothing to negotiate with.
We rewrote a client's production SOUL.md using exactly this pattern and watched the same known-constraint test that failed at message 22 hold clean past message 40. Nothing else about the setup changed. Just the wording.
Platform notes on where drift shows up
OpenClaw and Hermes: use /new to reset context, and remember that memory files persist across the reset while unsaved chat context does not. Get in the habit of asking the agent to jot a quick note before you clear the buffer.
Claude Code: context management is handled by the runtime, but drift still shows up in long sessions the same way it does anywhere else. The practical fix here is procedural: break work into smaller commits and smaller sessions rather than one marathon conversation, so instructions never have to survive fifty turns unassisted.
BetterClaw: smart context management handles instruction reinforcement automatically, so rules drift is meaningfully reduced compared to a raw OpenClaw setup where you're manually re-injecting SOUL.md content yourself. That's just how the platform is built, not a sales pitch, it's the same underlying context math, just with the reinforcement handled for you instead of left as a DIY project.
If manually babysitting a context window and re-injecting your own instructions sounds like the wrong use of a Tuesday afternoon, that's a big part of why we built BetterClaw the way we did. The free plan includes every feature, one agent, no credit card, and the same smart context management that's reducing drift on every other agent running on the platform.

Drift isn't unique to email agents either. Anywhere an agent runs long, unattended, or across many turns, the same math applies, and shorter, tighter instruction files paired with fewer redundant tokens in your skills stack both help. If you're curious how much of your token budget your integrations are actually consuming before instructions even enter the picture, our breakdown on reducing token usage from skills is worth a read. And if you're seeing responses cut off entirely rather than just drifting in tone, that's usually a related but distinct problem, covered in our guide to fixing truncated Hermes responses.
The honest takeaway
Rules drift isn't a sign you configured something wrong. It's a sign your agent has been running long enough to matter, which is honestly a good problem to have.
The fix was never about writing a longer, more thorough SOUL.md. It was about writing a shorter one, with harder edges, and building in a reset habit before the context window quietly decides which of your rules it can afford to forget.
If you'd rather have that reinforcement handled automatically instead of manually testing your own agent at message 30 every week, give BetterClaw a try. Free plan with one agent and every feature, no credit card. $19 a month per agent for Pro when you're ready to run more than one. Your first deploy takes about 60 seconds. We handle keeping your rules in view. You handle deciding what they say.
Frequently Asked Questions
Why does my AI agent forget its instructions?
Your agent's instructions sit at the start of the context window and stay a fixed size, while the conversation around them keeps growing. As the conversation gets longer, those instructions become a smaller share of the total context, and the model starts weighing recent messages more heavily. The instructions aren't deleted, they're just outweighed.
How many messages before an AI agent starts drifting?
Most agents start showing measurable drift somewhere between message 20 and 30, though the exact point depends on how long your SOUL.md is and how strict your model's context handling is. Shorter instruction files with hard negative constraints tend to hold noticeably longer than long, soft, aspirational ones.
How to fix agent rules drift?
Keep SOUL.md under 500 tokens, use negative constraints instead of soft suggestions, repeat critical rules in AGENTS.md as well, and reset the conversation periodically with something like OpenClaw's /new command after saving any context worth keeping. Testing your agent with adversarial prompts past message 25 is the most reliable way to confirm a fix actually worked.
What is the best length for SOUL.md?
Keep SOUL.md under 400 to 500 tokens, which is roughly 300 to 400 words. Beyond that ceiling, instructions start losing the model's attention faster as the conversation grows, so shorter files with harder rules consistently outperform longer files full of soft guidance.
Does /new reset agent memory in OpenClaw?
/new clears the active conversation history but leaves your workspace memory files, like MEMORY.md and daily notes, intact on disk. What it doesn't do is automatically save unsaved context from the chat before wiping it, so anything important that was only discussed in conversation and never written to a file will be lost on reset.
How to make AI agent follow instructions longer?
Write instructions as hard negative constraints rather than soft goals, keep the file short enough that it doesn't get diluted by conversation growth, and reinforce critical rules in more than one place, such as both SOUL.md and AGENTS.md. Periodically resetting the session, or using a platform with automatic context reinforcement, addresses the problem at its root instead of just delaying it.




