Maximem Synap's Agent Memory Now Available for Mastra
Mastra has emerged as the TypeScript-native choice for developers building production agents. Type-safe workflows. Native async patterns. If you are building an agent in TypeScript, Mastra is where you start.
Today, Maximem Synap extends Mastra with persistent per-user memory. Native memory stores conversation state within a single process. Synap makes that state survive restarts, resolve entities across sessions, and retrieve relevant context without manual wiring.
Where Mastra Excels
Mastra gave TypeScript developers a framework that feels native. Workflows with proper type inference. Agent coordination without fighting the type system. Tool calling with full IDE support. If your agent needs to enforce schemas, coordinate multiple agents, or guarantee output structure, Mastra handles the type plumbing well.
The problem emerges when your user returns after a day or a week. Mastra's memory options handle the current session. They do not persist across process restarts. Type safety does not help if the agent forgets what the user told it yesterday.
How Mastra Memory Works Today
Mastra ships memory options for conversation tracking. All store data within a single process lifetime. For a deeper look at how each works, see the Mastra documentation
MemoryManager stores every message in a list attached to the agent run. This scratchpad grows with each turn. After twenty exchanges, your context window fills with accumulated noise. The agent struggles to find your actual instructions. When the process restarts, the list clears. Every session begins at zero.
SlidingWindow keeps only the most recent K messages and discards older content. The window slides forward. Conversations from yesterday are already gone. This approach does not solve memory. It accelerates forgetting by design.
Both options solve in-session state management. Cross-session persistence, entity resolution, semantic retrieval, and automatic compaction fall outside their scope. These are memory-layer problems, not framework-level concerns.
What Synap Adds
Synap is agentic context management. It does not replace Mastra's memory. It extends the framework with a persistence layer that survives restarts.
We ship three components that plug into Mastra's native interfaces:
SynapMiddleware implements Mastra's middleware interface. Attach it to any agent. The middleware captures every turn in the background and ingests it into Synap asynchronously. Your agent logic remains unchanged. Execution latency stays the same. The agent keeps working and starts remembering.
SynapHistory implements the memory backend interface. Use it as your memory store. Memory is scoped per user and per conversation. State survives restarts. Prior messages replay on the next session without manual setup.
SynapRetriever implements the retriever interface. Fetch user-scoped memories as standard memory objects. Two modes are available. Fast mode uses vector-only search and returns results in 50 to 100ms. Accurate mode adds graph traversal and reranking for 200 to 500ms latency.
The integration is a native TypeScript package. Drop it in, replace the memory backend, and your agent picks up persistent memory without a rewrite.
We built this because TypeScript agents kept stalling in production. The problem was not bad type safety. It was missing context that lived in a different session last Tuesday. Production testing hit 90.2% on LongMemEval. Fast mode retrieves in under 100ms.
For why context management is infrastructure and not a feature, read What Is Agentic Context Management? For build-versus-buy numbers, see The Real Cost of DIY Agent Memory.
Technical Deep Dive
LongMemEval Benchmark
LongMemEval tests whether agents recall facts across long, multi-turn conversations spanning multiple sessions. The benchmark simulates production conditions where users return days apart and expect the agent to remember prior context. Synap scores 90.2% on this benchmark. Baseline vector-only approaches typically score 60-70%. The gap comes from entity resolution and temporal awareness that pure vector search lacks.
Entity Resolution Mechanism
Synap tracks identity across 15 reference patterns: names, emails, phone numbers, account IDs, session IDs, API keys, and more. When an agent encounters "John" in one session and "[email protected]" in another, the resolution engine runs deterministic matching on structured fields, then probabilistic matching on unstructured references. Conflicts are resolved using temporal recency and source confidence scores. The result is a single canonical entity that accumulates context across all identifiers.
Accuracy-Preserving Compaction
Compaction identifies which facts are critical versus redundant. Critical facts include user preferences, constraints, commitments, and entity relationships. Redundant facts include repeated greetings, acknowledged statements, and intermediate reasoning steps. The compaction engine uses a classifier trained on conversation data to distinguish these categories. Most teams see 60 to 70% fewer tokens shipped to the LLM per turn after compaction kicks in. The accuracy preservation comes from never dropping classified-critical facts, even under aggressive token budgets.
Graph Traversal in Accurate Mode
Fast mode retrieves by vector similarity alone. Accurate mode adds a graph layer that traverses relationships between entities. If you ask about "the project John mentioned," the graph finds John, traverses to projects linked to John, and returns the relevant context. This adds latency but catches connections that vector similarity misses. Reranking then scores results by recency, confidence, and query relevance.
Multi-Tenant Scoping
Memory is scoped by three keys: user_id identifies the person, conversation_id isolates individual sessions, and customer_id enables multi-tenant deployments. A SaaS deploying agents for multiple customers uses customer_id to ensure tenant A never sees tenant B's memory. This scoping is enforced at the storage layer, not just in application logic.
What Synap Adds to Mastra
Persistence
Mastra Native. In-process only. State clears on restart.
With Synap. Per-user memory survives across sessions and restarts.
Entity Resolution
Mastra Native. Raw identifiers. No linking across sessions.
With Synap. "John" and "[email protected]" resolve to one canonical entity across every session.
Compaction
Mastra Native. Manual summarization or no compaction. Lossy.
With Synap. Automatic and configurable. Accuracy-preserving compaction that does not drop critical facts.
Retrieval Latency
Mastra Native. Depends on setup.
With Synap. 50 to 100ms fast mode. 200 to 500ms accurate mode.
Long-Term Recall
Mastra Native. Not benchmarked for cross-session recall.
With Synap. 90.2% on LongMemEval.
Failure Handling
Mastra Native. Retrieval failures crash the run or return noise.
With Synap. Empty result and a logged error. Your agent keeps running.
User Scoping
Mastra Native. Run-scoped only.
With Synap. Built-in user_id, conversation_id, customer_id scoping out of the box.
What Production Teams Gain
Cross-session continuity. Your user chats on Monday, returns on Wednesday. SynapHistory replays prior context. SynapRetriever surfaces relevant facts from last week. The agent treats every session as one continuous conversation. Native memory treats every session as a fresh start.
Accuracy that ships. 90.2% on LongMemEval measures whether agents recall facts across long, multi-turn conversations spanning multiple sessions.
Token efficiency. Synap's compaction trims conversation history without dropping critical context. Most teams see 60 to 70% fewer tokens shipped to the LLM per turn. At scale, that is the difference between profit and burn.
Latency that does not block. Fast retrieval: 50 to 100ms. Accurate mode with graph traversal and reranking: 200 to 500ms. Both degrade without crashing. A failure returns empty results and a log line, not a broken agent.
Entity resolution. "John from Acme," "[email protected]," and "user_4829" resolve to one person across every session. Synap handles this at the memory layer so your agent does not have to.
Production resilience. The middleware captures turns in the background without adding latency. The retriever returns empty results on failure instead of crashing. The history replays prior messages per session. All three components implement standard Mastra interfaces. No wrappers. No adapters.
How to Get Started
Setup
Install the package alongside Mastra:
npm install @maximem/synap-mastra @maximem/synap @mastra/core zod
Configure your API key. Generate one from the Synap Dashboard.
.env
SYNAP_API_KEY=synap_your_key_here
OPENAI_API_KEY=your-openai-api-key
Initialize the SDK once at application startup:
import { MaximemSynapSDK } from "@maximem/synap";
const sdk = new MaximemSynapSDK(); await sdk.initialize();
See SDK Initialization for the full lifecycle and configuration options.
Basic integration The smallest useful integration plugsSynapMemoryinto anAgent. Everygeneratecall automatically pulls relevant memories into the prompt and writes the new turn back out:
import { Agent } from "@mastra/core"; import { openai } from "@ai-sdk/openai"; import { SynapMemory } from "@maximem/synap-mastra";const agent = new Agent({ name: "MemoryAgent", instructions: "You are an agent with persistent memory.", model: openai("gpt-4o"),
memory: new SynapMemory({ sdk, userId: "alice", customerId: "acme", // optional — required for B2B instances }), });
const result = await agent.generate("What do you remember about my project deadlines?"); console.log(result.text);
The scoping triple is bound whenSynapMemoryis constructed — the model never sees the user identity.Memory reads degrade gracefully(empty context on failure); writes raise so silent data loss is impossible.To let the model decidewhento recall or store (rather than running on every turn), use the tools below.
Memory Is Infrastructure
Mastra gave TypeScript developers a native framework for building agents. Real value. The memory layer it ships handles in-session state well. Making that state persist across sessions, resolve entities, and retrieve intelligently is a different problem.
The teams that ship production agents discover this around month three. They either build memory infrastructure themselves, or they plug in a system built for the problem.
This is why memory is infrastructure, not a feature.
Start building Mastra agents that remember across sessions → (https://synap.maximem.ai)
Synap pricing is usage-based. You pay for memory operations: storage, retrieval, compaction. No per-seat or per-framework surcharge. Starter plan: $49/month. Every new account gets $25 in free credits to test before committing. See full pricing at https://synap.maximem.ai/pricing.
Related Posts
- What Is Agentic Context Management?



