Skip to main content
The Supermemory AI SDK provides native integration with Vercel’s AI SDK through two approaches: User Profiles for automatic personalization and Memory Tools for agent-based interactions.

@supermemory/tools on npm

Check out the NPM page for more details

Installation

npm install @supermemory/tools

Quick Comparison

ApproachUse CaseSetup
User ProfilesPersonalized LLM responses with automatic user contextSimple middleware
Memory ToolsAI agents that need explicit memory controlTool definitions

User Profiles with Middleware

Automatically inject user profiles into every LLM call for instant personalization.
import { generateText } from "ai"
import { withSupermemory } from "@supermemory/tools/ai-sdk"
import { openai } from "@ai-sdk/openai"

const modelWithMemory = withSupermemory(openai("gpt-5"), "user-123")

const result = await generateText({
  model: modelWithMemory,
  messages: [{ role: "user", content: "What do you know about me?" }]
})
Memory saving is disabled by default. The middleware only retrieves existing memories. To automatically save new memories:
const modelWithMemory = withSupermemory(openai("gpt-5"), "user-123", {
  addMemory: "always"
})

Memory Search Modes

Profile Mode (Default) - Retrieves the user’s complete profile:
const model = withSupermemory(openai("gpt-4"), "user-123", { mode: "profile" })
Query Mode - Searches memories based on the user’s message:
const model = withSupermemory(openai("gpt-4"), "user-123", { mode: "query" })
Full Mode - Combines profile AND query-based search:
const model = withSupermemory(openai("gpt-4"), "user-123", { mode: "full" })

Custom Prompt Templates

Customize how memories are formatted:
import { withSupermemory, type MemoryPromptData } from "@supermemory/tools/ai-sdk"

const claudePrompt = (data: MemoryPromptData) => `
<context>
  <user_profile>
    ${data.userMemories}
  </user_profile>
  <relevant_memories>
    ${data.generalSearchMemories}
  </relevant_memories>
</context>
`.trim()

const model = withSupermemory(anthropic("claude-3-sonnet"), "user-123", {
  mode: "full",
  promptTemplate: claudePrompt
})

Verbose Logging

const model = withSupermemory(openai("gpt-4"), "user-123", {
  verbose: true
})
// Console output shows memory retrieval details

Memory Tools

Add memory capabilities to AI agents with search, add, and fetch operations.
import { streamText } from "ai"
import { createAnthropic } from "@ai-sdk/anthropic"
import { supermemoryTools } from "@supermemory/tools/ai-sdk"

const anthropic = createAnthropic({ apiKey: "YOUR_ANTHROPIC_KEY" })

const result = await streamText({
  model: anthropic("claude-3-sonnet"),
  prompt: "Remember that my name is Alice",
  tools: supermemoryTools("YOUR_SUPERMEMORY_KEY")
})

Available Tools

Search Memories - Semantic search through user memories:
const result = await streamText({
  model: openai("gpt-5"),
  prompt: "What are my dietary preferences?",
  tools: supermemoryTools("API_KEY")
})
// AI will call: searchMemories({ informationToGet: "dietary preferences" })
Add Memory - Store new information:
const result = await streamText({
  model: anthropic("claude-3-sonnet"),
  prompt: "Remember that I'm allergic to peanuts",
  tools: supermemoryTools("API_KEY")
})
// AI will call: addMemory({ memory: "User is allergic to peanuts" })
Fetch Memory - Retrieve specific memory by ID:
const result = await streamText({
  model: openai("gpt-5"),
  prompt: "Get the details of memory abc123",
  tools: supermemoryTools("API_KEY")
})

Using Individual Tools

For more control, import tools separately:
import {
  searchMemoriesTool,
  addMemoryTool,
  fetchMemoryTool
} from "@supermemory/tools/ai-sdk"

const result = await streamText({
  model: openai("gpt-5"),
  prompt: "What do you know about me?",
  tools: {
    searchMemories: searchMemoriesTool("API_KEY", { projectId: "personal" }),
    createEvent: yourCustomTool,
  }
})

Tool Results

// searchMemories result
{ success: true, results: [...], count: 5 }

// addMemory result
{ success: true, memory: { id: "mem_123", ... } }

// fetchMemory result
{ success: true, memory: { id: "mem_123", content: "...", ... } }