Use this file to discover all available pages before exploring further.
Integrate Honcho with the Vercel AI SDK to build AI apps that remember users across sessions. The Vercel AI SDK is an open-source TypeScript toolkit for building AI-powered apps with a unified API across providers. This guide shows you how to wrap any generateText or streamText call with Honcho’s memory middleware and reasoning tools.
The full package source and examples are available on GitHub.
We’ll wire Honcho into a Vercel AI SDK app so the model receives context from past conversations and can query what it knows about the user mid-generation. Here’s how the pieces fit together:
Vercel AI SDK handles model calls and streaming
Honcho stores messages and retrieves user context before each generation
Your model provider can be Anthropic, OpenAI, Google, etc.
The key benefit: you don’t manually manage conversation history across sessions. Honcho handles persistence and context injection — the model always has a rich picture of who it’s talking to. (New to Honcho’s primitives? See peers and sessions.)
The package ships a Skill that can walk an agent through wiring Honcho into your Vercel AI SDK app automatically — it greps for your generateText / streamText call sites, asks where userId / sessionId come from, and applies the integration in place.
npx skills add plastic-labs/vercel-ai-sdk
Then invoke /honcho-vercel-ai-sdk.
Alternative: manual symlink from npm package
If you’ve already installed @honcho-ai/vercel-ai-sdk via npm, you can symlink the skill directly. Example shown is for Claude Code:
createHoncho() is the entry point. It reads your API key and workspace from environment variables and returns a provider object with middleware(), tools(), and send().
import { createHoncho } from '@honcho-ai/vercel-ai-sdk';const honcho = createHoncho();
You can set a stable defaultAssistantId on the provider to identify the AI peer across all calls:
honcho.middleware() is compatible with wrapLanguageModel. Two things happen on each call:
Before generation — Honcho fetches the user’s representation, peer card, session summary, and recent messages and injects them into the system prompt
After generation — the user message and assistant response are stored back in Honcho with correct peer attribution
import { createHoncho } from '@honcho-ai/vercel-ai-sdk';import { wrapLanguageModel, generateText } from 'ai';import { anthropic } from '@ai-sdk/anthropic';const honcho = createHoncho();const model = wrapLanguageModel({ model: anthropic('claude-sonnet-4-6'), middleware: honcho.middleware({ userId: 'user-abc', sessionId: 'session-123', }),});const { text } = await generateText({ model, prompt: 'What should I focus on today?',});
Pass userId and sessionId per request — no session handles to construct. Both default to lazily generated IDs if omitted, which is fine for local scripts but not for multi-user server traffic.
Persist an observation about the user for future sessions
Pass the same userId and sessionId to honcho.tools() so tool calls bind to the same peers as the middleware:
import { generateText, stepCountIs } from 'ai';const { text } = await generateText({ model, tools: honcho.tools({ userId: 'user-abc', sessionId: 'session-123', }), stopWhen: stepCountIs(3), prompt: 'Based on our conversations, what do I care about most?',});
If your app already manages conversation history and passes a messages array directly, set injectHistory: false to prevent Honcho from prepending duplicate history:
Honcho still injects the user’s representation and peer card into the system prompt, and still persists messages after generation. With injectHistory: false you must pass a messages array — without either messages or prompt, the Vercel AI SDK throws Invalid prompt: prompt or messages must be defined.
Let’s confirm the memory is actually coming from Honcho and not your app’s existing conversation history.Two ways to check: 1) through a developer method 2) through the UI.Token delta (developer check). On a session with a few prior turns, run the same prompt twice — once with injectHistory: false and once without.Compare result.usage.inputTokens:
const baseline = await generateText({ model: wrapLanguageModel({ model: anthropic('claude-sonnet-4-6'), middleware: honcho.middleware({ userId, sessionId, injectHistory: false }), }), prompt: 'What do you know about my preferences?',});const injected = await generateText({ model: wrapLanguageModel({ model: anthropic('claude-sonnet-4-6'), middleware: honcho.middleware({ userId, sessionId }), }), prompt: 'What do you know about my preferences?',});console.log(injected.usage.inputTokens - baseline.usage.inputTokens);
A positive delta is Honcho’s representation, peer card, and session summary being injected into the system prompt. Expect ~0 on a fresh peer — the deriver runs asynchronously after messages persist, so injected context only populates after a few prior turns.Dashboard (UI check). Open app.honcho.dev/explore, select your workspace, and confirm your peer and session appear under the Peers and Sessions tables.With Honcho’s contribution isolated, the rest of this section shows what the integration feels like in practice.
Start a new session (new sessionId) with the same userId. Ask:
Call your honcho_search tool with the query 'TypeScript' and quote the exact verbatim message that contained TypeScript. Do not paraphrase.
If the search returns a message from the prior session word-for-word, peer-scoped retrieval is crossing session boundaries. honcho_search queries the user’s messages across all their sessions and doesn’t depend on the deriver, so it works regardless of how short the prior session was.To confirm the tool actually fired, inspect result.steps[i].toolCalls: