mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 03:03:44 +00:00
Add ASCII diagram to compaction docs
This commit is contained in:
parent
403faafdbe
commit
ea16af8b72
1 changed files with 25 additions and 4 deletions
|
|
@ -183,10 +183,31 @@ For `before_branch` and `branch` events, `event.targetTurnIndex` contains the en
|
||||||
The `before_compact` event lets you implement custom compaction strategies. Understanding the data model:
|
The `before_compact` event lets you implement custom compaction strategies. Understanding the data model:
|
||||||
|
|
||||||
**How default compaction works:**
|
**How default compaction works:**
|
||||||
1. When context exceeds the threshold, pi finds a "cut point" that keeps ~20k tokens of recent turns
|
|
||||||
2. Messages before the cut point are summarized and discarded
|
When context exceeds the threshold, pi finds a "cut point" that keeps ~20k tokens of recent turns:
|
||||||
3. Messages after the cut point are kept verbatim
|
|
||||||
4. The summary + kept messages become the new context
|
```
|
||||||
|
Session entries (before compaction):
|
||||||
|
┌─────────────────────────────────────────────────────────────────┐
|
||||||
|
│ [header] [prev compaction] [msg] [msg] [msg] [msg] [msg] [msg] │
|
||||||
|
│ ↑ └─────┬─────┘ └───────┬───────┘ │
|
||||||
|
│ previousSummary messagesToSummarize messagesToKeep│
|
||||||
|
│ (will be discarded) (kept as-is) │
|
||||||
|
│ ↑ │
|
||||||
|
│ cutPoint.firstKeptEntryIndex │
|
||||||
|
└─────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
After compaction:
|
||||||
|
┌─────────────────────────────────────────────────────────────────┐
|
||||||
|
│ [header] [prev compaction] [NEW compaction] [msg] [msg] [msg] │
|
||||||
|
│ └──────┬──────┘ └───────┬───────┘ │
|
||||||
|
│ summary of messagesToKeep │
|
||||||
|
│ messagesToSummarize (unchanged) │
|
||||||
|
│ + previousSummary │
|
||||||
|
└─────────────────────────────────────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
The new compaction entry's `firstKeptEntryIndex` tells the session loader where to start reading messages after the summary.
|
||||||
|
|
||||||
**Event fields:**
|
**Event fields:**
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue