Memory
Memory enables your agent to remember user messages, agent replies, and tool results across interactions, giving it the context it needs to stay consistent, maintain conversation flow, and produce better answers over time.
Mastra supports three complementary memory types:
- Message history - keeps recent messages from the current conversation so they can be rendered in the UI and used to maintain short-term continuity within the exchange.
- Working memory - stores persistent, structured user data such as names, preferences, and goals.
- Semantic recall - retrieves relevant messages from older conversations based on semantic meaning rather than exact keywords, mirroring how humans recall information by association. Requires a vector database and an embedding model.
If the combined memory exceeds the model's context limit, memory processors can filter, trim, or prioritize content so the most relevant information is preserved.
Getting startedDirect link to Getting started
Choose a memory option to get started:
StorageDirect link to Storage
Before enabling memory, you must first configure a storage adapter. Mastra supports several databases including PostgreSQL, MongoDB, libSQL, and more.
Storage can be configured at the instance level (shared across all agents) or at the agent level (dedicated per agent).
For semantic recall, you can use a separate vector database like Pinecone alongside your primary storage.
See the Storage documentation for configuration options, supported providers, and examples.
Debugging memoryDirect link to Debugging memory
When tracing is enabled, you can inspect exactly which messages the agent uses for context in each request. The trace output shows all memory included in the agent's context window - both recent message history and messages recalled via semantic recall.

This visibility helps you understand why an agent made specific decisions and verify that memory retrieval is working as expected.
Next stepsDirect link to Next steps
- Learn more about Storage providers and configuration options
- Add Message history, Working memory, or Semantic recall
- Visit Memory configuration reference for all available options