Skip to main content

ConversationSummarizer

Struct ConversationSummarizer 

Source
pub struct ConversationSummarizer { /* private fields */ }
Expand description

Generates and caches conversation summaries for episodic memory.

Uses LLM to create concise summaries of conversation history. Implements incremental summarization - only new messages since the last summary are sent to the LLM, merged with the previous summary.

Implementations§

Source§

impl ConversationSummarizer

Source

pub fn new() -> Self

Create a new summarizer with default settings.

Source

pub fn with_threshold(self, n: usize) -> Self

Set the regeneration threshold (number of new messages before re-summarizing).

Source

pub fn with_max_length(self, n: usize) -> Self

Set the maximum summary length in characters.

Source

pub fn with_exclude_last(self, n: usize) -> Self

Set how many recent messages to exclude from summarization.

Source

pub fn needs_regeneration(&self, current_message_count: usize) -> bool

Check if summary needs regeneration based on message count delta.

Source

pub fn get_cached_summary(&self) -> Option<&str>

Get cached summary if available.

Source

pub fn generate_summary<F>( &mut self, messages: &[Value], llm_caller: F, ) -> String
where F: Fn(&[Value]) -> Option<String>,

Generate summary of conversation history using incremental approach.

Only sends new messages since the last summary to the LLM, along with the previous summary for context merging.

The llm_caller receives a slice of message values (system + user prompt) and should return Some(summary_text) on success.

Source

pub fn format_conversation(messages: &[Value]) -> String

Format messages into readable conversation text.

Source

pub fn clear_cache(&mut self)

Clear the cached summary.

Source

pub fn to_json(&self) -> Option<Value>

Serialize cache for session persistence.

Source

pub fn from_json(&mut self, data: Option<&Value>)

Load cache from session persistence.

Trait Implementations§

Source§

impl Default for ConversationSummarizer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.