pub trait MemoryPolicy: WasmCompatSend + WasmCompatSync {
// Required method
fn apply(&self, messages: Vec<Message>) -> Result<Vec<Message>, MemoryError>;
// Provided method
fn apply_with_demoted(
&self,
messages: Vec<Message>,
) -> Result<(Vec<Message>, Vec<Message>), MemoryError> { ... }
}Expand description
A transformation applied to messages loaded from a ConversationMemory.
Policies typically truncate, summarize, or re-order history. They are
pure, fallible message transformers: implementors that cannot fail should
always return Ok.
Required Methods§
Provided Methods§
Sourcefn apply_with_demoted(
&self,
messages: Vec<Message>,
) -> Result<(Vec<Message>, Vec<Message>), MemoryError>
fn apply_with_demoted( &self, messages: Vec<Message>, ) -> Result<(Vec<Message>, Vec<Message>), MemoryError>
Transform messages and report which messages were demoted (excluded
from the returned history).
Returns (kept, demoted). The default implementation returns
(self.apply(messages)?, Vec::new()), which is correct for
non-truncating policies. Truncating policies (sliding window, token
window, …) override this method to populate demoted with the
messages they evicted.
Implementors must guarantee that demoted is the prefix of the
original input not retained in kept, in original order. Composing
adapters such as DemotingPolicyMemory rely on this contract to
track delivery watermarks correctly.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".