Overview
BufferMemory is the simplest memory provider for AgentLIB. It stores conversation messages in an in-memory Map keyed by sessionId, persisting for the lifetime of the process.
Best for: single-process applications, development, and testing.
Constructor
Configuration
Maximum number of messages to retain per session (counts pairs: user+assistant).
Oldest messages are dropped first. System messages are always kept.
If set, trim history to fit within this token budget.
Applied after
maxMessages trimming.Optional pre-populated store. Useful for seeding memory or testing.
Methods
read()
Retrieve conversation history for a session.options.sessionId- Session identifier (defaults to'default')options.limit- Maximum number of messages to returnoptions.query- Semantic query (not used by BufferMemory)options.tags- Filter by metadata tags (not used by BufferMemory)
write()
Persist messages for a session.messages- Array of messages to storeoptions.sessionId- Session identifier (defaults to'default')options.agentName- Name of the agent storing the messagesoptions.tags- Metadata tags for filtering
- Filters out system messages (they’re re-injected by the agent)
- Trims to
maxMessages(keeps newest) - Updates access timestamp
clear()
Remove stored memory.sessionId- If provided, clears only that session. Otherwise clears all sessions.
entries()
Retrieve raw memory entries for inspection/debugging.sessionId- If provided, returns only that session’s entry
MemoryEntry objects with metadata.
Properties
sessionCount
Number of active sessions currently in memory.Usage Examples
Basic Usage
With Token Budget
Pre-populated Store
Inspecting Memory
Type Reference
Source:/packages/memory/src/buffer.ts:11-30