#[non_exhaustive]pub struct Offload;Expand description
Builds the offload strategies (Offload). Each returns a strategy; chain when to set when and
on what it acts.
Target OffloadTarget::All acts on whole messages; any other target acts on each block.
block_threshold measures whichever the target acts on, and context_utilization only gates
when the strategy fires. Targets All and Media need conditions from when; any other target
without them acts on each matching block as it arrives, before the model reads it.
use strands::context_manager::{
Offload, OffloadConditions, OffloadTarget, SummarizeConfig, TruncateConfig,
};
// Per block, eagerly: truncate each tool result over 1,500 tokens to a 750-token preview.
let truncate = Offload::truncate(
OffloadTarget::ToolResults,
TruncateConfig { preview_tokens: Some(750.0), ..Default::default() },
)?
.when(OffloadConditions { block_threshold: Some(1500.into()), ..Default::default() })?;
// Whole messages: summarize the oldest at 70% context utilization, keeping the newest four.
let summarize = Offload::summarize(OffloadTarget::All, SummarizeConfig::default())?.when(OffloadConditions {
context_utilization: Some("70%".into()),
preserve_recent: Some(4.into()),
..Default::default()
})?;
// Whole messages: once the window is full, drop the oldest, keeping the newest 70%.
let drop = Offload::drop(OffloadTarget::All)?.when(OffloadConditions {
context_utilization: Some("100%".into()),
preserve_recent: Some("70%".into()),
..Default::default()
})?;Implementations§
Source§impl Offload
impl Offload
Sourcepub fn drop(target: OffloadTarget) -> Result<DropStrategy>
pub fn drop(target: OffloadTarget) -> Result<DropStrategy>
Drops matching content from the context window entirely (Offload.drop). Without when
conditions, drops each block on arrival.
§Errors
A tool list target that is empty or excludes every tool it includes.
Sourcepub fn truncate(
target: OffloadTarget,
config: TruncateConfig,
) -> Result<TruncateStrategy>
pub fn truncate( target: OffloadTarget, config: TruncateConfig, ) -> Result<TruncateStrategy>
Replaces oversized content with a preview (Offload.truncate). Without when conditions,
truncates each block on arrival.
§Errors
A tool list target that is empty or excludes every tool it includes.
Sourcepub fn summarize(
target: OffloadTarget,
config: SummarizeConfig,
) -> Result<SummarizeStrategy>
pub fn summarize( target: OffloadTarget, config: SummarizeConfig, ) -> Result<SummarizeStrategy>
Replaces content with a model-written summary (Offload.summarize). Without when
conditions, summarizes each block on arrival.
§Errors
A tool list target that is empty or excludes every tool it includes.
Sourcepub fn defer(target: DeferTarget) -> Result<DeferStrategy>
pub fn defer(target: DeferTarget) -> Result<DeferStrategy>
Keeps tools’ input schemas out of the context until the model loads them with
load_tools (Offload.defer). The model still sees each deferred tool’s name and
description. Without when conditions, defers at any tool count;
either of its conditions is enough. One per context manager, the deferredToolLoading
preset included.
§Errors
A DeferTarget::Tools list that is empty, lists toolSpecs, or excludes every tool it
includes.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Offload
impl RefUnwindSafe for Offload
impl Send for Offload
impl Sync for Offload
impl Unpin for Offload
impl UnsafeUnpin for Offload
impl UnwindSafe for Offload
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
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<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> ⓘ
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