Why does our agent forget its instructions halfway through a long task?
As the conversation grows, a naive truncation strategy drops the oldest messages to stay under the context window. The oldest messages usually hold the system prompt and the original task state. The agent keeps running with no memory of what it was supposed to do.
Also known as truncation drops system prompt, long-run instruction drift
What does this look like in production?
- An agent behaves correctly for the first several steps of a long session, then starts ignoring constraints stated at the very start
- The transcript, inspected at step 20, no longer contains the original system prompt or task specification
- Behavior at step 1 and behavior at step 20 diverge on rules that were never explicitly rescinded mid-session
- Runs crossing a certain length or turn count show a step change in error rate rather than a gradual decline
Why does it happen?
A context windowThe context window is the maximum text, measured in tokens, a model can consider at once. has a hard token ceiling, and once a long-running agent or conversation approaches it, something has to give. The simplest and most common strategy is to drop the oldest messages first. This is exactly the strategy that discards the system prompt and the initial task framing before it discards anything else, since those were written first. The agent does not forget in any dramatic sense. The instruction is simply no longer in its input. It continues from the remaining context, which looks more and more like an ordinary continuation task. The constrained job it started as is gone.
This is worse for agents than for simple chat. An agent often keeps its task state in the same truncatable transcript. That state covers what it already tried, what the goal is, which constraints apply. Losing the early context doesn't just lose politeness instructions; it can lose the actual definition of the task.
How do you confirm it's this?
- Log token count and specifically which messages get dropped at every truncation event, per run
- Replay a long session and diff the agent's behavior at step 1 against step 20 on a rule stated only once, at the start
- Check whether your system prompt and task state are stored in a truncatable position in the message array or pinned separately
- Alert when any run's token usage crosses a defined share (e.g. 80%) of the context window, before truncation has to kick in
How do you fix it?
- Pin the system prompt and task state outside the truncatable window
Store critical instructions and task state in a position that truncation never touches. Re-inject them on every call. Do not leave them once in a message history that can age out.
- Summarize and compact instead of truncating
When the window fills, compress older turns into a summary that preserves the decisions and state that matter, rather than deleting them outright.
- Persist task state in a store the agent re-reads
Keep the goal, constraints, and progress in an external structure, separate from conversation history. Re-read it on every step. It then survives whatever happens to the transcript.
- Alert when a run crosses a set share of the context window
Treat the approaching window limit as an operational signal, the same way you watch memory usage. Do not discover it after truncation has silently dropped something.
What this doesn't cover
This explains instruction loss caused specifically by truncation. A long run can degrade for a different reason. Accumulated wrong context can reinforce itself, as in compounding agent-loop failures. The task can also be ambiguous. In those cases truncation may not be the cause even if the symptoms look similar.
Sources
- arXiv - Lost in the Middle: How Language Models Use Long Contexts
The paper measuring how a fact's position in a context window affects recall. Retrieved 2026-08-24.
- NIST - AI Risk Management Framework (AI RMF 1.0)
The risk-management functions our governance and adoption controls map onto. Retrieved 2026-08-24.
A Ship Audit runs this full checklist against your actual system and hands back a written, prioritized plan.