generateText or streamText call with Honcho’s memory middleware and reasoning tools.
The full package source and examples are available on GitHub.
What We’re Building
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.
Setup
Install the package:Use the Skill
The package ships a Skill that can walk an agent through wiring Honcho into your Vercel AI SDK app automatically — it greps for yourgenerateText / streamText call sites, asks where userId / sessionId come from, and applies the integration in place.
/honcho-vercel-ai-sdk.
Alternative: manual symlink from npm package
Alternative: manual symlink from npm package
If you’ve already installed Restart the session, then invoke
@honcho-ai/vercel-ai-sdk via npm, you can symlink the skill directly. Example shown is for Claude Code:/honcho-vercel-ai-sdk.Create a Provider Instance
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().
defaultAssistantId on the provider to identify the AI peer across all calls:
Add Middleware
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
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.
Add Tools
honcho.tools() gives the model six tools it can call mid-generation to query or update what it knows about the user:
| Tool | What it does |
|---|---|
honcho_chat | Dialectic reasoning — ask natural-language questions about the user; answers synthesized from full interaction history |
honcho_context | Short summary of recent context within the session |
honcho_search | Semantic search over stored conversation messages |
honcho_search_conclusions | Query derived conclusions: personality traits, preferences, behavioral patterns |
honcho_get_representation | Full synthesized profile of the user |
honcho_save_conclusion | Persist an observation about the user for future sessions |
userId and sessionId to honcho.tools() so tool calls bind to the same peers as the middleware:
Complete Example
Here’s a full working example combining middleware and tools. Want a runnable end-to-end version? See the Full Script.Streaming
streamText works the same way — middleware handles persistence after the stream completes:
Using with messages
If your app already manages conversation history and passes a messages array directly, set injectHistory: false to prevent Honcho from prepending duplicate history:
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.
Verifying the Integration
1. Isolate Honcho’s Contribution
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 withinjectHistory: false and once without.
Compare result.usage.inputTokens:
2. First turn
Send any message. The model responds normally — nothing is stored yet. Context injection returns empty on the first turn.3. Build memory across turns
Have a multi-turn conversation and share something about yourself:4. Cross-session recall
Start a new session (newsessionId) with the same userId. Ask:
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:
result.toolCalls is empty — check inside each step.
Full Script
honcho_vercel_chat.ts
honcho_vercel_chat.ts
Next Steps
Github Repository
Source, tests, and full API reference for @honcho-ai/vercel-ai-sdk.
Honcho Architecture
Learn about peers, sessions, and dialectic reasoning.
Self-Hosting Guide
Run Honcho locally with your Vercel AI SDK app.
Vercel AI SDK Docs
wrapLanguageModel, middleware, and tool use reference.