Context compaction
agentcore estimates conversation size and compacts history when it crosses the configured threshold.
The current algorithm:
- Scans backwards to find a recent window within the token estimate.
- Collects tool request identifiers in the retained window.
- Expands the window when a retained tool result would otherwise lose its matching request.
- 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.