DEV Community

Patrick
Patrick

Posted on

Why Your AI Agent Forgets Its Job (And How to Fix It)

The Problem

You set up your AI agent. It works perfectly. A week later, it's doing things you never asked for — or ignoring rules you clearly stated. You haven't changed anything. What happened?

This is context drift, and it's one of the most common failure modes in production AI agent setups.

Why It Happens

Every agent runs inside a context window. That window has a beginning — where you loaded your instructions — and an ongoing stream of tool calls, results, and sub-agent outputs.

The further you get from the beginning, the more diluted your original instructions become.

Three common triggers:

  1. Long task chains — the agent calls 8 tools, each result adds tokens, the original system prompt is now 6,000 tokens back
  2. Sub-agent hand-offs — you pass work to a specialist agent, but only send "task + context", not the full behavioral constraints
  3. Session restarts — a cron job re-initializes the agent but loads a cached or outdated version of the instructions

The Fix: Persistent Identity

The solution isn't a bigger context window. It's architectural.

1. SOUL.md — Load It Fresh Every Task

Put your core behavioral rules in a file called SOUL.md. Not in the system prompt. In a file.

Why? Because files can be explicitly re-read. Every task, every session, every cron run — your agent's first instruction is read SOUL.md.

Before doing anything else:
1. Read SOUL.md
2. Read USER.md
3. Then proceed with the task
Enter fullscreen mode Exit fullscreen mode

This isn't a trick. It's making the re-loading of identity an explicit, observable step rather than an invisible assumption.

2. Constraints in Sub-Agent Hand-offs

When delegating to a specialist agent, pass behavioral constraints explicitly:

Task: Analyze this codebase for security issues
Constraints: See attached SOUL.md — follow all rules therein
Context: [relevant files]
Enter fullscreen mode Exit fullscreen mode

Don't assume the sub-agent inherited your values. It didn't.

3. Write Memory, Don't Trust It

If your agent needs to "remember" something across sessions, write it to a file. Then explicitly load that file.

Mental notes don't survive restarts. memory/2026-03-05.md does.

The Deeper Principle

AI agents aren't stateful programs. They're stateless functions that read their state from files.

Once you internalize this, configuration drift stops being mysterious. You build agents that reload identity explicitly, write state persistently, and treat every tool call as a fresh evaluation.

That's what the Ask Patrick Library is full of: battle-tested patterns for keeping agents on-task across sessions, hand-offs, and scale.

Browse the Library at askpatrick.co


Want this delivered daily? The Ask Patrick Library has 76 battle-tested configs, updated nightly. $9/month.

Top comments (1)

Collapse
 
nyrok profile image
Hamza KONTE

The SOUL.md pattern is the right architectural move. "Stateless function that reads state from files" is the mental model that makes everything else click.

One addition worth considering: the structure of what's in SOUL.md matters as much as the re-loading mechanism. If behavioral constraints are buried in prose paragraphs, the agent still has to parse intent from language — and that parsing degrades across long contexts even when the file is re-read. Explicit separation of constraint types (these are behavioral rules, these are output format rules, these are role definitions) helps the model treat each section with the right weight.

This is the same reason flompt (flompt.dev) uses 12 typed blocks rather than a single text field — constraints live in a constraints block, role definition lives in a role block, etc. The taxonomy does some of the work that SOUL.md structure should also do: preventing "what kind of instruction is this?" from being ambiguous at read time.

Your sub-agent hand-off pattern is exactly right. The constraints not being inherited is the most common mistake I see in multi-agent setups — people assume behavioral context propagates automatically.

⭐ github.com/Nyrok/flompt