pub struct ToolResultClearingStrategy { /* private fields */ }Expand description
Replaces old tool result content with a placeholder to reduce token usage.
Keeps the most recent keep_recent_n tool results intact and replaces
older ones with [tool result cleared] while preserving the tool_use_id
so the conversation still makes semantic sense.
§Example
use neuron_context::ToolResultClearingStrategy;
let strategy = ToolResultClearingStrategy::new(2, 100_000);Implementations§
Source§impl ToolResultClearingStrategy
impl ToolResultClearingStrategy
Sourcepub fn new(keep_recent_n: usize, max_tokens: usize) -> Self
pub fn new(keep_recent_n: usize, max_tokens: usize) -> Self
Creates a new ToolResultClearingStrategy.
§Arguments
keep_recent_n— number of most-recent tool results to leave untouchedmax_tokens— token threshold above which compaction is triggered
Sourcepub fn with_counter(
keep_recent_n: usize,
max_tokens: usize,
counter: TokenCounter,
) -> Self
pub fn with_counter( keep_recent_n: usize, max_tokens: usize, counter: TokenCounter, ) -> Self
Creates a new ToolResultClearingStrategy with a custom TokenCounter.
Trait Implementations§
Source§impl ContextStrategy for ToolResultClearingStrategy
impl ContextStrategy for ToolResultClearingStrategy
Source§fn should_compact(&self, messages: &[Message], token_count: usize) -> bool
fn should_compact(&self, messages: &[Message], token_count: usize) -> bool
Whether compaction should be triggered given the current messages and token count.
Source§fn compact(
&self,
messages: Vec<Message>,
) -> impl Future<Output = Result<Vec<Message>, ContextError>> + WasmCompatSend
fn compact( &self, messages: Vec<Message>, ) -> impl Future<Output = Result<Vec<Message>, ContextError>> + WasmCompatSend
Compact the message list to reduce token usage.
Source§fn token_estimate(&self, messages: &[Message]) -> usize
fn token_estimate(&self, messages: &[Message]) -> usize
Estimate the token count for a list of messages.
Auto Trait Implementations§
impl Freeze for ToolResultClearingStrategy
impl RefUnwindSafe for ToolResultClearingStrategy
impl Send for ToolResultClearingStrategy
impl Sync for ToolResultClearingStrategy
impl Unpin for ToolResultClearingStrategy
impl UnsafeUnpin for ToolResultClearingStrategy
impl UnwindSafe for ToolResultClearingStrategy
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
Mutably borrows from an owned value. Read more