Skip to main content

Crate rig_memory

Crate rig_memory 

Source
Expand description

Conversation memory policies for the Rig agent framework.

rig-core provides the ConversationMemory trait and an in-process InMemoryConversationMemory backend. This crate adds reusable, named transformations for shaping loaded history before it is sent to the model:

All sliding policies drop a leading orphan tool-result message when the preceding assistant tool call has been truncated, since most providers reject unpaired tool results.

§Example

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

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

Structs§

CompactingMemory
A ConversationMemory adapter that wraps a backend with a MemoryPolicy and a Compactor, replacing truncated turns with a summary artifact spliced at the front of the loaded history.
DemotingPolicyMemory
A ConversationMemory adapter that wraps a backend with a MemoryPolicy and a DemotionHook, so messages truncated by the policy flow into the hook before the active window is returned.
HeuristicTokenCounter
A provider-agnostic TokenCounter that approximates token counts from UTF-8 byte lengths.
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
Wrap a ConversationMemory backend with a MemoryPolicy, propagating policy errors to the caller as MemoryError::Policy.
SlidingWindowMemory
A MemoryPolicy that retains only the most recent max_messages entries.
TemplateCompactor
A zero-dependency reference Compactor that produces a textual rollup of evicted messages without calling an LLM.
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 a single Message-shaped artifact from a slice of messages that a memory policy has evicted from the active window.
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. A side-channel for messages that a memory policy or adapter removes from active history during ConversationMemory::load.
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.