Expand description
Conversation memory: Rig-managed persistent conversation history for agents.
Memory differs from existing agent context features:
crate::agent::AgentBuilder::context: static documents always included in prompts.crate::agent::AgentBuilder::dynamic_context: RAG documents fetched from a vector store.crate::agent::prompt_request::PromptRequest::with_history: caller-managed message history.- Memory (this module): Rig-managed history loaded and saved automatically per conversation id.
§Example
use rig_core::client::{CompletionClient, ProviderClient};
use rig_core::completion::Prompt;
use rig_core::memory::InMemoryConversationMemory;
use rig_core::providers::openai;
let memory = InMemoryConversationMemory::new();
let openai = openai::Client::from_env()?;
let agent = openai.agent("gpt-4o").memory(memory).build();
agent.prompt("My name is Alice.")
.conversation("thread-1")
.await?;
let answer = agent.prompt("What's my name?")
.conversation("thread-1")
.await?;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§
- InMemory
Conversation Memory - A simple thread-safe in-memory
ConversationMemorybacked by aHashMap. - Noop
Demotion Hook - A
DemotionHookthat 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§
- Memory
Error - Errors produced by a
ConversationMemorybackend.
Traits§
- Compactor
- Derives a single
Message-shaped artifact from a slice of messages that a memory policy has evicted from the active window. - Conversation
Memory - A persistent conversation history backend.
- Demotion
Hook - A side-channel for messages that a memory policy or adapter removes from
active history during
ConversationMemory::load. - Message
Filter - A history-shaping closure applied during
InMemoryConversationMemory::load.
Type Aliases§
- Memory
Backend Error Non- target_family=wasm - Boxed error source for memory backend failures.