Integration

Long-term memory for the Vercel AI SDK

The Vercel AI SDK's `streamText`, `generateText`, and `streamObject` loops are stateless: every request rebuilds the message history from scratch. `@lumetra/engram-vercel-ai` ships six AI-SDK tool definitions through a `createEngramTools({...})` factory. Pass them to the model and the agent stores and recalls on its own, with citations in the response.

Install

Three steps: sign up for an Engram API key, paste a BYOK LLM-provider key on /models, then drop the snippet below into Vercel AI SDK.

Three steps to memory in your agent

  1. Sign up. Free, no card. You'll land on a Getting Started page that walks the next two steps.
  2. Add your LLM key. Engram is BYOK. Paste an OpenAI / Anthropic / Groq / Together / Fireworks key and we'll route every extraction and query call through your provider. You pay your provider directly. We never see your inference.
  3. Paste the snippet below into your agent and restart it. Use Authorization: Bearer <api-key>with the API key from your portal.

@lumetra/engram-vercel-ai: first-party AI-SDK adapter

Six tool definitions via createEngramTools({...}). Pass into any streamText / generateText / streamObject call. Source: github.com/lumetra-io/engram-vercel-ai · npm: @lumetra/engram-vercel-ai. Full walkthrough: Engram + Vercel AI SDK.

  1. Install (peer deps: ai ≥ 4 and zod):
  2. Terminal
    npm install @lumetra/engram-vercel-ai ai zod
  3. Set ENGRAM_API_KEY in .env.local (server-side env; never NEXT_PUBLIC_*).
  4. Wire the tools into your route handler:
  5. server-side TypeScript
    import { openai } from "@ai-sdk/openai";
    import { streamText } from "ai";
    import { createEngramTools } from "@lumetra/engram-vercel-ai";
    
    const result = streamText({
      model: openai("gpt-4o"),
      tools: createEngramTools({
        // apiKey: read from process.env.ENGRAM_API_KEY
        bucket: "alice",          // optional default bucket
      }),
      prompt: "Remember that my favorite color is blue, then tell me what you know about my preferences.",
    });
    
    for await (const chunk of result.textStream) {
      process.stdout.write(chunk);
    }
  6. Six tools wired: storeMemory, queryMemory, listBuckets, listMemories, deleteMemory, clearMemories. Subset by destructuring the factory return if you want a chat-only agent that can't delete.

What you can do once memory's wired in

  • Add `createEngramTools({ bucket: 'alice' })` to a `streamText` call and get six tools ready to go
  • Subset to just `storeMemory` and `queryMemory` for a chat-only agent that shouldn't be allowed to delete
  • Set per-user buckets via `createEngramTools({ bucket: `user-${userId}` })` on every request
  • Stream answers backed by memory so the SDK's streaming UI updates as Engram retrieves and synthesizes

FAQ

Does this work with `streamText`, `generateText`, AND `streamObject`?

All three. The tool definitions are SDK-wide; pass them via `tools: ...` to any of them.

Server-side only?

Yes. `ENGRAM_API_KEY` lives in `.env.local` and the tool's `execute` runs on the server. Never expose the key to the browser, and never put it in `NEXT_PUBLIC_*`.

Can I omit the `bucket` param when calling tools?

Only if you set a default. Pass `bucket: 'my-bucket'` to `createEngramTools(...)` and the model can omit it on individual tool calls. With no default, the model must supply `bucket` explicitly.

Ship durable memory in Vercel AI SDK today

Free tier: 10K memories and 50K retrievals per month. No credit card. Same Engram backend powers all 41 integrations, so memories you write from one client are immediately queryable from the rest.