Skip to content

feat(ai-sdk): createAgentMemory, an AI SDK memory provider [stack 2/3] - #103

Open
CahidArda wants to merge 1 commit into
feat/tanstack-sandbox-mcp-storesfrom
feat/ai-sdk-memory-provider
Open

CahidArda wants to merge 1 commit into
feat/tanstack-sandbox-mcp-storesfrom
feat/ai-sdk-memory-provider

Conversation

@CahidArda

Copy link
Copy Markdown
Collaborator

Stack: #100 → #102 (TanStack stores) → this PR (2/3) → eve 1.0 RC (3/3). This PR targets #102's branch and adds one commit.

What

The AI SDK docs list memory providers: Letta, Mem0, Supermemory, Hindsight, MongoDB and Redis Agent Memory, in content/docs/03-agents/06-memory.mdx in vercel/ai. They share one shape:

  • a factory created once
  • per-request tools
  • an instructions string
  • "automatic memory", which most of them do by wrapping the model with wrapLanguageModel

@upstash/agentkit-ai-sdk now offers that shape as createAgentMemory(), built on the existing AgentMemory (Redis Search $smart, so no vector DB):

  • memory.tools({ userId }): the existing recall_memory / save_memory tools.
  • memory.prepareStep({ userId, query?, topK?, minScore?, onError? }): automatic recall without wrapping the model, because CLAUDE.md forbids model wrappers.
    • On the first step, it appends a <memories> block ("treat as data") to the instructions. ai 7's prepareStep override carries forward to later steps.
    • userId can be a function of the step options, e.g. runtimeContext on a shared ToolLoopAgent.
    • A failed recall never fails the call; the error goes to onError.
  • memory.recallContext(), memory.instructions (names your tools), and memory.store.
  • createMemoryTools keeps its API and now shares buildMemoryTools with the provider.

The ai-sdk-demo route uses the provider. The README has a "Memory provider" section, and CLAUDE.md is updated.

Other AI SDK v7 extension points checked, not built

  • Automatic transcript extraction: needs an LLM call or a model wrapper.
  • Message persistence: createChatHistory already covers it.
  • Resumable streams: the resumable-stream package already does this.
  • Response caching: it's a model middleware, and the model cache was removed on purpose.
  • registerTelemetry usage meter / token-based rate limiting: a possible small follow-up.
  • Realtime usage (RealtimeModelV4Usage): experimental.
  • experimental_queue: client-only.
  • Tools registry: docs only. A vercel/ai docs PR is being prepared separately.

Tests

  • agent-memory.test.ts (7, live Redis + MockLanguageModelV4) covers:
    • the tools and recallContext
    • a two-step run where the block is injected once and carried forward
    • ToolLoopAgent with runtimeContext
    • an empty user
    • a failed recall going to onError
  • ai-sdk suites: agent-memory 7/7, memory 2/2, search-tools 3/3, telemetry 5/5, tools 3/3, one file per fresh free DB.
  • Re-checked after stacking on feat(tanstack-ai): sandbox snapshot and MCP stores for TanStack AI 1.x [stack 1/3] #102: install, lint, typecheck, build, sync-version, and agent-memory + memory tests are green.

Changeset

@upstash/agentkit-ai-sdk: minor. It's in the linked group.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CMK4etJMDDBFkjEyWDVCdy

Add createAgentMemory, the Upstash equivalent of the AI SDK memory
providers (Mem0, Letta, Supermemory, Hindsight, @redis/vercel-ai-sdk):
one factory over a core AgentMemory that exposes per-request tools(),
an automatic-recall prepareStep() that appends a <memories> block to the
instructions on step 0, recallContext(), tool-usage instructions and
the underlying store.

The other providers' automatic memory wraps the model with
wrapLanguageModel; this repo does not wrap models, so automatic recall
uses the prepareStep seam instead (generateText, streamText and
ToolLoopAgent, userId optionally from runtimeContext). A failed recall
never fails the call.

createMemoryTools now shares buildMemoryTools with the provider. The
ai-sdk demo uses the provider; README and CLAUDE.md document it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CMK4etJMDDBFkjEyWDVCdy
@CahidArda
CahidArda force-pushed the feat/ai-sdk-memory-provider branch from eafa45b to 532757a Compare November 11, 2026 11:32
@linear-code

linear-code Bot commented Nov 11, 2026

Copy link
Copy Markdown

DX-3285

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants