Skip to main content

ContextConfig

Struct ContextConfig 

Source
pub struct ContextConfig {
Show 19 fields pub snip_threshold: f64, pub micro_threshold: f64, pub collapse_threshold: f64, pub auto_threshold: f64, pub renewal_threshold: f64, pub target_after_compress: f64, pub snip_per_msg_ratio: f64, pub carryover_ratio: f64, pub recovery_content_ratio: f64, pub preserve_recent_msgs: usize, pub preserve_recent_turns: usize, pub render_dashboard: bool, pub verbose_control_notes: bool, pub collapse_assistant_narration: bool, pub micro_compact_idle_minutes: u32, pub preserved_tool_results: usize, pub autocompact_buffer: u32, pub spool_threshold_bytes: u32, pub spool_preview_bytes: u32,
}
Expand description

All compression and context management parameters expressed as fractions of max_tokens. This is the single control surface for the compression pipeline: changing max_tokens (e.g. switching model) rescales every derived limit automatically with no other configuration change required.

Invariant: snip < micro < collapse < auto < renewal (strictly increasing).

Fields§

§snip_threshold: f64§micro_threshold: f64§collapse_threshold: f64§auto_threshold: f64§renewal_threshold: f64§target_after_compress: f64

Target rho after any compression pass. Must be < snip_threshold.

§snip_per_msg_ratio: f64

Fraction of max_tokens any single message may occupy after SnipCompact. Messages smaller than this are never touched.

§carryover_ratio: f64

Fraction of max_tokens worth of history tokens to carry across renewal. Renewal stops carrying messages once this token budget is exhausted.

§recovery_content_ratio: f64

Maximum fraction of max_tokens a recovery/replay payload may occupy.

§preserve_recent_msgs: usize

Recent history messages always kept during render.

§preserve_recent_turns: usize

Number of most-recent turns (user+assistant pairs) preserved by CollapseCompactor and AutoCompactor. Each turn = 2 messages, so the actual message count kept is preserve_recent_turns * 2. Must be ≥ 1. Default: 2 (= 4 messages).

§render_dashboard: bool

Include the dashboard block in the rendered system context. Defaults to false; enable only in explicit agent-os mode.

§verbose_control_notes: bool

Use verbose internal control notes (e.g. “[SYSTEM] Transaction rollback: …”). Defaults to false; uses concise natural-language notes instead.

§collapse_assistant_narration: bool

Collapse the narration text of OLD assistant turns (those past the preserve_recent_msgs window that also carry tool calls) to a short stub at render time — non-destructively (the full text stays in partitions.history). The model’s user-facing preamble (“好的,我来…先X”) has no value once it has aged out of the recent window, but re-feeding it verbatim every turn primes the model to keep emitting the same preamble (an in-context repetition trap). Tool calls and pairing are untouched; current progress lives in the TASK STATE turn. Defaults to true.

§micro_compact_idle_minutes: u32

Minutes of inactivity before triggering Micro-Compact (Layer 3). Defaults to 60 minutes — assumes Prompt Cache has expired by then.

§preserved_tool_results: usize

Number of recent tool results to preserve during Micro-Compact.

§autocompact_buffer: u32

Buffer size for Auto-Compact trigger (Layer 5). Trigger threshold = max_tokens - autocompact_buffer. Defaults to 13K tokens (p99.99 of summarizer output length + safety margin).

§spool_threshold_bytes: u32

Byte size above which a single tool result is spooled (Layer 1): the kernel keeps only a preview in context and emits LargeResultSpooled for the SDK to persist the full content to disk. Default: 50 KiB. 0 disables spooling.

§spool_preview_bytes: u32

Preview byte budget kept in context when a tool result is spooled. Default: 2 KiB.

Implementations§

Source§

impl ContextConfig

Source

pub fn target_tokens(&self, max_tokens: u32) -> u32

Token budget to target after a compression pass.

Source

pub fn snip_per_msg_tokens(&self, max_tokens: u32) -> u32

Per-message token cap used by SnipCompact. Floor of 50 ensures very small context windows still get useful output.

Source

pub fn carryover_tokens(&self, max_tokens: u32) -> u32

Token budget for history carryover across renewal.

Source

pub fn recovery_content_tokens(&self, max_tokens: u32) -> u32

Token cap for a single recovery/replay payload.

Source

pub fn autocompact_threshold(&self, max_tokens: u32) -> u32

Auto-Compact trigger threshold (Layer 5). Returns max_tokens - autocompact_buffer (absolute value).

Trait Implementations§

Source§

impl Clone for ContextConfig

Source§

fn clone(&self) -> ContextConfig

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 Debug for ContextConfig

Source§

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

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

impl Default for ContextConfig

Source§

fn default() -> Self

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

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<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, 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.