Skip to main content

Module memory

Module memory 

Source
Expand description

Conversation history storage, filtering, and compaction interfaces.

use rig_core::{
    completion::Message,
    memory::{ConversationMemory, InMemoryConversationMemory},
};

let memory = InMemoryConversationMemory::new();
memory
    .append(
        &"thread-1".into(),
        vec![
            Message::user("My name is Alice."),
            Message::assistant("Hello, Alice!"),
        ],
    )
    .await?;
let history = memory.load(&"thread-1".into()).await?;
assert_eq!(history.len(), 2);

Truncation, summarization, and other history-shaping policies live in the rig-memory companion crate. To shape history inside the in-tree backend, pass a closure to InMemoryConversationMemory::with_filter.

Structs§

InMemoryConversationMemory
A simple thread-safe in-memory ConversationMemory backed by a HashMap.
NoopDemotionHook
A DemotionHook that does nothing. Useful as a default when an adapter requires a hook value but the caller has no long-tail store wired up yet.

Enums§

MemoryError
Errors produced by a ConversationMemory backend.

Traits§

Compactor
Derives an artifact from evicted messages for insertion before recent history. Compaction runs inline during loading and delays the next turn.
ConversationMemory
A persistent conversation history backend.
DemotionHook
Receives messages removed from active history during ConversationMemory::load. Hooks are awaited inline, so their latency delays the next turn.
MessageFilter
A history-shaping closure applied during InMemoryConversationMemory::load.

Type Aliases§

MemoryBackendErrorNon-target_family=wasm
Boxed error source for memory backend failures.