Skip to main content

memory_first_keep_tail

Function memory_first_keep_tail 

Source
pub fn memory_first_keep_tail(
    messages: &[Message],
    history_start: usize,
) -> usize
Expand description

Compute how many tail messages to keep when the MemoryFirst strategy is active.

Always keeps at least 2 messages. Extends the tail as long as the boundary message is a ToolResult (user message with a ToolResult part) to avoid splitting a tool-call round-trip. Capped at MAX_KEEP_TAIL_SCAN to prevent O(N) scans on long sessions.

history_start is the index of the first non-system message (typically 1).