Part 1 of 6 · 1 min read
Overview
Every step of an agent re-sends its whole prompt: the rules, the tool definitions, and the history so far. Providers can cache the start of a prompt that repeats exactly, and charge much less to read it again than to process it the first time. That makes the order and stability of the prompt a cost decision: a prompt that changes near the top gets no benefit, and one that only grows at the end gets a lot. This module puts numbers on that, and shows how the compaction of module 3 can undo the saving.
About the example, and what is real
Everything runs offline in code/mini-cache. Real: the prefix-matching cache (segment-by-segment identity, expiry by idle time, refresh on use, a minimum cacheable size), the cost arithmetic, the 40-step agent run and the 31 tests. Imitated: the prices and the time-to-live are parameters I chose (read 0.1, write 1.25, 5 steps) and the sweeps vary them; they are not any provider's terms, and providers differ in minimum size, breakpoints, expiry and billing. Request contents are abstract segments with token counts, not text. No provider is called. Only cost is measured; what compaction does to accuracy is module 3's result.