Skip to main content

Module session_memory_compact

Module session_memory_compact 

Source
Expand description

Session memory compaction.

Uses pre-extracted session memory as the summary instead of making an API call. Keeps recent messages above minimum thresholds and preserves API invariants.

Structs§

SessionMemoryCompactConfig
Configuration for session memory compaction thresholds
SessionMemoryCompactResult
Result from session memory compaction

Functions§

adjust_index_to_preserve_api_invariants
Adjust the start index to ensure we don’t split tool_use/tool_result pairs or thinking blocks that share the same message.id with kept assistant messages.
calculate_messages_to_keep_index
Calculate the starting index for messages to keep after compaction.
get_session_memory_compact_config
Get the current session memory compact configuration
has_text_blocks
Check if a message contains text blocks
is_compact_boundary_message
Check if a message is a compact boundary message
should_use_session_memory_compaction
Check if session memory compaction should be used
try_session_memory_compaction
Try to use session memory for compaction instead of traditional compaction. Returns None if session memory compaction cannot be used.