Skip to main content

ConversationMemory

Trait ConversationMemory 

Source
pub trait ConversationMemory: WasmCompatSend + WasmCompatSync {
    // Required methods
    fn load<'a>(
        &'a self,
        conversation_id: &'a str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, MemoryError>> + Send + 'a>>;
    fn append<'a>(
        &'a self,
        conversation_id: &'a str,
        messages: Vec<Message>,
    ) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'a>>;
    fn clear<'a>(
        &'a self,
        conversation_id: &'a str,
    ) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'a>>;
}
Expand description

Re-exports of the core memory abstractions so callers only need a single dependency on rig-memory for both the trait/backend and the policies. A persistent conversation history backend.

Implementors store an ordered list of Messages per conversation_id. Rig invokes ConversationMemory::load before sending a prompt and ConversationMemory::append after a successful turn.

Implementations should keep append cheap; it runs inline before the agent returns its response.

Required Methods§

Source

fn load<'a>( &'a self, conversation_id: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, MemoryError>> + Send + 'a>>

Load the full conversation history for conversation_id.

Returns an empty Vec if the conversation has no stored messages.

Source

fn append<'a>( &'a self, conversation_id: &'a str, messages: Vec<Message>, ) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'a>>

Append messages to the conversation identified by conversation_id.

Called after a successful agent turn with the user prompt, the assistant response, and any tool-call/tool-result pairs that occurred during the turn.

Source

fn clear<'a>( &'a self, conversation_id: &'a str, ) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'a>>

Remove all stored messages for conversation_id.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<M> ConversationMemory for Arc<M>

Source§

fn load<'a>( &'a self, conversation_id: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, MemoryError>> + Send + 'a>>

Source§

fn append<'a>( &'a self, conversation_id: &'a str, messages: Vec<Message>, ) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'a>>

Source§

fn clear<'a>( &'a self, conversation_id: &'a str, ) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'a>>

Source§

impl<M> ConversationMemory for Box<M>

Source§

fn load<'a>( &'a self, conversation_id: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>, MemoryError>> + Send + 'a>>

Source§

fn append<'a>( &'a self, conversation_id: &'a str, messages: Vec<Message>, ) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'a>>

Source§

fn clear<'a>( &'a self, conversation_id: &'a str, ) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'a>>

Implementors§