pub struct ConsolidatingBufferMemory { /* private fields */ }Expand description
Layered memory: a BufferMemory for recent turns, a
SummaryMemory for the running summary, and a Summarizer
that bridges the two when the buffer’s policy fires.
append drives the full loop:
let mem = ConsolidatingBufferMemory::new(buffer, summary, summariser);
mem.append(&ctx, Message::user("hi")).await?;
// — buffer now has the new message; if the policy fires,
// the previous buffer has already been summarised into
// `summary` and the buffer cleared.Implementations§
Source§impl ConsolidatingBufferMemory
impl ConsolidatingBufferMemory
Sourcepub fn new(
buffer: Arc<BufferMemory>,
summary: Arc<SummaryMemory>,
summarizer: Arc<dyn Summarizer>,
) -> Self
pub fn new( buffer: Arc<BufferMemory>, summary: Arc<SummaryMemory>, summarizer: Arc<dyn Summarizer>, ) -> Self
Build a layered memory from an existing buffer, summary, and
summariser. The buffer must already have a
crate::ConsolidationPolicy attached via
BufferMemory::with_consolidation_policy — without one the
adapter never consolidates and behaves as a thin
BufferMemory proxy.
Sourcepub const fn buffer(&self) -> &Arc<BufferMemory> ⓘ
pub const fn buffer(&self) -> &Arc<BufferMemory> ⓘ
Borrow the underlying buffer (for direct queries that bypass the consolidation loop, such as size accounting).
Sourcepub const fn summary(&self) -> &Arc<SummaryMemory> ⓘ
pub const fn summary(&self) -> &Arc<SummaryMemory> ⓘ
Borrow the underlying summary memory.
Sourcepub async fn append(
&self,
ctx: &ExecutionContext,
message: Message,
) -> Result<()>
pub async fn append( &self, ctx: &ExecutionContext, message: Message, ) -> Result<()>
Append message to the buffer, then check the bound
consolidation policy. When it fires, summarise the buffered
messages, append the summary to SummaryMemory, clear the
buffer, and mark the buffer’s last_consolidated_at.
Sourcepub async fn messages(&self, ctx: &ExecutionContext) -> Result<Vec<Message>>
pub async fn messages(&self, ctx: &ExecutionContext) -> Result<Vec<Message>>
Fetch the current buffered messages.
Sourcepub async fn current_summary(
&self,
ctx: &ExecutionContext,
) -> Result<Option<String>>
pub async fn current_summary( &self, ctx: &ExecutionContext, ) -> Result<Option<String>>
Fetch the current running summary.
Sourcepub async fn clear(&self, ctx: &ExecutionContext) -> Result<()>
pub async fn clear(&self, ctx: &ExecutionContext) -> Result<()>
Reset both layers — buffer and summary.