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 zodai 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)—saveMemoryandsearchMemorytools to spread into thetoolsoption, 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. Returnsmessagesunchanged 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.