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 the
owner’s
crumb_presentrecord says one is already sitting there. Returns whether a breadcrumb is present after the call, so the caller can store it as the population’s authoritative provenance instead of re-inferring it from text later. - 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_ recent_ turns_ with_ crumb - Crumb-aware variant of
trim_to_recent_turns: whencrumb_presentis true the population is assumed to carry the synthetic breadcrumb immediately after the leading system messages. That breadcrumb is never counted as a turn boundary, never dropped, and never double-counted indropped_messages. The owner flag decides, not message text. - trim_
to_ reported_ budget - trim_
to_ reported_ budget_ with_ crumb - Crumb-aware variant: when
crumb_presentis true the population carries the synthetic breadcrumb immediately after leading system messages. The breadcrumb is never counted as a turn and never dropped.