Commit 3bc4448
committed
feat: add double-buffer context window reducer for chat history
Implements proactive context compaction using double buffering for the
ChatHistoryReducer system. Instead of stop-the-world summarization when
the context fills, this reducer begins checkpoint summarization at a
configurable threshold while the agent continues working, then swaps to
the pre-built back buffer seamlessly.
Three-phase algorithm:
1. Checkpoint: background summarization (asyncio.create_task) seeds back buffer
2. Concurrent: new messages go to both active and back buffers
3. Swap: back buffer becomes active context at swap threshold
Key features:
- Configurable checkpoint/swap thresholds (fraction of target_count)
- Non-blocking async checkpoint with timeout (default 120s)
- Stop-the-world fallback if no back buffer ready at swap time
- Incremental summary accumulation across generations
- Renewal policies: RECURSE (meta-summarize) or DUMP (clean restart)
- Graceful degradation on checkpoint failure
Reference: https://marklubin.me/posts/hopping-context-windows/1 parent c086d09 commit 3bc4448
File tree
3 files changed
+912
-0
lines changed- python
- semantic_kernel/contents
- history_reducer
- tests/unit/contents
3 files changed
+912
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
0 commit comments