mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-17 12:20:04 +00:00
Some checks failed
Publish Tools / publish (push) Has been cancelled
- Published the v2.0.0 docs and a 1.4 → 2.0 migration guide so existing users have a clear upgrade path. - Updated the four integration pages (AI SDK, OpenAI, Mastra, VoltAgent) to reflect v2 defaults and link to the migration guide. - Added a short explainer on the two required fields (containerTag, customId) so new users aren't blocked at first integration.
93 lines
2.7 KiB
Text
93 lines
2.7 KiB
Text
---
|
|
title: "AI SDK Integration"
|
|
description: "Use Supermemory with Vercel AI SDK for seamless memory management"
|
|
sidebarTitle: "Overview"
|
|
---
|
|
|
|
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.
|
|
|
|
<Card title="Supermemory tools on npm" icon="npm" href="https://www.npmjs.com/package/@supermemory/tools">
|
|
Check out the NPM page for more details
|
|
</Card>
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
npm install @supermemory/tools
|
|
```
|
|
|
|
## User Profiles with Middleware
|
|
|
|
Automatically inject user profiles into every LLM call for instant personalization. Customize how memories are formatted with the `promptTemplate` option for XML-based prompting, custom branding, or model-specific formatting.
|
|
|
|
```typescript
|
|
import { generateText } from "ai"
|
|
import { withSupermemory } from "@supermemory/tools/ai-sdk"
|
|
import { openai } from "@ai-sdk/openai"
|
|
|
|
// Wrap your model with Supermemory - profiles are automatically injected
|
|
const modelWithMemory = withSupermemory(openai("gpt-5"), {
|
|
containerTag: "user-123",
|
|
customId: "conversation-456",
|
|
})
|
|
|
|
const result = await generateText({
|
|
model: modelWithMemory,
|
|
messages: [{ role: "user", content: "What do you know about me?" }]
|
|
})
|
|
// The model automatically has the user's profile context!
|
|
```
|
|
|
|
<Note>
|
|
**Memory saving is enabled by default** (`addMemory: "always"`). New conversations are persisted automatically. To opt out, set `addMemory: "never"`:
|
|
|
|
```typescript
|
|
const modelWithMemory = withSupermemory(openai("gpt-5"), {
|
|
containerTag: "user-123",
|
|
customId: "conversation-456",
|
|
addMemory: "never",
|
|
})
|
|
```
|
|
</Note>
|
|
|
|
```typescript
|
|
```
|
|
|
|
## Memory Tools
|
|
|
|
Add memory capabilities to AI agents with search, add, and fetch operations.
|
|
|
|
```typescript
|
|
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")
|
|
})
|
|
```
|
|
|
|
## When to Use
|
|
|
|
| Approach | Use Case |
|
|
|----------|----------|
|
|
| User Profiles | Personalized LLM responses with automatic user context |
|
|
| Memory Tools | AI agents that need explicit memory control |
|
|
|
|
## Next Steps
|
|
|
|
<CardGroup cols={2}>
|
|
<Card title="User Profiles" icon="user" href="/integrations/ai-sdk">
|
|
Automatic personalization with profiles
|
|
</Card>
|
|
|
|
<Card title="Memory Tools" icon="wrench" href="/integrations/ai-sdk">
|
|
Agent-based memory management
|
|
</Card>
|
|
</CardGroup>
|