Manus-style context compaction.
When approaching the token limit, compacts old tool results into summaries and truncates old assistant text, preserving the first message (original request) and the most recent messages.
Summary
Functions
Compacts messages, preserving the first message and the most recent N messages.
Compacts state messages if over the 90% token budget threshold. Returns state unchanged if within budget.
Functions
@spec compact_messages( [Alloy.Message.t()], keyword() ) :: [Alloy.Message.t()]
Compacts messages, preserving the first message and the most recent N messages.
Options
:keep_recent- number of recent messages to preserve (default 10)
@spec maybe_compact(Alloy.Agent.State.t()) :: Alloy.Agent.State.t()
Compacts state messages if over the 90% token budget threshold. Returns state unchanged if within budget.