Skip to main content

trim_history

Function trim_history 

Source
pub fn trim_history(history: &mut Vec<ChatMessage>, max_history: usize)
Expand description

Trim conversation history to prevent unbounded growth.

Preserves: the system prompt (if any), the first user message (the framing anchor — losing it is what caused the silent-amnesia bug where models said “the first message I have is ‘Continue’”), and the most recent max_history messages (minus one slot already taken by the anchor).

Drops from the middle. Emits a WARN with counts on every fire so silent amnesia is impossible to miss again.