Memory
Memory lets agents retain context across turns. AutoAgents exposes a MemoryProvider trait and includes a simple sliding‑window implementation.
Sliding Window Memory
SlidingWindowMemory stores the most recent N messages (FIFO). Use it when recent context is sufficient and you want predictable memory usage.
#![allow(unused)]
fn main() {
use autoagents::core::agent::memory::SlidingWindowMemory;
let memory = Box::new(SlidingWindowMemory::new(10));
}
Attach memory via AgentBuilder:
#![allow(unused)]
fn main() {
let handle = AgentBuilder::<_, DirectAgent>::new(agent)
.llm(llm)
.memory(Box::new(SlidingWindowMemory::new(10)))
.build()
.await?;
}
The ReAct executor automatically stores user/assistant messages and tool interactions in memory each turn.
Custom Memory
Implement MemoryProvider to support alternate strategies (e.g., vector‑store, summaries, persistence). Key methods:
remember(&ChatMessage)— store messagerecall(query, limit)— retrieve relevant contextclear()— resetsize()/memory_type()— diagnostics
The trait includes convenience hooks for summarization and export/import if you need persistence.