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 the owner’s crumb_present record 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. When budget_tokens is zero the history is returned untouched.
trim_to_recent_turns_with_crumb
Crumb-aware variant of trim_to_recent_turns: when crumb_present is 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 in dropped_messages. The owner flag decides, not message text.
trim_to_reported_budget
trim_to_reported_budget_with_crumb
Crumb-aware variant: when crumb_present is true the population carries the synthetic breadcrumb immediately after leading system messages. The breadcrumb is never counted as a turn and never dropped.