Skip to main content

target_savings_chars

Function target_savings_chars 

Source
const fn target_savings_chars(payload_chars: usize, limit_chars: usize) -> usize
Expand description

The number of estimated characters truncation must reclaim from a payload of payload_chars under a budget of limit_chars.

The naive answer — payload_chars - limit_chars, just enough to fit — re-elides one more message on almost every turn of a growing conversation, because this stage is stateless and the client resends the full raw history each time. The target is therefore anchored at the LOW_WATERMARK_PCT watermark and rounded up to a whole multiple of the margin between watermark and budget: the result depends on the payload size only through that coarse bracket, so the elision set it induces stays identical across every turn within one margin (~25% of budget) of payload growth. See the module docs for the full KV-cache rationale.

Returns 0 when the payload is already at or below the watermark. The margin is clamped to at least one character so a degenerate limit_chars of 0 still yields a finite target (the whole payload).