Skip to content

Commit ab196df

Browse files
abrookinsclaude
andcommitted
Make summarization threshold configurable
Address review comments by making the 0.7 threshold configurable instead of hardcoded. Added summarization_threshold setting that can be configured via environment variable or config file. - Added summarization_threshold to Settings (default: 0.7) - Updated both _calculate_context_usage_percentage and _summarize_working_memory to use settings.summarization_threshold - Improved maintainability and consistency between functions - Allows users to customize when summarization is triggered 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 8043c18 commit ab196df

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

agent_memory_server/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def _calculate_context_usage_percentage(
8888
# Get effective token limit for the client's model
8989
max_tokens = _get_effective_token_limit(model_name, context_window_max)
9090

91-
# Use the same threshold as _summarize_working_memory (70% of context window)
92-
token_threshold = int(max_tokens * 0.7)
91+
# Use the same threshold as _summarize_working_memory (reserves space for new content)
92+
token_threshold = int(max_tokens * settings.summarization_threshold)
9393

9494
# Calculate percentage of threshold used
9595
percentage = (current_tokens / token_threshold) * 100.0
@@ -123,8 +123,8 @@ async def _summarize_working_memory(
123123
max_tokens = _get_effective_token_limit(model_name, context_window_max)
124124

125125
# Reserve space for new messages, function calls, and response generation
126-
# Use 70% of context window to leave room for new content
127-
token_threshold = int(max_tokens * 0.7)
126+
# Use configurable threshold to leave room for new content
127+
token_threshold = int(max_tokens * settings.summarization_threshold)
128128

129129
if current_tokens <= token_threshold:
130130
return memory

agent_memory_server/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ class Settings(BaseSettings):
119119

120120
# Working memory settings
121121
window_size: int = 20 # Default number of recent messages to return
122+
summarization_threshold: float = (
123+
0.7 # Fraction of context window that triggers summarization
124+
)
122125

123126
# Other Application settings
124127
log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO"

0 commit comments

Comments
 (0)