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§
- Compacting
Memory - 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.
- Demoting
Policy Memory - 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. - Heuristic
Token Counter - 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.
- InMemory
Conversation Memory - Re-exports of the core memory abstractions so callers only need a single
dependency on
rig-memoryfor both the trait/backend and the policies. A simple thread-safe in-memoryConversationMemorybacked by aHashMap. - Noop
Demotion Hook - Re-exports of the core memory abstractions so callers only need a single
dependency on
rig-memoryfor both the trait/backend and the policies. ADemotionHookthat does nothing. Useful as a default when an adapter requires a hook value but the caller has no long-tail store wired up yet. - Noop
Memory Policy - A
MemoryPolicythat returns its input unchanged. - Policy
Memory - Applies a policy to loaded history, propagating backend and policy errors unchanged. Append and clear operations delegate to the backend.
- Sliding
Window Memory - A
MemoryPolicythat retains only the most recentmax_messagesentries. - Template
Compactor - Builds a textual rollup without calling a model.
Concatenates a header, the previous summary, and rendered evicted messages
into a
TextSummaryconvertible to a system message. - Text
Summary - Plain-text artifact produced by
TemplateCompactor. - Token
Window Memory - A
MemoryPolicythat retains the most recent messages up to a token budget.
Enums§
- Memory
Error - Re-exports of the core memory abstractions so callers only need a single
dependency on
rig-memoryfor both the trait/backend and the policies. Errors produced by aConversationMemorybackend.
Traits§
- Compactor
- Re-exports of the core memory abstractions so callers only need a single
dependency on
rig-memoryfor 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. - Conversation
Memory - Re-exports of the core memory abstractions so callers only need a single
dependency on
rig-memoryfor both the trait/backend and the policies. A persistent conversation history backend. - Demotion
Hook - Re-exports of the core memory abstractions so callers only need a single
dependency on
rig-memoryfor both the trait/backend and the policies. Receives messages removed from active history duringConversationMemory::load. Hooks are awaited inline, so their latency delays the next turn. - Into
Filter - Adapt a
MemoryPolicyinto a closure suitable forInMemoryConversationMemory::with_filter. - Memory
Policy - A transformation applied to messages loaded from a
ConversationMemory. - Token
Counter - Counts the tokens contributed by a single
Message.
Type Aliases§
- Boxed
Filter - Boxed filter closure returned by
IntoFilter::into_filter.