pub struct Compaction { /* private fields */ }Expand description
How much of a conversation reaches the model, for every run a workspace mints.
Set with WorkspaceBuilder::with_compaction;
unset, Compaction::default() applies. with_* returns a new value, so a
host can keep one of these beside its other defaults and finish it
differently per workspace.
Implementations§
Source§impl Compaction
impl Compaction
Sourcepub fn with_keep_recent_tool_results(self, keep: Option<usize>) -> Self
pub fn with_keep_recent_tool_results(self, keep: Option<usize>) -> Self
Elides all but the keep most recent tool results from every provider
request, or keeps all of them with None.
A host asks for this by number when it knows something basis does not: that its tool results are large, repetitive, and cheaply re-derived, and that the tokens are worth more than the transcript. What it costs is stated plainly — the model stops being able to see results it was shown. The request-only event reports that loss, but any turn that depends on comparing an early result against a late one still becomes unreliable.
Some(0) elides every tool result over 100 bytes, including the one
that just came back.
Sourcepub fn with_auto_threshold_tokens(self, tokens: Option<usize>) -> Self
pub fn with_auto_threshold_tokens(self, tokens: Option<usize>) -> Self
Triggers a summarizing pass once an estimated request reaches tokens,
for a model whose context window basis does not know — or, with None,
declines to name a number for one at all.
The estimate is mentra’s, over the serialized messages plus the system
prompt, and it is not the provider’s accounting.
with_auto_threshold_percent wins
over this whenever the window is known, so this is the fallback a
host sets for a model it cannot ask, or the only number that matters
once the percentage is cleared.
None here is no longer the off switch for the whole mechanism, which
is what it meant until mentra 0.24 separated the switch from the number
(AutoCompactTrigger). Cleared while the percentage stands, it now
asks for the posture that used to be unspellable: compact at a share of
a known window, and do not compact at all for a model whose window
nobody reports — rather than falling back on a figure a host had to
invent precisely for the case where inventing one is worst. Clearing
both numbers is the off switch, and the only spelling of it.
Off is a real posture, not a way of saying later: nothing then shortens the history ahead of time, and a conversation that outgrows the window gets exactly the recovery every other posture also gets — the provider’s own refusal triggers one compaction and one retry (see this module’s header) — rather than a second, earlier attempt basis would have made on its own guess. It suits a run that is bounded by construction — one prompt, a handful of turns — where an earlier pass would only ever cost a model call it did not need.
Sourcepub fn with_auto_threshold_percent(self, percent: Option<u8>) -> Self
pub fn with_auto_threshold_percent(self, percent: Option<u8>) -> Self
Triggers a summarizing pass once an estimated request reaches percent
of the model’s context window, when that window is known — or pins the
trigger to with_auto_threshold_tokens’s
absolute number regardless, with None.
The window is known when
PreparedRun::context_window
returns Some — today, a workspace whose provider is Gemini; Anthropic
and the Responses transport do not report one, so this has no effect for
them until they do. Values above 100 are treated as 100.
With with_auto_threshold_tokens
cleared this is the whole trigger: a model that reports no window
then never auto-compacts, instead of falling back on an absolute number
the host declined to give. Clearing this one as well is how automatic
summarizing is turned off — see there.
basis reads mentra’s own default (75) here rather than choosing one: unlike the absolute number, a percentage is not a guess about any particular model, so there is nothing basis knows that would make a different figure more honest.
Sourcepub fn with_preserve_recent_user_tokens(self, tokens: usize) -> Self
pub fn with_preserve_recent_user_tokens(self, tokens: usize) -> Self
Keeps at least tokens of the most recent user turns verbatim through a
summarizing pass.
What the user actually asked for is the thing a summary is least able to stand in for, which is why mentra protects a budget of it and why this is a knob rather than one of the six that stayed behind.
Trait Implementations§
Source§impl Clone for Compaction
impl Clone for Compaction
impl Copy for Compaction
Source§impl Debug for Compaction
impl Debug for Compaction
Source§impl Default for Compaction
Keeps every tool result, and leaves every one of mentra’s summarizing
numbers where mentra put them.
impl Default for Compaction
Keeps every tool result, and leaves every one of mentra’s summarizing numbers where mentra put them.
The three it leaves alone are read off mentra’s own default rather than copied into a constant here. basis has no basis for choosing any of them — the window-relative trigger is a fact about the model, and the preserved-user-text budget is a property of how mentra summarizes — so restating them as literals would mean maintaining a second opinion that can silently drift from the first.