Skip to content

Context and Output Compaction

Long conversations and large tool outputs both eat context. Wayland Core handles each with a separate mechanism: automatic context compaction keeps the conversation under the model’s window, and output compaction trims what tool results cost before they enter the context.

Context compaction runs on its own in three tiers. You do not call it directly.

TierTriggerMethodLLM call
MicrocompactToo many old tool results, or a long gapClears old Read/Bash/Grep/Glob/Write/Edit results, keeping the most recentNo
AutocompactInput tokens approach the windowThe model summarizes the conversation, history is replaced with a boundary markerYes
EmergencyInput tokens near the absolute limitBlocks further calls and asks you to start freshNo

Defaults live in [compact]. Microcompact keeps the 5 most recent tool results; autocompact triggers around context_window - output_reserve - autocompact_buffer. A circuit breaker stops retrying autocompact after a set number of failures.

[compact]
enabled = true
context_window = 200000
output_reserve = 20000
autocompact_buffer = 13000
emergency_buffer = 3000
micro_keep_recent = 5

Output compaction post-processes tool output to cut tokens. Three levels run from lightest to heaviest:

  • off: no change.
  • safe (default): strip ANSI codes, merge blank lines, collapse carriage-return progress bars.
  • full: everything in safe, plus folding repeated lines and compacting JSON indentation.

Set it per run:

Terminal window
wayland-core --compaction full "Run the test suite and report failures"

With full compaction you can turn on TOON, which encodes uniform JSON arrays as compact tables. It is a session-level choice and cannot change mid-conversation:

Terminal window
wayland-core --compaction full --toon "List the users table as JSON"
[compact]
compaction = "safe"
toon = false

In --json-stream mode a host can change the level at runtime with a set_config command carrying a new compaction value.