CHAPTER 05 · Prompt Caching and Context Management · 5 / 8
How it works: ordering and compacting
Two small mechanisms. First, a builder that guarantees the stable prefix never changes so the cache keeps hitting. Second, a compactor that summarizes old turns when the history gets too big, while always preserving the original request and the most recent exchanges.