@unisonlabs/ai-sdk
v0.1.1
Published
Long-term memory for the Vercel AI SDK, powered by the Unison brain
Maintainers
Readme
@unisonlabs/ai-sdk
Long-term memory for the Vercel AI SDK, powered by the Unison brain.
Install • Quick start • Options • Low-level client • For agents
🤖 Reading this as an AI agent? See
AGENTS.md— install, auth, andwrapLanguageModelusage in one page.
Before each model call, the middleware recalls relevant memories from your Unison brain and injects them into the system prompt. After the call, the user/assistant turn is persisted back so future calls can reference it — giving any LLM durable, cross-session memory with zero boilerplate.
Install
npm i @unisonlabs/ai-sdk aiQuick start
import { openai } from '@ai-sdk/openai';
import { generateText, wrapLanguageModel } from 'ai';
import { unisonMemory } from '@unisonlabs/ai-sdk';
const model = wrapLanguageModel({
model: openai('gpt-4o'),
middleware: unisonMemory({ sessionId: 'user-123' }),
});
const { text } = await generateText({
model,
prompt: 'What projects am I currently working on?',
});
console.log(text);The middleware automatically:
- Calls
GET /v1/brain/contextwith the user's latest message before generating. - Prepends the recalled
contextMdto the system prompt (skipped whenweakEvidenceis true). - POSTs the user + assistant turn to
POST /v1/brain/ingestafter generating (fire-and-forget).
Options
| Option | Type | Default | Description |
|---|---|---|---|
| sessionId | string | — | Required. Used as sourceRef for ingested conversations. |
| token | string | UNISON_TOKEN env var | Your Unison API token (usk_live_...). |
| apiUrl | string | UNISON_API_URL or https://brain.unisonlabs.ai | Unison brain base URL. |
| k | number | 5 | Number of memory hits to retrieve. |
| recall | boolean | true | Set to false to skip the recall step. |
| persist | boolean | true | Set to false to skip the persist step. |
Environment variables
| Variable | Description |
|---|---|
| UNISON_TOKEN | Unison API token. Overridden by options.token. |
| UNISON_API_URL | Unison brain base URL. Overridden by options.apiUrl. |
Low-level client
import { recall, ingestConversation } from '@unisonlabs/ai-sdk';
const result = await recall({
apiUrl: 'https://brain.unisonlabs.ai',
token: process.env.UNISON_TOKEN!,
q: 'What are my ongoing projects?',
k: 5,
});
if (!result.weakEvidence) {
console.log(result.contextMd);
}
await ingestConversation({
apiUrl: 'https://brain.unisonlabs.ai',
token: process.env.UNISON_TOKEN!,
sessionId: 'user-123',
turns: [
{ role: 'user', content: 'Hello' },
{ role: 'assistant', content: 'Hi! How can I help?' },
],
});Agents
See AGENTS.md for the full agent onboarding guide: install, auth, wrapLanguageModel usage, env vars, and contributor commands.
Releasing
Run npm login once to authenticate, then:
bun run releaseThat's it. The script builds the package, publishes @unisonlabs/ai-sdk to npm (idempotent — skips if the version is already published), and tags + pushes the release commit. Bump the version in package.json before running.
Links
License
MIT — see LICENSE.
Part of the Unison Labs constellation
One brain, every agent. Every repo below reads from and writes to the same Unison brain — no per-tool memory silos.
| Repo | What it does | |---|---| | unison-brain | CLI · SDK · MCP server — the core | | claude-unison | Memory for Claude Code | | cursor-unison | Memory for Cursor | | codex-unison | Memory for OpenAI Codex CLI | | opencode-unison | Memory for OpenCode | | openclaw-unison | Memory for OpenClaw | | pipecat-unison | Memory for Pipecat voice agents | | langchain-unison | LangChain memory, history & retriever | | llama-index-memory-unison | LlamaIndex memory provider | | unison-ai-sdk | Vercel AI SDK memory middleware ← you are here | | unison-mastra | Mastra agent memory provider | | python-sdk | Python SDK for the brain | | install-mcp | One-command MCP installer | | unison-fs | Mount the brain as a filesystem | | backchannel | Async messaging between agents | | Unison-evals | Open memory benchmark suite |
