Skip to main content

CompactionConfig

Struct CompactionConfig 

Source
pub struct CompactionConfig {
    pub token_threshold: usize,
    pub keep_last_messages: usize,
}
Expand description

Tuning knobs for non-destructive context compaction (#2070, §5.4).

Why: A caller (production: AgentLoop; tests: unit tests exercising Transcript directly) needs to control both “how big is too big” and “how much of the recent conversation counts as the active work zone” — bundling them avoids two separate parameters threading through every call site. What: token_threshold is compared against the transcript’s [estimate_tokens] total; keep_last_messages is the number of the most recent messages (the active work zone, §5.4 item 4) that are never eligible for compaction regardless of size. Test: compaction::tests::default_is_sane.

Fields§

§token_threshold: usize

Estimated-token threshold that triggers compaction once exceeded.

§keep_last_messages: usize

Number of most-recent messages kept verbatim (the active work zone).

Implementations§

Source§

impl CompactionConfig

Source

pub fn for_context_window(context_window: usize) -> Self

Derive a CompactionConfig proportional to a model’s real context window (#2308).

Why: This is the production constructor — the flat, model-blind Default threshold (see that impl’s doc) is the root cause of #2308’s pathological re-compaction. Every production call site that knows its model slug must resolve the model’s real context window (via crate::provider::resolve_context_window) and build its CompactionConfig through this constructor instead. What: token_threshold is context_window * [COMPACTION_THRESHOLD_FRACTION_PCT] / 100; keep_last_messages is unchanged from the previous default (6). Test: compaction::tests::for_context_window_scales_threshold_proportionally, compaction::tests::should_compact_does_not_trigger_at_10k_tokens_against_200k_window, compaction::tests::should_compact_triggers_near_75pct_of_200k_window.

Trait Implementations§

Source§

impl Clone for CompactionConfig

Source§

fn clone(&self) -> CompactionConfig

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 CompactionConfig

Source§

impl Debug for CompactionConfig

Source§

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

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

impl Default for CompactionConfig

Source§

fn default() -> Self

LEGACY/TEST-ONLY default — a flat, model-blind 6_000-token threshold.

Why: This was the pre-#2308 production default; the root cause of #2308’s pathological re-compaction (roughly every 2 turns at 4-13K estimated tokens) is exactly this hard-coded constant, which is only ~3% of a real Bedrock Claude Sonnet 200K-token context window. Kept for back-compat (tests that want a small, deterministic threshold without wiring a model slug) but production code must call CompactionConfig::for_context_window instead so the threshold scales with the model actually in use. What: §5.4 gives no exact numbers; these defaults keep several full tool-call round-trips (a handful of assistant+tool pairs) uncompacted while triggering well before a typical model’s context window is at risk — but ONLY for a small/unknown context window; see CompactionConfig::for_context_window for the model-aware production path.

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> AsOut<T> for T
where T: Copy,

Source§

fn as_out(&mut self) -> Out<'_, T>

Returns an out reference to self.
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<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> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
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> Same for T

Source§

type Output = T

Should always be Self
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<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