# When an AI Agent Context Reaches 261k Tokens

> Source: <https://dev.to/interro-ai/how-to-stop-an-ai-agent-infinite-loop-3i03>
> Published: 2026-09-26 17:04:45+00:00

One research request grew to 261,834 tokens and failed against a 128,000-token model limit. The context did not become large in one prompt. Replayed tool results accumulated across checkpoints.

INC-002 exposed three missing controls: no hard token budget, no message cap, and no pruning policy for old tool observations. Large search and file results were also inserted without compression.

The important metric is context size at each boundary. A final failure log is too late to explain where growth started.

Run a heuristic review with:

```
prevention-scanner scan . --format json
```

Then confirm the result with a test that simulates 50 or more tool calls and asserts the context remains bounded.

Read the [full INC-002 incident](https://github.com/InterroAI/interro-awesome-agent-incidents/blob/main/INC-002-context-explosion.md).
