Skip to content

Vercel AI SDK

Give generateText / streamText long-term memory: let the model save and recall facts as tools, or inject recalled memories into the prompt yourself.

Install

bash
npm install @suprflo/ai-sdk ai zod

ai and zod are peer dependencies — you bring your own versions. Targets AI SDK v5; v4 is not supported (it used parameters where v5 uses inputSchema).

What you get

Built on the JavaScript SDK client:

  • suprfloMemoryTools(client, options)saveMemory and searchMemory tools to spread into the tools option, so the model decides when to persist and recall.
  • recallMemories(client, query, options) — search Suprflo directly.
  • withMemories(client, messages, options) — prepend a system message of recalled memories, keyed off the last user message. Returns messages unchanged when nothing relevant is stored.

Memory as tools

ts
import { generateText } from 'ai'
import { MemoryClient } from '@suprflo/sdk'
import { suprfloMemoryTools } from '@suprflo/ai-sdk'

const client = new MemoryClient({ apiKey: process.env.SUPRFLO_API_KEY })

const { text } = await generateText({
  model: openai('gpt-4o'),
  prompt: 'Remember that I am vegetarian.',
  tools: suprfloMemoryTools(client, { userId: 'alice' }),
})

Recall into the prompt

When you want recall on every turn rather than at the model's discretion:

ts
import { withMemories } from '@suprflo/ai-sdk'

const { text } = await generateText({
  model: openai('gpt-4o'),
  messages: await withMemories(client, messages, { userId: 'alice', topK: 5 }),
})

The two compose: use withMemories for reliable recall and suprfloMemoryTools for model-driven writes.

Notes

npx tsc --noEmit passes against the real ai package, so the tool and message shapes are checked against the actual v5 types rather than assumed.

The memory layer for AI agents.