pub struct ContextManager {
pub budget: Option<ContextBudget>,
pub soft_compaction_threshold: f32,
pub hard_compaction_threshold: f32,
pub compaction_preserve_tail: usize,
pub prune_protect_tokens: usize,
pub compression: CompressionConfig,
pub routing: StoreRoutingConfig,
pub store_routing_provider: Option<Arc<AnyProvider>>,
pub compaction: CompactionState,
pub compaction_cooldown_turns: u8,
pub turns_since_last_hard_compaction: Option<u64>,
}Expand description
Per-session context lifecycle manager.
Holds the token budget, compaction lifecycle state, and routing configuration.
Callers in zeph-core drive the state machine via advance_turn, compaction_tier,
and related accessors; the assembler reads the budget via build_router and field access.
Fields§
§budget: Option<ContextBudget>Token budget for this session. None until configured via apply_budget_config.
soft_compaction_threshold: f32Soft compaction threshold (default 0.70): prune tool outputs + apply deferred summaries.
hard_compaction_threshold: f32Hard compaction threshold (default 0.90): full LLM-based summarization.
compaction_preserve_tail: usizeNumber of recent messages preserved during hard compaction.
prune_protect_tokens: usizeToken count protected from pruning during soft compaction.
compression: CompressionConfigCompression configuration for proactive compression.
routing: StoreRoutingConfigRouting configuration for query-aware memory routing.
store_routing_provider: Option<Arc<AnyProvider>>Resolved provider for LLM/hybrid routing. None when strategy is Heuristic
or when the named provider could not be resolved from the pool.
compaction: CompactionStateCompaction lifecycle state. Replaces four independent boolean/u8 fields to make
invalid states unrepresentable. See CompactionState for the full transition map.
compaction_cooldown_turns: u8Number of cooling turns to enforce after a successful hard compaction.
turns_since_last_hard_compaction: Option<u64>Counts user-message turns since the last hard compaction event.
None = no hard compaction has occurred yet in this session.
Some(n) = n turns have elapsed since the last hard compaction.
Implementations§
Source§impl ContextManager
impl ContextManager
Sourcepub fn apply_budget_config(
&mut self,
budget_tokens: usize,
reserve_ratio: f32,
hard_compaction_threshold: f32,
compaction_preserve_tail: usize,
prune_protect_tokens: usize,
soft_compaction_threshold: f32,
compaction_cooldown_turns: u8,
)
pub fn apply_budget_config( &mut self, budget_tokens: usize, reserve_ratio: f32, hard_compaction_threshold: f32, compaction_preserve_tail: usize, prune_protect_tokens: usize, soft_compaction_threshold: f32, compaction_cooldown_turns: u8, )
Apply budget and compaction thresholds from config.
Must be called once after config is resolved. Safe to call again when config reloads.
Sourcepub fn reset_compaction(&mut self)
pub fn reset_compaction(&mut self)
Reset compaction state for a new conversation.
Clears cooldown, exhaustion, and turn counters so the new conversation starts with a clean compaction slate.
Sourcepub fn compaction_tier(&self, cached_tokens: u64) -> CompactionTier
pub fn compaction_tier(&self, cached_tokens: u64) -> CompactionTier
Determine which compaction tier applies for the given token count.
Hardwhencached_tokens > budget * hard_compaction_thresholdSoftwhencached_tokens > budget * soft_compaction_thresholdNoneotherwise (or when no budget is set)
Sourcepub fn build_router(&self) -> Box<dyn AsyncMemoryRouter + Send + Sync>
pub fn build_router(&self) -> Box<dyn AsyncMemoryRouter + Send + Sync>
Build a memory router from the current routing configuration.
Returns a Box<dyn AsyncMemoryRouter> so callers can use route_async() for LLM-based
classification. HeuristicRouter implements AsyncMemoryRouter via a blanket impl that
delegates to the sync route_with_confidence.
Sourcepub fn should_proactively_compress(
&self,
current_tokens: u64,
) -> Option<(usize, usize)>
pub fn should_proactively_compress( &self, current_tokens: u64, ) -> Option<(usize, usize)>
Check if proactive compression should fire for the current turn.
Returns Some((threshold_tokens, max_summary_tokens)) when proactive compression
should be triggered, None otherwise.
Will return None if compaction already happened this turn (CRIT-03 fix).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ContextManager
impl !RefUnwindSafe for ContextManager
impl Send for ContextManager
impl Sync for ContextManager
impl Unpin for ContextManager
impl UnsafeUnpin for ContextManager
impl !UnwindSafe for ContextManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request