pub struct DeferStrategy { /* private fields */ }Expand description
A strategy that keeps tools’ input schemas out of the model’s context until the model loads
them with load_tools (DeferStrategy, built with
Offload::defer).
On every model call it picks the tools to defer from that call’s tools and passes their names
on the call as its deferred_tools. The call’s model decides how a deferred tool reaches it
(ModelCapabilities::deferred_tool_loading); a model that can’t defer tools gets every spec.
The model still sees each deferred tool’s name and description and loads a schema with
load_tools, which the context manager registers. A call to a deferred tool before its load
gets the schema back instead of running. SDK tools such as load_tools and retrieve_context
are never deferred, nor is a tool that takes no parameters, since its stub would leave nothing
out. It never changes the messages. One per context manager, the deferredToolLoading preset
included.
use strands::context_manager::{DeferConditions, DeferTarget, Offload};
// From 20 tools, or once their schemas reach 5% of the context window, defer every one but shell's.
let defer = Offload::defer(DeferTarget::tools(["!shell"]))?.when(DeferConditions {
tool_count: Some(20.into()),
schema_tokens: Some("5%".into()),
})?;Implementations§
Source§impl DeferStrategy
impl DeferStrategy
Sourcepub fn when(&self, conditions: DeferConditions) -> Result<Self>
pub fn when(&self, conditions: DeferConditions) -> Result<Self>
A copy of this strategy with these conditions in place of its current ones (when).
§Errors
A tool_count that is not a whole number above 0, or a schema_tokens that is not a whole
number above 0 or a "N%" string below "100%".
Trait Implementations§
Source§impl Clone for DeferStrategy
impl Clone for DeferStrategy
Source§impl ContextStrategy for DeferStrategy
impl ContextStrategy for DeferStrategy
Source§fn apply<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_context: &'life1 mut ContextState<'life2>,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn apply<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_context: &'life1 mut ContextState<'life2>,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Messages are never changed; the tools list is rendered on each model call.
Auto Trait Implementations§
impl Freeze for DeferStrategy
impl RefUnwindSafe for DeferStrategy
impl Send for DeferStrategy
impl Sync for DeferStrategy
impl Unpin for DeferStrategy
impl UnsafeUnpin for DeferStrategy
impl UnwindSafe for DeferStrategy
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