pub struct SlidingWindowConversationManager { /* private fields */ }Expand description
Sliding window conversation manager (default)
Keeps as many recent messages as will fit within the context window. This implementation never fails due to context overflow - it will always truncate old messages to fit.
The manager reserves space for the system prompt and leaves headroom for the model’s response.
§Example
use mixtape_core::conversation::SlidingWindowConversationManager;
// Use defaults (10% reserved for system prompt, 20% for response)
let manager = SlidingWindowConversationManager::new();
// Or customize the reserved percentages
let manager = SlidingWindowConversationManager::with_reserve(0.15, 0.25);Implementations§
Source§impl SlidingWindowConversationManager
impl SlidingWindowConversationManager
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new sliding window manager with default reserves
Defaults:
- 10% reserved for system prompt
- 20% reserved for model response
Sourcepub fn with_reserve(system_prompt_reserve: f32, response_reserve: f32) -> Self
pub fn with_reserve(system_prompt_reserve: f32, response_reserve: f32) -> Self
Create a manager with custom reserve percentages
§Arguments
system_prompt_reserve- Fraction of context for system prompt (0.0 - 1.0)response_reserve- Fraction of context for model response (0.0 - 1.0)
Trait Implementations§
Source§impl Clone for SlidingWindowConversationManager
impl Clone for SlidingWindowConversationManager
Source§fn clone(&self) -> SlidingWindowConversationManager
fn clone(&self) -> SlidingWindowConversationManager
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl ConversationManager for SlidingWindowConversationManager
impl ConversationManager for SlidingWindowConversationManager
Source§fn add_message(&mut self, message: Message)
fn add_message(&mut self, message: Message)
Add a message to the conversation history
Source§fn messages_for_context(
&self,
limits: ContextLimits,
estimate_tokens: TokenEstimator<'_>,
) -> Vec<Message>
fn messages_for_context( &self, limits: ContextLimits, estimate_tokens: TokenEstimator<'_>, ) -> Vec<Message>
Get messages to send to the model (may be a subset of all messages) Read more
Source§fn all_messages(&self) -> &[Message]
fn all_messages(&self) -> &[Message]
Get all messages in the conversation (full history)
Source§fn hydrate(&mut self, messages: Vec<Message>)
fn hydrate(&mut self, messages: Vec<Message>)
Restore conversation state from persisted messages
Source§fn context_usage(
&self,
limits: ContextLimits,
estimate_tokens: TokenEstimator<'_>,
) -> ContextUsage
fn context_usage( &self, limits: ContextLimits, estimate_tokens: TokenEstimator<'_>, ) -> ContextUsage
Get context usage statistics
Auto Trait Implementations§
impl Freeze for SlidingWindowConversationManager
impl RefUnwindSafe for SlidingWindowConversationManager
impl Send for SlidingWindowConversationManager
impl Sync for SlidingWindowConversationManager
impl Unpin for SlidingWindowConversationManager
impl UnwindSafe for SlidingWindowConversationManager
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