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:
NoopMemoryPolicy— identity, returns input unchanged.SlidingWindowMemory— retains the most recentNmessages.TokenWindowMemory— retains messages that fit within a token budget.HeuristicTokenCounter— provider-agnostic, zero-dependencyTokenCounterthat approximates token cost from character lengths.DemotionHook+DemotingPolicyMemory— bridge truncated turns from aMemoryPolicyinto a long-tail store.Compactor+CompactingMemory— replace truncated turns with a derived summary artifact (rolling-summary semantics).TemplateCompactor— zero-dependency referenceCompactorthat produces a textual rollup without calling an LLM.
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§
- Compacting
Memory - A
ConversationMemoryadapter that wraps a backend with aMemoryPolicyand aCompactor, replacing truncated turns with a summary artifact spliced at the front of the loaded history. - Demoting
Policy Memory - A
ConversationMemoryadapter that wraps a backend with aMemoryPolicyand aDemotionHook, so messages truncated by the policy flow into the hook before the active window is returned. - Heuristic
Token Counter - A provider-agnostic
TokenCounterthat approximates token counts from UTF-8 byte lengths. - 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 - Wrap a
ConversationMemorybackend with aMemoryPolicy, propagating policy errors to the caller asMemoryError::Policy. - Sliding
Window Memory - A
MemoryPolicythat retains only the most recentmax_messagesentries. - Template
Compactor - A zero-dependency reference
Compactorthat produces a textual rollup of evicted messages without calling an LLM. - 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 a singleMessage-shaped artifact from a slice of messages that a memory policy has evicted from the active window. - 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. A side-channel for messages that a memory policy or adapter removes from active history duringConversationMemory::load. - 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.