Skip to main content
Mastra 1.0 is available 🎉 Read announcement

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 started
Direct link to Getting started

Choose a memory option to get started:

Storage
Direct 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 memory
Direct 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.

Trace output showing memory context included in an agent request

This visibility helps you understand why an agent made specific decisions and verify that memory retrieval is working as expected.

Next steps
Direct link to Next steps

On this page