Auto-compaction

Coming soon

Long conversations outgrow the model's context window. The agent handles this itself: when the live context passes auto_compact_threshold tokens, the loop summarizes older turns and the conversation carries on. There is no hook and no capability to add.

agent = agents.Agent(
    model="mistral-medium-3-5",
    instructions="Be concise.",
    auto_compact_threshold=4_000,   # cap live context; older turns are summarized
)

It is off by default (0). Set a positive token budget to enable it.

Knowing it happened

Knowing it happened

The conversation does not announce a compaction, it just keeps going. What it leaves behind is a history entry: a CheckpointHistoryEntry whose checkpoint_kind is "compaction".

from mistralai.vibe.harness.app_server.session import CheckpointHistoryEntry

compactions = [
    entry
    for entry in session.state.history.items
    if isinstance(entry, CheckpointHistoryEntry) and entry.checkpoint_kind == "compaction"
]
Picking a threshold

Picking a threshold

Summarized turns lose their exact wording but keep the gist, so raise the budget if precise recall matters and lower it if you care more about cost.

The budget has a floor. The system prompt, the tool catalog and the compaction prompt all have to fit inside it, so too small a value is rejected when the session opens rather than at the moment it would have compacted:

ValueError: token threshold cannot fit the generated system prompt, tool catalog, and compaction prompt

How low is too low depends on how much your agent carries, since the tool catalog counts. An agent with no tools is fine at 4_000 and fails at 2_000; one with a large tool surface needs more.

See also

See also

  • The Agent - where auto_compact_threshold is set.
  • Sessions - reading the history a compaction writes into.