Skip to main content

Module condense

Module condense 

Source
Expand description

Last-resort context condensing: drop the middle of a conversation that will not fit anywhere.

§Why this is narrow on purpose

Condensing routinely — trimming every long conversation to save tokens — would mean the gate verifies an answer produced from a prompt the client never sent. The receipt would attest to a decision about a different question than the one asked, which is the one thing this product cannot afford to get wrong.

So it fires in exactly one situation: the prompt has already overflowed the context window of every rung on the ladder, and the alternative is not a cheaper answer, it is no answer. At that point the trade is no longer “faithful vs. degraded” but “degraded vs. failed”, and a degraded answer the receipt openly labels is the better of the two.

§What it keeps

The head and the tail. The opening turns usually carry the task definition and the tail carries the live thread; the middle is where a long agent conversation accumulates tool output nobody refers to again. A marker turn is inserted where the elision happened, so the model is told the history is incomplete rather than being left to infer it from a discontinuity.

Structs§

Condensed
Outcome of a condensing attempt.

Functions§

condense
Drop the middle of req’s conversation, keeping keep_head opening turns and keep_tail closing ones.