Owns the information sent to the model.
Older messages may be deterministically compressed, but the original goal and optional system prompt are always preserved.
Summary
Functions
Appends an assistant reply.
Appends a tool result.
Appends a user message.
Deterministically compresses context if its rendered message count
exceeds opts[:max_messages] (required): the oldest messages are folded
into context.summary (capped at opts[:summary_char_limit], default
Renders context into the ordered list of messages sent to the model:
optional system prompt, the goal as a user message, the compressed-history
summary (if any) as a system message, then the accumulated messages.
Starts a fresh context for goal, optionally with a :system_prompt.
Types
@type compression_metadata() :: %{ :compressed? => boolean(), :before_count => non_neg_integer(), :after_count => non_neg_integer(), :compressed_messages => non_neg_integer(), optional(:summary_chars) => non_neg_integer() }
Functions
Appends an assistant reply.
Appends a tool result.
Appends a user message.
@spec compress( t(), keyword() ) :: {:ok, t(), compression_metadata()} | {:error, {:context_limit_too_small, map()}}
Deterministically compresses context if its rendered message count
exceeds opts[:max_messages] (required): the oldest messages are folded
into context.summary (capped at opts[:summary_char_limit], default
- and dropped from
messages. Returns{:ok, context, metadata}(unchanged if under the limit, withmetadata.compressed? == false), or{:error, {:context_limit_too_small, %{...}}}if:max_messagesis too small to hold the goal + optional system prompt + at least one summary/message slot.
Renders context into the ordered list of messages sent to the model:
optional system prompt, the goal as a user message, the compressed-history
summary (if any) as a system message, then the accumulated messages.
Starts a fresh context for goal, optionally with a :system_prompt.