Skip to main content

Module context_collapse

Module context_collapse 

Source
Expand description

Context collapse (snip compaction).

An alternative to full LLM-based compaction that works by selectively snipping (removing) older message groups to stay within the context window. The full conversation history is preserved for UI scrollback, but only a subset is sent to the API.

Snipping preserves:

  • The system prompt (always)
  • Any compact boundary / summary messages
  • The most recent N messages (configurable)

Snipped messages are replaced with a “[messages snipped]” marker in the API-facing view, while the UI retains the full history.

Structs§

CollapseResult
Result of a context collapse operation.

Functions§

collapse_to_budget
Collapse the message history to fit within a token budget.
recover_from_overflow
Recover from a prompt-too-long error by collapsing more aggressively.