Skip to main content

Module history_trim

Module history_trim 

Expand description

Whole-turn history trimming. One rule: keep the most recent whole turns that fit the token budget, drop the rest, never cut a turn in half.

Structs§

TrimResult
Outcome of a trim pass. trimmed is true only when at least one whole turn was dropped, in which case the caller emits a user-visible event and injects a breadcrumb so the loss is never silent.

Functions§

breadcrumb
Front breadcrumb injected after the system messages so the model SEES that earlier turns were cut and cannot confabulate dropped work as present.
insert_breadcrumb_deduped
Insert the trim breadcrumb after the leading system messages, unless one is already sitting there.
trim_to_recent_turns
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.
trim_to_reported_budget