tanstack-ai-memory

Adds server-side cross-session memory to TanStack AI chat calls via recall/save middleware.

3.1k|316|Updated Oct 8, 2025
One-click install
npx skills add https://github.com/TanStack/ai --skill tanstack-ai-memory
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tanstack-ai-memory
Source: https://github.com/TanStack/ai/tree/main/packages/ai-memory/skills/tanstack-ai-memory
Command: npx skills add https://github.com/TanStack/ai --skill tanstack-ai-memory

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tanstack/ai, @tanstack/ai-memory, @tanstack/ai-event-client.

What problem does it solve?

LLM chat applications forget everything between sessions, forcing users to repeat context. This Skill wires persistent, per-user or per-thread memory into a TanStack AI chat() call so the model recalls prior context across turns and sessions.

Core Features & Use Cases

  • Recall/Save Middleware: memoryMiddleware injects recalled memory into the system prompt before the model runs and defers saving the turn after it finishes, with non-fatal failure handling.
  • Pluggable Adapters: Choose from inMemory, redis, hindsight, mem0, or honcho, or implement the two-verb MemoryAdapter contract (recall/save) yourself.
  • Secure Scoping: Derive MemoryScope (threadId, userId, tenantId, namespace) server-side from session state to enforce isolation boundaries.
  • Use Case: A support chatbot needs to remember a user's preferences from last week. Attach memoryMiddleware with a Redis adapter and a session-derived scope so each conversation recalls prior facts automatically.

Quick Start

Add memoryMiddleware from @tanstack/ai-memory to my chat() call with a Redis adapter and a scope derived from my server-side session.

Frequently Asked Questions about tanstack-ai-memory

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add memory to a TanStack AI chat call?

Add memoryMiddleware from @tanstack/ai-memory to the middleware array of your chat() call, passing an adapter and a scope. The middleware recalls memory into the system prompt before the model runs and saves the turn afterward.

Which memory adapter should I use with @tanstack/ai-memory?

Use inMemory for dev and tests, redis for exact-match thread/user lookup, and hindsight, mem0, or honcho for hosted memory services. You can also implement the recall/save contract yourself and validate it with the package's contract tests.

Can I trust a client-supplied userId or threadId for memory scope?

No. MemoryScope is the isolation boundary, so always resolve scope server-side from session or auth state and pass it through chat({ context: { session } }). Validate any request-supplied thread id belongs to the session user before use.

What happens if memory recall or save fails during a chat turn?

Memory failures are non-fatal. A throwing recall or save emits a memory:error event and the run continues with degraded memory; streaming is never blocked and a failed save never fails the turn.

When should I not use memory middleware for chat history?

Do not use it just to keep recent messages within a conversation; that is what the messages array on chat() is for. Memory middleware is for cross-turn and cross-session recall, not within-turn history.