Skip to content

pickCut

function pickCut(messages, budget): number;

Defined in: core/src/context.ts:108

Where to cut so the messages AFTER the cut fit budget, walking backwards from the newest.

Two invariants the cut must respect, and both are correctness rather than taste:

  1. Never split a tool call from its result. Every provider rejects a tool result whose call is missing, so a cut landing between them produces a 400 on the very next turn, the failure compaction was called to avoid.
  2. Never cut into the system prompt. It is not history.

Returns the index the kept tail starts at, or 0 when everything already fits.

Parameter Type
messages readonly ChatMessage[]
budget number

number