1. Start with raw messages
A continuous stretch of context can be written as m1 through m10. These are simply the original messages, in order.
| Message | Example content |
|---|---|
m1 | user request |
m2 | assistant reasoning |
m3 | tool call |
m4 | tool result |
m5 | follow-up |
m6 | code output |
m7 | another tool result |
m8 | intermediate conclusion |
m9 | recent work |
m10 | current work |
As the task continues, raw messages keep accumulating: m1, m2, m3 … m100 … m1000. The model does not need every historical detail to stay in its current context.
2. Digest
Suppose m1–m4 describe one completed stretch of work. We can compress the important information into a shorter account. This compressed content is called a digest.
Fixed the routing bug. Literal routes now run before dynamic routes. Tests passed.
A digest keeps the main information needed to continue working, while leaving out details that no longer need to stay in context.
3. Chunked compression
We do not compress all of m1–m10 into one digest. Instead, divide the history into local stretches and compress each completed stretch separately.
Fixed the routing bug. Literal routes now run before dynamic routes. Tests passed.
d1 = digest of m1–m4
Added regression tests and verified the routing behavior.
d2 = digest of m5–m8
Still active. Keep these messages raw.
This keeps the work from different stages independent. The two completed stretches are not merged into one global digest.
4. Source Reference
A digest alone is not enough. Suppose d1 says “Fixed the routing bug. Tests passed.” Later, the model asks: “What exact timeout value was used?” That detail may be missing from the digest.
Each compressed block therefore also records which original messages it came from. This record is its source reference.
Fixed the routing bug. Literal routes now run before dynamic routes. Tests passed.
Added regression tests and verified the routing behavior.
When an exact detail is needed, follow the reference to read the original content. The original messages remain available; the digest does not have to contain every detail.
Fold
Now we can define the complete result. A folded block contains both the compressed content and a reference to its source.
Before
After
Fixed the routing bug. Literal routes now run before dynamic routes. Tests passed.
Added regression tests and verified the routing behavior.
Fold reduces active context and keeps a path back to the original context.
message → digest → chunked compression → source reference → Fold block