ExAgent.Compaction.Summary (ExAgent v1.1.0)

Copy Markdown View Source

A compactor that summarizes older messages and keeps a recent window verbatim.

When the history exceeds :threshold_tokens (estimated via ExAgent.Compaction.estimate_tokens/1 by default), everything older than the last :keep_recent messages is replaced by a single system message produced by the caller-supplied :summarize function — typically an ExAgent.run/3 call to a cheap summarizer model.

Options

  • :threshold_tokens — compact once the estimate exceeds this (default 4000).
  • :keep_recent — number of trailing messages kept verbatim (default 6).
  • :summarize(old_messages -> summary_text). Required to compact; if absent, the history is left untouched.
  • :token_counter(messages -> non_neg_integer()), default ExAgent.Compaction.estimate_tokens/1.

Wiring

compaction = %ExAgent.Compaction.Capability{
  compactor: ExAgent.Compaction.Summary,
  opts: [
    threshold_tokens: 6000,
    keep_recent: 8,
    summarize: fn old ->
      {:ok, %{output: text}} = ExAgent.run(summarizer_agent, summarize_prompt(old))
      text
    end
  ]
}

ExAgent.new(model: "anthropic:claude-3-5-haiku", capabilities: [compaction])