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§
- Trim
Result - Outcome of a trim pass.
trimmedis 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. Whenbudget_tokensis zero the history is returned untouched. - trim_
to_ reported_ budget