Skip to main content

trim_to_recent_turns

Function trim_to_recent_turns 

pub fn trim_to_recent_turns(
    history: Vec<ChatMessage>,
    budget_tokens: usize,
) -> TrimResult
Expand description

Drop oldest whole turns until the history fits budget_tokens, always keeping leading system messages and at least the most recent whole turn. When budget_tokens is zero the history is returned untouched.