npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

memorysync-mastra

v1.0.1

Published

MemorySync memory for Mastra agents: input/output processors for automatic recall and persistence, a zero-config agent wrapper, five agent memory tools, and helpers. Works on current @mastra/core.

Readme

memorysync-mastra

Long-term memory for Mastra agents, backed by MemorySync — on Mastra's native processor pipeline.

  • Processors — recalled context injected as a system message before each generate/stream call, the exchange persisted after it and distilled server-side into durable facts.
  • withMemorySync — zero-config wrapper that merges the processors into any agent config.
  • Five agent tools — add, search, list, update, delete; they never throw.
  • HelpersgetMemoryContext, searchMemories, saveTurn for hand-wired setups.
npm install memorysync-mastra @mastra/core

Set MEMORYSYNC_API_KEY in the environment (create a key at app.memorysync.io), or pass apiKey explicitly.

Processors — memory on the native pipeline

import { Agent } from "@mastra/core/agent";
import { openai } from "@ai-sdk/openai";
import { createMemorySyncProcessors } from "memorysync-mastra";

const { inputProcessor, outputProcessor } = createMemorySyncProcessors({
  userId: "customer-7",     // per-end-user scoping
  sessionId: "thread-42",   // groups the stored facts by thread
});

const agent = new Agent({
  id: "assistant",
  name: "Assistant",
  instructions: "You are a helpful assistant.",
  model: openai("gpt-4o-mini"),
  inputProcessors: [inputProcessor],
  outputProcessors: [outputProcessor],
});

// First conversation
await agent.generate("I'm vegetarian and I fly aisle.");

// Any later call — same user, any thread, any model
const { text } = await agent.generate("Book my trip: flight plus a dinner spot.");
// The model already saw: vegetarian, aisle seat — injected from memory.

Or wrap the config:

import { withMemorySync } from "memorysync-mastra";

const agent = new Agent(withMemorySync(
  { id: "assistant", name: "Assistant", instructions, model },
  { userId: "customer-7" },
));

Injection happens once per call — the processors use processInput, not the per-step hook, so multi-step tool loops never pay for the context block twice. Recall failing means the call proceeds without context; persistence failing is reported through onError and never thrown. A stream that dies mid-flight persists nothing (the failed run is detected via finishReason: "error" and skipped), so no half-turns are ever stored.

Who is the agent acting for?

Identity resolves per call from four sources, in priority order:

// 1. Your own resolver — wins over everything (multi-user servers).
createMemorySyncProcessors({
  resolveIdentity: (requestContext) => ({ userId: session.userId }),
});

// 2. Static ids — one agent per user (scripts, workers).
createMemorySyncProcessors({ userId: "customer-7" });

// 3. Mastra's RequestContext — set by server middleware.
import { RequestContext } from "@mastra/core/request-context";
import { MASTRA_RESOURCE_ID_KEY } from "memorysync-mastra";
const ctx = new RequestContext();
ctx.set(MASTRA_RESOURCE_ID_KEY, "customer-7");
await agent.generate(messages, { requestContext: ctx });

// 4. Mastra's own memory plumbing.
await agent.generate("...", { memory: { resource: "customer-7", thread: "t-1" } });

No resolved user means no write. If none of the sources yields a user id, recall is skipped and the persist is refused — reported through onError, never written to a default scope.

Recall modes and switches

createMemorySyncProcessors({ userId, mode: "query" });   // relevant to the latest message (default)
createMemorySyncProcessors({ userId, mode: "profile" }); // overview of the user: newest facts, listed (1.0.1; 1.0.0 searched with a generic prompt and injected nothing)
createMemorySyncProcessors({ userId, mode: "full" });    // both
createMemorySyncProcessors({ userId, persist: false });  // read-only
createMemorySyncProcessors({ userId, recall: false });   // write-only
createMemorySyncProcessors({ userId, k: 12, template: "What you know:\n{context}" });

Agent tools

import { createMemorySyncTools } from "memorysync-mastra";

const agent = new Agent({
  // ...
  tools: { ...createMemorySyncTools({ userId: "customer-7" }) },
});

// Untrusted agents: search + list only.
createMemorySyncTools({ userId: "customer-7", readOnly: true });

add_memory, search_memory, list_memories, update_memory, delete_memory — the same five operations, same response strings as the MemorySync LangChain, AI SDK and CrewAI tool sets. A memory failure can never abort the agent run: tools return short readable error strings instead of throwing, and add_memory derives a client ref from the content so a repeating agent gets "already stored", never a duplicate.

Helpers

import { getMemoryContext, saveTurn, searchMemories } from "memorysync-mastra";

// Prompt-ready context block ("" for a new user)
const context = await getMemoryContext("what should I cook?", { userId: "customer-7" });

// Scored raw results
const hits = await searchMemories("dietary preferences", { userId: "customer-7" });

// Explicit persistence — THROWS on failure (an explicit call is owed the
// truth), unlike the processors' reported-never-thrown discipline.
await saveTurn(
  { user: "I'm vegetarian", assistant: "Noted!", sessionId: "thread-42" },
  { userId: "customer-7" },
);

All surfaces share the same idempotency seeds, so mixing styles cannot double-store a turn.

Version support

| Package | Requires | Runtime | | --- | --- | --- | | memorysync-mastra 1.0.1 | @mastra/core >=1.42 <2 (peer) | Node 20+ (@mastra/core itself requires Node 22+) |

The CI suite drives a real @mastra/core Agent through the processors — hook timing, RequestContext keys, message shapes — on the pinned core and again on the latest 1.x release.

Documentation