Skip to content
1 min read · 255 words

Function: stripPriorTurnThoughts()

ts
function stripPriorTurnThoughts(
  ws: Pick<WorkingSet, "thoughts">,
  options: EstimatorOptions,
  keepIds?: ReadonlySet<string>,
): {
  dropped: number;
  tokens: number;
};

Defined in: src/batteries/context/thrift/subtractive_pass.ts:371

Gemma model card §3 — "No Thinking Content in History": thoughts from previous model turns MUST NOT be re-added before the next user turn. Enforced here as a standalone, callable step (not a silent battery-wide flag), because it is also pure thrift: prior-turn reasoning is the highest-volume, lowest-reuse content a working set carries.

Parameters

ParameterTypeDescription
wsPick<WorkingSet, "thoughts">A working set exposing (at least) a mutable thoughts array; mutated in place.
optionsEstimatorOptionsThe estimator used to measure the tokens reclaimed by dropped thoughts.
keepIds?ReadonlySet<string>Thought ids to preserve.

Returns

ts
{
  dropped: number;
  tokens: number;
}

How many thoughts were dropped, and how many tokens that reclaimed.

NameTypeDefined in
droppednumbersrc/batteries/context/thrift/subtractive_pass.ts:375
tokensnumbersrc/batteries/context/thrift/subtractive_pass.ts:375

Remarks

keepIds is an allow-list of thought ids to PRESERVE — used for e.g. a planner's synthetic THIS-TURN plan thought, which is fresh guidance generated for the current request (NOT prior-turn chain-of-thought, and NOT subject to the §3 policy): it must survive into the next dispatch's prompt so the model follows the plan. Everything else is dropped.

subtractToFit calls this internally as step 1 (gated by its stripPriorTurnThoughts option, default true); it is also exported standalone for a caller who wants the strip without running the rest of the pass.