Context Window Pollution: The Silent Agent Degradation Problem
Source: Dev.to
Introduction
Your AI agent starts sharp. Give it a task, it executes cleanly.
Give it the same task two hours later, after running continuously? It might fumble.
The Problem: Context Window Pollution
- Every tool call leaves residue in the context: partial API responses, dead‑end reasoning steps, error messages from retries, stale task context.
- The model does not cleanly distinguish “fresh instructions” from “junk from 47 steps ago.”
- Result: degraded decisions. The right answer is buried under noise.
Symptoms include:
- Agent quality degrades mid‑task (early decisions are good; later ones are sloppy).
- Unnecessary retries and re‑doing work that was already completed.
- Token usage per step grows linearly instead of staying flat.
Solution: Context Hygiene
Add this to your SOUL.md:
Every 20 steps, summarize completed work to
memory/progress.md, clear intermediate reasoning, and reload only the current task context.
Benefits
- Fresh context → sharper decisions, less noise, more signal.
- Progress is preserved via the summary file—nothing important is lost, just restructured.
Recommended Context Architecture
-
Core context (always loaded)
- Identity, rules, current task.
-
Working context (loaded per step)
- Recent tool results, current state.
-
Archive context (on‑demand only)
- Historical results, previous decisions.
- Only pull archive context when explicitly needed.
- Core reasoning stays clean.
Design Guidance
- Agent reliability is not just about the initial prompt; it depends on what the context looks like after many steps.
- Design for context hygiene from the beginning.
Further Resources
The Ask Patrick Library includes agent configurations with context‑flush rules built in: