Skip to main content

compact_messages

Function compact_messages 

Source
pub fn compact_messages(
    messages: Vec<AgentMessage>,
    config: &ContextConfig,
) -> Vec<AgentMessage>
Expand description

Compact messages to fit within the token budget using tiered strategy.

  • Level 1: Truncate tool outputs (keep head + tail)
  • Level 2: Summarize old turns (replace details with one-liner)
  • Level 3: Drop old messages (keep first + recent only)

Each level is tried in order. Returns as soon as messages fit.