Quick Start
User Interaction Flow
Memory
Main memory manager for agents.Factory Methods
| Method | Signature | Description |
|---|---|---|
new(adapter, config) | fn new(impl MemoryAdapter, MemoryConfig) -> Self | Create with custom adapter |
in_memory(config) | fn in_memory(MemoryConfig) -> Self | Create in-memory storage |
default_memory() | fn default_memory() -> Self | Create with default config |
Instance Methods
| Method | Signature | Description |
|---|---|---|
store(message) | async fn store(&mut self, Message) -> Result<()> | Store a message |
history() | async fn history(&self) -> Result<Vec<Message>> | Get conversation history |
search(query, limit) | async fn search(&self, &str, usize) -> Result<Vec<Message>> | Search messages |
clear() | async fn clear(&mut self) -> Result<()> | Clear all memory |
config() | fn config(&self) -> &MemoryConfig | Get config reference |
MemoryConfig
Configuration for memory behavior.Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
use_short_term | bool | true | Enable short-term memory |
max_messages | usize | 100 | Max messages to retain |
ConversationHistory
Low-level message storage with automatic trimming.Methods
| Method | Signature | Description |
|---|---|---|
new(max) | fn new(usize) -> Self | Create with max messages |
add(message) | fn add(&mut self, Message) | Add message (auto-trims) |
messages() | fn messages(&self) -> Vec<Message> | Get all messages |
clear() | fn clear(&mut self) | Clear all messages |
len() | fn len(&self) -> usize | Message count |
is_empty() | fn is_empty(&self) -> bool | Check if empty |
Note: When trimming, system messages are preserved - only user/assistant messages are removed.
MemoryAdapter Trait
Interface for custom memory backends.InMemoryAdapter
Default in-memory implementation.Methods
| Method | Signature | Description |
|---|---|---|
new(max) | fn new(usize) -> Self | Create with max messages |
default() | fn default() -> Self | Create with 100 max messages |
Custom Memory Adapter
Best Practices
Set appropriate max_messages
Set appropriate max_messages
Too many messages increase token usage and cost. Start with 50-100.
Clear memory for new contexts
Clear memory for new contexts
Use
clear_memory() when starting unrelated conversations.System messages are preserved
System messages are preserved
The trimming algorithm keeps system messages - only user/assistant messages are removed when exceeding limits.
Use search for relevant context
Use search for relevant context
For long histories, use
search() to find relevant past messages instead of loading everything.Related
Agent
Agent API
Sessions
Session persistence

