Agent context window full and dropping information? Fixing context overflow
Early in a run the agent is sharp. Twenty steps later it starts forgetting instructions, hallucinating fields, or calling a tool with the wrong arguments — not because the model got worse, but because the context window filled and quietly pushed the things it needed out of scope. Context overflow is a slow degrade, not a crash, which is what makes it sneaky.
What gets lost
Context is finite, and a long run keeps adding to it — every tool result, every reasoning step. When it fills, the oldest content falls out of scope first, and that's often the content the agent most needs:
- Tool definitions get pushed out — so the model calls a tool from memory of its shape, and hallucinates the arguments.
- The original goal drifts out — so the agent optimises for the last thing it read, not the task.
- Earlier results vanish — so it re-fetches what it already had, or contradicts a fact it established ten steps ago.
The tell is that quality falls off as the run gets longer. If your agent is great for the first N steps and unreliable after, suspect context overflow before you suspect the model.
Catch it before it overflows
The fix is to watch context usage mid-run and act before the limit, not after. budget_guard includes a context check and warns as you approach the ceiling — free, no LLM:
budget_guard({ context_pct: 0.88, tokens_used: 88000, token_budget: 100000 })
// → { warnings: [{type:"context_limit", severity:"warning",
// suggestions:["summarise old turns", "pin tool defs + goal", ...] }] }The fix
- Summarise or prune old turns when context approaches the limit — keep the gist, drop the raw transcript.
- Pin what matters. Keep tool definitions and the original goal in context at decision points so they never fall out of scope.
- Store large outputs by reference. A big tool result shouldn't be inlined into context — keep a pointer and fetch on demand.
- Watch it every step.
budget_guardis cheap enough to call continuously, so you act on a warning instead of discovering the overflow in a degraded output.
Diagnose a degraded run
If a run went sideways and you suspect context, send the trace — Snapback returns failure_class: "context_overflow" with the root cause, so you can confirm it before restructuring your context strategy.
Machine-readable guide: https://snapback.sh/llms.txt · Tool discovery: https://snapback.sh/.well-known/mcp.json · MCP endpoint: https://api.snapback.sh/mcp. Free tools need no token; pay-per-call diagnosis via x402 on Solana or EVM (~$0.0032 USDC).