pub struct ConversationMemory { /* private fields */ }Expand description
In-memory conversation history with configurable limits.
Implementations§
Source§impl ConversationMemory
impl ConversationMemory
Sourcepub fn new(config: MemoryConfig) -> Self
pub fn new(config: MemoryConfig) -> Self
Create a new memory with the given config.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a new memory with default configuration (5 turns, 4000 chars).
Sourcepub fn record_turn(&mut self, role: Role, content: impl Into<String>)
pub fn record_turn(&mut self, role: Role, content: impl Into<String>)
Record a new conversation turn, evicting the oldest if over max_turns.
Sourcepub fn format_context(&self) -> String
pub fn format_context(&self) -> String
Format the stored turns as a context string for injection.
Builds the context from most recent turns backward, stopping when
adding the next turn would exceed budget_chars. Returns the
context in chronological order.
Sourcepub fn config(&self) -> &MemoryConfig
pub fn config(&self) -> &MemoryConfig
Current configuration.
Trait Implementations§
Source§impl Clone for ConversationMemory
impl Clone for ConversationMemory
Source§fn clone(&self) -> ConversationMemory
fn clone(&self) -> ConversationMemory
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 Debug for ConversationMemory
impl Debug for ConversationMemory
Source§impl<'de> Deserialize<'de> for ConversationMemory
impl<'de> Deserialize<'de> for ConversationMemory
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ConversationMemory
impl RefUnwindSafe for ConversationMemory
impl Send for ConversationMemory
impl Sync for ConversationMemory
impl Unpin for ConversationMemory
impl UnwindSafe for ConversationMemory
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
Converts
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>
Converts
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