Skip to main content

Context compaction

agentcore estimates conversation size and compacts history when it crosses the configured threshold.

The current algorithm:

  1. Scans backwards to find a recent window within the token estimate.
  2. Collects tool request identifiers in the retained window.
  3. Expands the window when a retained tool result would otherwise lose its matching request.
  4. Prepends a marker explaining that earlier history was pruned.

The invariant is structural: a retained tool result must not be orphaned from its tool request. The implementation does not yet produce a semantic summary of discarded conversation content, and token counting remains an approximation.