Build an AI assistant that remembers user preferences and past interactions:
import { streamText } from 'ai'import { createAnthropic } from '@ai-sdk/anthropic'import { supermemoryTools } from '@supermemory/tools/ai-sdk'const anthropic = createAnthropic({ apiKey: process.env.ANTHROPIC_API_KEY!})export async function POST(request: Request) { const { messages } = await request.json() const result = await streamText({ model: anthropic('claude-3-sonnet-20240229'), messages, tools: supermemoryTools(process.env.SUPERMEMORY_API_KEY!), system: `You are a helpful personal assistant. When users share information about themselves, remember it using the addMemory tool. When they ask questions, search your memories to provide personalized responses. Always be proactive about remembering important details.` }) return result.toAIStreamResponse()}
Example conversation:
User: “I’m allergic to peanuts and I love Italian food”
AI: Uses addMemory tool “I’ve remembered that you’re allergic to peanuts and love Italian food!”
User: “Suggest a restaurant for dinner”
AI: Uses searchMemories tool “Based on what I know about you, I’d recommend an Italian restaurant that’s peanut-free…”
Build a customer support system that remembers customer history:
import { streamText } from 'ai'import { createOpenAI } from '@ai-sdk/openai'import { supermemoryTools } from '@supermemory/tools/ai-sdk'const openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY!})export async function POST(request: Request) { const { messages, customerId } = await request.json() const result = await streamText({ model: openai('gpt-5'), messages, tools: supermemoryTools(process.env.SUPERMEMORY_API_KEY!, { containerTags: [customerId] }), system: `You are a customer support agent. Before responding to any query: 1. Search for the customer's previous interactions and issues 2. Remember any new information shared in this conversation 3. Provide personalized help based on their history 4. Always be empathetic and solution-focused` }) return result.toAIStreamResponse()}
Build an assistant that learns from multiple users but keeps data separate:
import { streamText } from 'ai'import { createAnthropic } from '@ai-sdk/anthropic'import { supermemoryTools } from '@supermemory/tools/ai-sdk'const anthropic = createAnthropic({ apiKey: process.env.ANTHROPIC_API_KEY!})export async function POST(request: Request) { const { messages, userId, courseId } = await request.json() const result = await streamText({ model: anthropic('claude-3-haiku-20240307'), messages, tools: supermemoryTools(process.env.SUPERMEMORY_API_KEY!, { containerTags: [userId] }), system: `You are a learning assistant. Help students with their coursework by: 1. Remembering their learning progress and struggles 2. Searching for relevant information from their past sessions 3. Providing personalized explanations based on their learning style 4. Tracking topics they've mastered vs topics they need more help with` }) return result.toAIStreamResponse()}
Combine file upload with memory tools for research assistance:
import { streamText } from 'ai'import { createOpenAI } from '@ai-sdk/openai'import { supermemoryTools } from '@supermemory/tools/ai-sdk'const openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY!})export async function POST(request: Request) { const { messages, projectId } = await request.json() const result = await streamText({ model: openai('gpt-5'), messages, tools: supermemoryTools(process.env.SUPERMEMORY_API_KEY!, { containerTags: [projectId] }), system: `You are a research assistant. You can: 1. Search through uploaded research papers and documents 2. Remember key findings and insights from conversations 3. Help synthesize information across multiple sources 4. Track research progress and important discoveries` }) return result.toAIStreamResponse()}