Adapters
Vercel AI SDK
Use MemexAI memory tools with the Vercel AI SDK in TypeScript.
The Vercel AI SDK adapter wires MemexAI memory tools into any generateText, streamText, or generateObject call.
Before you start
- Choose service mode or direct Postgres mode.
- Read How MemexAI works for the tool-call-to-Postgres flow.
- Read Memory tools to choose memory subagent or raw file tools.
- Read Memory scopes before writing paths like
user/profile.md.
Setup
Use @memexai/sdk when connecting to the containerized MemexAI service.
npm install @memexai/sdk aiimport { MemexAI } from '@memexai/sdk'
import { generateText, stepCountIs } from 'ai'
import { createGoogleGenerativeAI } from '@ai-sdk/google'
const memex = new MemexAI({ url: 'http://localhost:8080', apiKey: process.env.MEMEX_API_KEY! })
const memory = memex.forUser({ userId: 'user_123', actor: 'assistant' })
const system = await memory.getSystemPrompt('You are a helpful assistant with durable user memory.')
const result = await generateText({
model: createGoogleGenerativeAI()('gemini-2.5-flash'),
system,
prompt: 'Remember that I prefer quiet neighborhoods near good schools.',
tools: memory.createMemorySubagentToolset(),
stopWhen: stepCountIs(5),
})
console.log(result.text)The instance method memory.createMemorySubagentToolset() returns Vercel AI-compatible tools directly. Pair it with memory.getSystemPrompt(...) so stored memory can influence the next response.
Explicit adapter import
The named export is available if you prefer to import it directly.
import { createVercelAITools } from '@memexai/sdk/adapters/vercel-ai'
// or for direct mode:
import { createVercelAITools } from '@memexai/core/adapters/vercel-ai'
const memorySubagentTools = createVercelAITools(memory)
const rawTools = createVercelAITools(memory, { mode: 'raw' })Raw file toolset
Pass { mode: 'raw' } to expose the full file-level tool set instead of the memory subagent tools.
tools: memory.createRawToolset()
// memory_list, memory_read, memory_write, memory_patch, memory_findUse raw file tools when your agent or workflow should control exactly what gets written.
Examples
Working examples with hot path and background path patterns:
- Service mode (hot + background) —
@memexai/sdk+ Vercel AI SDK - Direct Postgres mode (hot + background) —
@memexai/core+ Vercel AI SDK