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 the assistant's tool-call message.
Appends a tool result, tagged with the call_id of the tool call it
answers (see add_tool_call/2).
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
(assistant replies, and tool-call/tool-result pairs correlated by
call_id).
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.
@spec add_tool_call(t(), BeamAgent.LLM.Client.tool_call()) :: t()
Appends the assistant's tool-call message.
A real provider first emits a message announcing which tool call it
wants (identified by tool_call.id); the matching add_tool_result/3
then carries the same id so the provider can correlate the result back
to the request.
Appends a tool result, tagged with the call_id of the tool call it
answers (see add_tool_call/2).
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
(assistant replies, and tool-call/tool-result pairs correlated by
call_id).
Starts a fresh context for goal, optionally with a :system_prompt.