# `Wardrik.Compaction`

Middleware that summarises an agent's older history when a turn starts.

It runs once the history passes `:at` of the model's context window. The most recent `:keep`
of the window stays word for word.

## Options

  * `:at` - the share of the window that triggers compaction. `0.6` unless set.
  * `:keep` - the share of the window kept word for word. `0.25` unless set.
  * `:window` - the window in tokens, if the model catalog has none. `128_000` unless set.

## Behaviour

  * The agent's own model writes the summary, in a `compaction` step. Policy and budgets apply
    as for any model call.
  * History is only cut where a person's message starts.
  * Resumed turns aren't compacted.
  * The summary keeps the labels of what it replaces, such as `"outside"`.
  * If summarising fails, the history is left as it is and the turn runs anyway.
  * Each compaction emits `[:wardrik, :conversation, :compacted]` with message and token counts
    before and after.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
