Skip to content

Commit 3bc4448

Browse files
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

3 files changed

+912
-0
lines changed

python/semantic_kernel/contents/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from semantic_kernel.contents.file_reference_content import FileReferenceContent
88
from semantic_kernel.contents.function_call_content import FunctionCallContent
99
from semantic_kernel.contents.function_result_content import FunctionResultContent
10+
from semantic_kernel.contents.history_reducer.chat_history_double_buffer_reducer import ChatHistoryDoubleBufferReducer
1011
from semantic_kernel.contents.history_reducer.chat_history_reducer import ChatHistoryReducer
1112
from semantic_kernel.contents.history_reducer.chat_history_summarization_reducer import ChatHistorySummarizationReducer
1213
from semantic_kernel.contents.history_reducer.chat_history_truncation_reducer import ChatHistoryTruncationReducer
@@ -35,6 +36,7 @@
3536
"AudioContent",
3637
"AuthorRole",
3738
"ChatHistory",
39+
"ChatHistoryDoubleBufferReducer",
3840
"ChatHistoryReducer",
3941
"ChatHistorySummarizationReducer",
4042
"ChatHistoryTruncationReducer",

0 commit comments

Comments
 (0)