Vercel AI SDK

Rekall memory plus durable session state for the Vercel AI SDK. The @rekall/vercel-ai package recalls relevant context into your prompts, captures what the model produces, and persists conversation state across runs.

Overview

The Vercel AI SDK has no built-in long-term memory. RekallMemory adds it on three surfaces: recall into the system prompt, capture via the SDK's onStepFinish / onFinish callbacks, and durable persistence of response.messages across runs. Capture callbacks never throw, so memory can't break generation.

Installation

Terminal
npm install @rekall/vercel-ai

Usage

Build a memory-augmented system prompt with systemWithMemory, wire the capture callback into generateText, and persist the resulting messages:

route.ts
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { RekallMemory } from '@rekall/vercel-ai';
const mem = new RekallMemory({
apiUrl: 'https://api.rekall.app', // or http://localhost:9876 in dev
apiKey: process.env.REKALL_API_KEY, // rk_… key, or accessToken: 'rat_…'
});
const system = await mem.systemWithMemory('You are a helpful assistant.', userPrompt);
const res = await generateText({
model: openai('gpt-4o'),
system,
prompt: userPrompt,
onStepFinish: mem.onStepFinish(), // capture assistant text + tool results
});
await mem.saveSession('thread-1', res.response.messages); // durable history
const prior = await mem.loadSession('thread-1');

Works with streamText too

Use mem.onFinish() with streamText for the streaming case — the capture callbacks share the same shape.

API

MethodWhat it doesRekall endpoint
remember(content, { metadata })store a memoryPOST /api/v2/memories
recall(query, { limit })semantic search → { content, score }[]POST /api/v2/memories/search
contextFor / systemWithMemoryrecalled memory for the system promptsearch
onStepFinish() / onFinish()capture callbacks for generateText/streamText
saveSession(key, state) / loadSession(key)durable session historyexecution-memory /external

Why

This adds long-term memory to the Vercel AI SDK — recall into the system prompt, capture via the SDK's callbacks, and persist response.messages across runs — while sharing the same Rekall store as your LangGraph, CrewAI, and Claude agents.

Authentication

Pass apiKey / accessToken (sent as Bearer), or headers: { 'x-user-id': '…' } for local dev against a header-auth server.

Next Steps

Rekall
rekall