#[non_exhaustive]pub struct ContextCompactionPolicy {
pub max_input_tokens: u32,
pub keep_recent_turns: usize,
}conversation only.Expand description
Policy controlling when and how Conversation drops older turns to
stay under a token budget.
v0.3 first cut implements truncation: oldest complete user→assistant
roundtrips are dropped until either the estimated input is under
Self::max_input_tokens or only Self::keep_recent_turns complete
roundtrips remain. Tool-use / tool-result pairs are preserved as a unit
(an assistant turn with tool_use blocks is never dropped without its
matching tool_result user turn and follow-up assistant text).
Token estimation is a fast local heuristic (~4 chars/token); for exact
counts use Conversation::estimate_input_tokens only as a hint, and
configure max_input_tokens with some headroom.
Future work (v0.4): callback-based summarization that replaces a span of old turns with a single text summary instead of dropping them.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.max_input_tokens: u32Compact when the estimated input would exceed this many tokens.
keep_recent_turns: usizeAfter compaction, keep at least this many complete roundtrips.
Trait Implementations§
Source§impl Clone for ContextCompactionPolicy
impl Clone for ContextCompactionPolicy
Source§fn clone(&self) -> ContextCompactionPolicy
fn clone(&self) -> ContextCompactionPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ContextCompactionPolicy
impl Debug for ContextCompactionPolicy
Source§impl Default for ContextCompactionPolicy
impl Default for ContextCompactionPolicy
Source§impl<'de> Deserialize<'de> for ContextCompactionPolicy
impl<'de> Deserialize<'de> for ContextCompactionPolicy
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ContextCompactionPolicy
impl PartialEq for ContextCompactionPolicy
Source§impl Serialize for ContextCompactionPolicy
impl Serialize for ContextCompactionPolicy
impl Eq for ContextCompactionPolicy
impl StructuralPartialEq for ContextCompactionPolicy
Auto Trait Implementations§
impl Freeze for ContextCompactionPolicy
impl RefUnwindSafe for ContextCompactionPolicy
impl Send for ContextCompactionPolicy
impl Sync for ContextCompactionPolicy
impl Unpin for ContextCompactionPolicy
impl UnsafeUnpin for ContextCompactionPolicy
impl UnwindSafe for ContextCompactionPolicy
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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 more