Skip to main content

Compaction

Struct Compaction 

Source
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

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Compaction

Source§

impl Debug for Compaction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Compaction

Source§

impl PartialEq for Compaction

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Compaction

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more