Skip to content

Commit 9311712

Browse files
committed
fix: make renewal feature opt-in (max_generations defaults to None)
Change max_generations from int=999 to int|None=None so the renewal feature is fully disabled by default rather than hidden behind an arbitrary high number.
1 parent 7cda9c7 commit 9311712

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

python/semantic_kernel/contents/history_reducer/chat_history_double_buffer_reducer.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class ChatHistoryDoubleBufferReducer(ChatHistoryReducer):
9898
swap_threshold: Fraction of target_count at which to swap buffers
9999
(0.0-1.0). Default 0.95. Must be greater than checkpoint_threshold.
100100
max_generations: Maximum number of summary-on-summary layers before
101-
triggering renewal. Default 5.
101+
triggering renewal. None means no limit (renewal disabled).
102102
renewal_policy: How to handle accumulated compression debt when
103103
max_generations is reached. Default RECURSE.
104104
summarization_instructions: The summarization prompt template.
@@ -121,11 +121,10 @@ class ChatHistoryDoubleBufferReducer(ChatHistoryReducer):
121121
le=1.0,
122122
description="Fraction of target_count at which to swap to the back buffer.",
123123
)
124-
max_generations: int = Field(
125-
default=999,
126-
gt=0,
124+
max_generations: int | None = Field(
125+
default=None,
127126
description="Maximum summary-on-summary layers before renewal. "
128-
"Set to a lower value to enable incremental summary accumulation.",
127+
"None means no limit (renewal disabled).",
129128
)
130129
renewal_policy: RenewalPolicy = Field(
131130
default=RenewalPolicy.RECURSE,
@@ -263,7 +262,7 @@ async def _create_checkpoint(self) -> Self | None:
263262

264263
try:
265264
# Check if we need renewal first
266-
if self._current_generation >= self.max_generations:
265+
if self.max_generations is not None and self._current_generation >= self.max_generations:
267266
await self._perform_renewal()
268267
# Re-capture — renewal may have reassigned self.messages
269268
history = self.messages

python/tests/unit/contents/test_chat_history_double_buffer_reducer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_double_buffer_reducer_defaults(mock_service):
7777
reducer = ChatHistoryDoubleBufferReducer(service=mock_service, target_count=10)
7878
assert reducer.checkpoint_threshold == 0.7
7979
assert reducer.swap_threshold == 0.95
80-
assert reducer.max_generations == 999
80+
assert reducer.max_generations is None
8181
assert reducer.renewal_policy == RenewalPolicy.RECURSE
8282
assert reducer.fail_on_error is True
8383
assert reducer.generation == 0

0 commit comments

Comments
 (0)