Compaction

Warning

The compaction API is experimental and may change as the implementation matures.

Compaction utilities format blackboard event history for prompts and optionally summarize older events when the formatted history exceeds a token threshold.

terrarium.compaction.compactor.compact_events(events, llm_client=None, model_name=None, token_threshold=3000, keep_recent=3, mechanism='baseline', pin_context_events=False, cache=None, evict_kinds=None, extract_limit=5, compaction_logger=None, agent_name=None, blackboard_id=None, phase=None, iteration=None, params=None)[source]

Compact a blackboard’s event history into prompt text.

mechanism selects how the aged-out portion of history is compressed once the token budget is exceeded (see MECHANISMS). pin_context_events is an orthogonal modifier, not a mechanism of its own: it holds every kind == “context” event (channel-purpose / standing-rule messages posted once when a blackboard is created) out of whichever mechanism is active, so it can never be paraphrased or evicted away once it ages past keep_recent. mechanism=”baseline”, pin_context_events=False reproduces the original behavior exactly (control group).

cache, if provided, is a mutable dict the caller owns (one per blackboard) used by mechanism=”anchored” to carry its running summary across calls instead of re-summarizing the whole history every turn. Ignored by every other mechanism.

params are generation params for the summarizer request, such as max_tokens and temperature. max_tokens defaults to 500.

Parameters:
  • token_threshold (int)

  • keep_recent (int)

  • mechanism (str)

  • pin_context_events (bool)

  • cache (Dict[str, Any] | None)

  • evict_kinds (Set[str] | None)

  • extract_limit (int)

  • agent_name (str | None)

  • blackboard_id (Any)

  • phase (str | None)

  • iteration (int | None)

  • params (Dict[str, Any] | None)

Return type:

str