90 min · The hardest engineering problem in production harnesses
Module 0.3's anchor: tool outputs 67.6%, history 18%, and history is the only layer that grows unboundedly. By the end: why context rots, five strategies, the priority stack, and a compaction function you'll build.
The U-shape: strong attention at start (system prompt) and end (latest user message). The middle — where history piles up — is a desert.
Implication: where you place info matters as much as what it is.
Effective context < nominal context. The harness must keep effective context below the cliff — managing proactively, not just fitting within the nominal limit.
| Layer | Share | Grows? |
|---|---|---|
| Tool outputs | 67.6% | per-turn, compressible |
| History | ~18% | UNBOUNDED — the rot source |
| Tool defs | 10.7% | fixed |
| System prompt | 3.4% | fixed |
History is the only layer that grows every turn. Compaction targets it.
Keep the reasoning chain (Thought); hide old raw tool outputs (Observation).
Before: [Thought: read auth.ts] [Observation: 248 lines, full content, 1840 tokens]
After: [Thought: read auth.ts] [Observation: auth.ts, 248 lines, contains validateToken — 40 tokens]Model sees its decision history without the noise. Cost: raw data gone unless retained in a side store for JIT retrieval.
| Synchronous | Async | |
|---|---|---|
| When | in-loop, blocks next call | background, loop continues |
| Latency | adds on compaction turn | none |
| Complexity | simple | race conditions possible |
| Production default | yes — trigger at threshold | rare |
Most production harnesses: synchronous compaction at ~50% of context window. Tunable: too low wastes calls; too high lets rot set in.
| Tier | What | Loaded | Cost |
|---|---|---|---|
| T1 Index | ~150 char summaries | always | low |
| T2 Topic files | detailed content | on demand | medium |
| T3 Raw logs | full history | search only | high |
| Method | Best for | Cost |
|---|---|---|
| Keyword (ripgrep) | exact code: "find validateToken" | fast, deterministic |
| Vector (embeddings) | semantic: "auth approach discussions" | infra; can hallucinate relevance |
| File read | known path: "read decisions.md" | no search needed |
Provide all three; let the model choose. Tool surface (Module 2) determines retrieval capability.
System Message ← HIGHEST attention (first)
↓ Tool Definitions
↓ Memory (T1 index)
↓ History ← WEAK attention (middle) — compaction target
↓ User Message ← HIGH attention (last)The original task, placed in the system prompt, survives better than the same task in turn-1 history.
Thickness spectrum (Module 0.1) applies to prompt assembly. Question: how much behavior do you encode vs. delegate?
System prompt and tool defs are FIXED across turns → caching turns recurring cost into one-time. Reward stability; dynamic prompts invalidate the cache.
Next: Module 4 — Memory Architecture. Continuity across sessions.