Skip to main content

Crate rig_memory

Crate rig_memory 

Source
Expand description

Conversation-history windows, demotion hooks, and rolling summaries. Window policies remove leading orphaned tool results along with truncated history. Stateful adapters deliver evicted prefixes to hooks or compactors.

use rig_memory::{InMemoryConversationMemory, IntoFilter, SlidingWindowMemory};

let memory = InMemoryConversationMemory::new()
    .with_filter(SlidingWindowMemory::last_messages(20).into_filter());

Structs§

CompactingMemory
Prepends a rolling summary of demoted history to the policy’s retained window. New evictions are compacted with the previous artifact as carry-over. The summary is outside the policy budget; callers needing a bounded prompt must also bound the compactor’s artifact.
DemotingPolicyMemory
Applies a policy and delivers newly demoted prefixes to a hook before returning retained history. The policy must report demotions through MemoryPolicy::apply_with_demoted.
HeuristicTokenCounter
Estimates token cost from UTF-8 lengths, rounded up per text-bearing part. Tool calls count name bytes plus serialized argument bytes. Attachments and message overhead have fixed costs. These estimates do not bound provider usage.
InMemoryConversationMemory
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 simple thread-safe in-memory ConversationMemory backed by a HashMap.
NoopDemotionHook
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 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.
NoopMemoryPolicy
A MemoryPolicy that returns its input unchanged.
PolicyMemory
Applies a policy to loaded history, propagating backend and policy errors unchanged. Append and clear operations delegate to the backend.
SlidingWindowMemory
A MemoryPolicy that retains only the most recent max_messages entries.
TemplateCompactor
Builds a textual rollup without calling a model. Concatenates a header, the previous summary, and rendered evicted messages into a TextSummary convertible to a system message.
TextSummary
Plain-text artifact produced by TemplateCompactor.
TokenWindowMemory
A MemoryPolicy that retains the most recent messages up to a token budget.

Enums§

MemoryError
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. Errors produced by a ConversationMemory backend.

Traits§

Compactor
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. Derives an artifact from evicted messages for insertion before recent history. Compaction runs inline during loading and delays the next turn.
ConversationMemory
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.
DemotionHook
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. Receives messages removed from active history during ConversationMemory::load. Hooks are awaited inline, so their latency delays the next turn.
IntoFilter
Adapt a MemoryPolicy into a closure suitable for InMemoryConversationMemory::with_filter.
MemoryPolicy
A transformation applied to messages loaded from a ConversationMemory.
TokenCounter
Counts the tokens contributed by a single Message.

Type Aliases§

BoxedFilter
Boxed filter closure returned by IntoFilter::into_filter.