Quick Example
How It Works
Before each model call, the agent loads the session’s conversation entries and injects them as context. After each response, the agent stores the new messages. When the entry count exceedsmax_messages, a summarization strategy runs automatically — pinning the first few messages, summarizing the middle, and keeping the most recent messages intact.
Architecture
Memory Constructor
MemoryStore
default:"InMemoryStore()"
The storage backend. See Memory Stores for available options. When
None, defaults to an ephemeral InMemoryStore.Model
default:"None"
The LLM used for summarization when entries exceed
max_messages. When None, the agent’s own model is used at runtime.bool
default:true
Whether memory recall and storage are active. Set to
False to temporarily disable without removing the configuration.int
default:100
When the entry count exceeds this, the
SummarizeStrategy runs automatically to compress older messages.int
default:2
Number of earliest messages to always preserve during summarization. These provide initial context.
int
default:5
Number of most recent messages to always preserve during summarization. These provide current context.
Public Methods
Adding and Retrieving Entries
Getting Context Messages
MemoryEntry
Each conversation entry is represented as aMemoryEntry dataclass:
What’s Next
Memory Stores
Choose a storage backend: InMemory, SQLite, or file-based.
Agent Integration
Learn how memory integrates with the agent lifecycle and multi-user scoping.