#[non_exhaustive]pub struct HistoryLimit {
pub max_messages: usize,
pub max_bytes: usize,
}Expand description
The most a task’s history keeps: a number of messages and a number of
bytes, whichever is reached first. The oldest messages go first.
§Why bytes as well as messages
A count alone bounds nothing in bytes: at the default 4 MiB request body, 1,024 messages is 4 GiB of one task’s history, all of it from remote input. Bytes are each message’s serialized JSON length, the form it is sent and stored in.
§The newest message is always kept
A turn is never stored without the message that made it, so a message
larger than max_bytes on its own is kept and everything older goes. The
request body limit bounds that message.
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_messages: usizeAt most this many messages.
max_bytes: usizeAt most this many bytes of serialized messages; the newest message is kept even when it alone is larger.
Implementations§
Source§impl HistoryLimit
impl HistoryLimit
Sourcepub const fn new(max_messages: usize, max_bytes: usize) -> HistoryLimit
pub const fn new(max_messages: usize, max_bytes: usize) -> HistoryLimit
A limit of max_messages messages and max_bytes bytes.
Sourcepub fn trim(self, history: &mut Vec<Message>)
pub fn trim(self, history: &mut Vec<Message>)
Drops the oldest messages of history until it is within this limit,
keeping the newest message whatever its size.
A cheap upper bound on the history’s size is taken first, from string
lengths and structure without serializing anything; when it is within
max_bytes nothing can need trimming and nothing is measured. Only
otherwise are sizes measured exactly, from the newest message
backwards, stopping at the first that does not fit, so that cost is
bounded by max_bytes (plus one message) however long the history
was.
Measured 2026-10-18 (release build, 4-vCPU Xeon at 2.8 GHz, 60 runs each, a timing harness not kept in the tree): 1,024 messages of 100 bytes, median 10.2 µs (p90 16.6) with the bound against 108 µs (p90 149) for the exact walk alone, which every turn of a long conversation would otherwise pay; a history of sixteen 1 MiB messages, which the bound cannot clear, median 11.0 ms either way.
Trait Implementations§
Source§impl Clone for HistoryLimit
impl Clone for HistoryLimit
Source§fn clone(&self) -> HistoryLimit
fn clone(&self) -> HistoryLimit
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for HistoryLimit
Source§impl Debug for HistoryLimit
impl Debug for HistoryLimit
impl Eq for HistoryLimit
Source§impl PartialEq for HistoryLimit
impl PartialEq for HistoryLimit
impl StructuralPartialEq for HistoryLimit
Auto Trait Implementations§
impl Forget for HistoryLimit
impl Freeze for HistoryLimit
impl Move for HistoryLimit
impl RefUnwindSafe for HistoryLimit
impl Send for HistoryLimit
impl Sync for HistoryLimit
impl Unpin for HistoryLimit
impl UnsafeUnpin for HistoryLimit
impl UnwindSafe for HistoryLimit
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].