Why picking context upfront beats compacting it later for AI agents
There are two ways to handle an AI agent's filling up as it works. The reactive approach waits until the window is full, then compacts everything at once. The proactive approach is picky about what gets added on every turn, so noise never piles up in the first place. Most use the reactive approach, but one developer spent months building the proactive kind instead.
A core principle that held up: a decision an agent made on turn 3 is worth more than tool output from turn 15 that's already resolved — treating them the same causes context rot, where irrelevant information piles up and quality degrades. A system called PRAANA splits into three tiers — active, soft, and hard. It scores each piece of context by information density, then uses BM25 (a keyword-based search method) plus semantic similarity, running via s.js in-process, to decide what gets pulled back into the active window. One mistake stood out: an early hash-based embedder, thrown together as a , was quietly injecting noise into search rankings.
Memories came back in the wrong order, with irrelevant items floating above relevant ones. There were no errors — it just looked plausible while being wrong — so it took three weeks to even notice. Switching to the s.js-based embedder fixed it.
Key points
- splits into 'reactive' (compact when full) and 'proactive' (curate every turn) approaches
- Recent-turn decisions should be weighted higher than resolved tool output from earlier turns
- PRAANA's compiler splits context into active/soft/hard tiers, scored by information density
- It combines BM25 with semantic similarity (via s.js) to decide recall
- An early hash-based embedder silently broke search ranking for three weeks before detection