Skip to main content

build_messages

Function build_messages 

Source
pub fn build_messages(
    conv: &Conversation,
    system_prompt: &str,
    token_budget: usize,
    turn_reminder: &str,
) -> (Vec<Message>, ContextStats)
Expand description

Context management with cold zone compression.

Structure: [System] [Cold Zone (max 3 summaries)] [Last 5 turns full]

The cold zone is populated by Conversation::apply_compression when total tokens exceed ~70% of budget. If still over 80% after cold zone injection, this function drops oldest turns inline.

turn_reminder — if non-empty, prepended to the last User message. Keeps the system prompt prefix stable across turns (好 cache), while still delivering per-turn dynamic context (git diff, current task, etc). Empty string = no injection.