npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@agentmem/vercel-ai-provider

v0.2.0

Published

AgentMem integration for the Vercel AI SDK — middleware, tools, and helpers for any model

Downloads

52

Readme

@agentmem/vercel-ai-provider

Vercel AI SDK integration for AgentMem. Three ways to wire it in — use one or stack them.

npm install @agentmem/vercel-ai-provider ai

Pattern A — middleware (automatic memory injection)

Wrap any @ai-sdk/* model and memories appear in the system prompt on every call. Works the same for generateText, streamText, and generateObject — they all route through the model's doGenerate / doStream hook, which is where the middleware fires.

import { generateText, wrapLanguageModel } from 'ai'
import { anthropic } from '@ai-sdk/anthropic'
import { createAgentMemMiddleware, type LanguageModel } from '@agentmem/vercel-ai-provider'

const cfg = { apiKey: process.env.AGENTMEM_API_KEY!, agentId: 'support-bot' }

const baseModel: LanguageModel = anthropic('claude-opus-4-7')
const model = wrapLanguageModel({
  model:      baseModel,
  middleware: createAgentMemMiddleware(cfg),
})

const { text } = await generateText({ model, prompt: 'What did the customer prefer?' })

Note on LanguageModel. Import the type from this package, not from ai. The ai SDK's LanguageModel alias is a union (string | LanguageModelV3 | LanguageModelV2) for high-level helpers that accept a model id; that union doesn't satisfy wrapLanguageModel, which needs the object form only. This package re-exports the right shape.

Structured output (generateObject) works the same way

Wrap the model exactly as above and use generateObject directly — the middleware injects memory into the prompt before the model sees it, and the structured schema is preserved.

import { generateObject } from 'ai'
import { z } from 'zod'

const { object } = await generateObject({
  model,
  schema: z.object({ verdict: z.enum(['approve', 'reject']), reasoning: z.string() }),
  prompt: 'Should we approve this purchase request?',
})

If search fails, the middleware logs to stderr and lets the call proceed without memory — your model never gets blocked.

Pattern B — tools

import { generateText } from 'ai'
import { anthropic } from '@ai-sdk/anthropic'
import { agentmemMemorize, agentmemRecall } from '@agentmem/vercel-ai-provider'

await generateText({
  model:  anthropic('claude-opus-4-7'),
  tools:  {
    memorize: agentmemMemorize(cfg),
    recall:   agentmemRecall(cfg),
  },
  prompt: '...',
})

The agent decides when to call memorize / recall. Lower per-turn latency than the middleware on simple turns.

Pattern C — helpers (manual control)

Drop-in API replacement for @mem0/vercel-ai-provider — same function names.

import {
  addMemories,
  retrieveMemories,
  searchMemories,
} from '@agentmem/vercel-ai-provider'

await addMemories('User prefers email.', { apiKey, agentId: 'bot' })

const context = await retrieveMemories(userMessage, { apiKey, agentId: 'bot' })
// → "Relevant memories retrieved from AgentMem...\n- User prefers email."
//   Splice into your system prompt manually.

const hits = await searchMemories('what does the user prefer?', { apiKey, agentId: 'bot' })
// → MemoryHit[] for custom rendering

Why this beats @mem0/vercel-ai-provider

| | Mem0 provider | AgentMem provider | |---|---|---| | Wraps every model SDK | Yes (OpenAI, Anthropic, Cohere, Groq, Google) | No | | Works with any @ai-sdk/* provider | Only the 5 it wraps | All of them | | Runtime dependency count | 8+ | 1 (@agentmem/sdk) | | Provides middleware | No | Yes | | Helper API compatibility | — | Same names: addMemories / retrieveMemories / searchMemories |

Migration from Mem0: change the import path, set AGENTMEM_API_KEY instead of MEM0_API_KEY, and pass agentId in the config.

Config reference

| Field | Default | Purpose | |---|---|---| | apiKey | — | Required. | | agentId | — | Required (constructor OR per-call). | | baseUrl | hosted | Self-host override. | | scope | private | Visibility default. | | workflowId | — | Group memories under a workflow. | | topK | 5 | Max memories per recall. | | rerank | false | Re-score with Gemini (+0.5-1.5s). | | minScore | 0 | Drop hits below this score. | | prefix | default | Custom text before the memory block (middleware + retrieveMemories). |

License

Apache-2.0