supermemory·Guides

How do I add persistent memory to a Vercel AI SDK app?

Reviewed Docs for this setup

The AI SDK keeps nothing between requests. Its persistence guide saves the chat in the onEnd callback of toUIMessageStream to your own database, which gives you chat history, not memory: the model still cannot recall last month's conversation unless you put it in the prompt. @supermemory/tools adds memory in one line. withSupermemory() wraps any AI SDK model so each call is sent with the user's profile and relevant memories, and the conversation is saved after it. supermemoryTools() gives an agent seven memory tools instead. Mem0 and Zep publish packages that do the equivalent for their platforms. Storing embeddings yourself in pgvector is the do-it-yourself route.

What does the AI SDK persist on its own?

Nothing. useChat holds messages in the browser for the life of the page, and on the server each generateText or streamText call sees only the messages you pass it. The SDK's chatbot persistence guide shows the pattern: save the messages in the onEnd callback of toUIMessageStream to a database you run, and load them by chat ID on the next request. That is history for one chat. What the user told you in another chat, or last month, is not there, and sending every past message would blow the context window. The SDK's own memory page says the same and lists the providers that plug in, supermemory among them.

How do I add memory with one line?

withSupermemory is AI SDK middleware. It wraps a model; on every call it fetches the namespace's profile (and, in query or full mode, memories relevant to the latest message), prepends them to the system prompt, and after the call saves the conversation to the namespace. Both namespace (whose memory: a user, workspace or tenant ID) and id (the conversation) are required.

npm install @supermemory/tools
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { withSupermemory } from "@supermemory/tools/ai-sdk";

const model = withSupermemory(openai("gpt-5"), {
  namespace: "user-123",
  id: "conversation-456",
  mode: "full", // "profile" (default), "query" or "full"
});

const { text } = await generateText({
  model,
  messages: [{ role: "user", content: "What do you know about me?" }],
});
  • Modes. profile sends the user's profile; query sends memories matching the message; full sends both.
  • Saving is on by default (addMemory: "always"); set "never" to read only.
  • Failures. If supermemory cannot be reached the call continues without memories by default.
  • It works with streamText and any provider the AI SDK supports, and it reads SUPERMEMORY_API_KEY from the environment.

How do I give an agent memory tools instead?

When the model should decide what to remember and when to look things up, pass supermemoryTools(). It returns seven tools: searchMemories, addMemory, getProfile, documentList, documentAdd, documentDelete and memoryForget. Individual tools are exported too, each taking a namespace.

import { streamText } from "ai";
import { anthropic } from "@ai-sdk/anthropic";
import { supermemoryTools } from "@supermemory/tools/ai-sdk";

const result = streamText({
  model: anthropic("claude-sonnet-5-5"),
  messages,
  tools: supermemoryTools(process.env.SUPERMEMORY_API_KEY!, { namespace: "user-123" }),
});

What about serverless and edge functions?

Both of the above are plain HTTP calls and run anywhere the AI SDK runs, including Vercel Functions and the edge runtime. There is a third shape for agents that like a filesystem: @supermemory/bash exposes a supermemory container as a single run_bash tool, so the agent can ls, cat and grep its memory, with the commands proxied over HTTP and nothing mounted. The SMFS page for the AI SDK shows it.

Which options exist?

OptionWhat you getExtracts and updates factsUser profileCode
onEnd + your databaseHistory for one chat, reloaded by IDNoNoYou write it; the SDK guide shows it
withSupermemory middlewareProfile and relevant memories in every call; conversation saved afterYesYesOne wrapper
supermemoryToolsSeven memory and document tools the agent callsYesYes, getProfileOne tools object
@supermemory/bashMemory as a filesystem the agent runs shell commands onYesVia filesOne tool
@mem0/vercel-ai-providerMem0 memories added to calls through a provider wrapper (AI SDK 6)YesMem0's user memoriesOne wrapper
@getzep/zep-vercel-aiZep graph memory for AI SDK 6 appsYesFacts from the graphOne package
pgvector or Pinecone yourselfEmbeddings of what you choose to storeNo, you write itNoEmbedding, storage and retrieval code

Questions

Does the Vercel AI SDK have built-in memory?

No. It persists nothing between requests; the official guide saves the chat in the onEnd callback of toUIMessageStream to your own database, which gives chat history only, and its memory page points to providers such as supermemory for the rest.

Does withSupermemory work with streamText and useChat?

Yes. It wraps the model, so anything that takes a model works, including streamText behind a useChat route.

Which models and providers does it support?

Any provider the AI SDK supports: OpenAI, Anthropic, Google and the rest. The wrapper is provider-agnostic.

Does it run on the edge runtime?

Yes. It is HTTP calls to api.supermemory.ai, with no native dependencies.

Can I read memories without saving new ones?

Yes. Set addMemory: "never" on the middleware, or pass only the search and profile tools.

supermemory facts from the AI SDK and SMFS pages in the supermemory docs and the @supermemory/tools README on npm (3.1.3). AI SDK persistence and its memory page from ai-sdk.dev. Mem0's and Zep's packages from npm and their docs. Checked November 10, 2026. The setup steps restate the docs page for this integration; when the two differ, the docs are current.

YOUR PRIVACY

Change or withdraw any time via Cookie settings in the footer. Read our cookie notice.