Use when wiring memoryMiddleware from @tanstack/ai-memory into a chat() call — covers the recall/save adapter contract, scope shape and server-side scope security, the recall-inject / deferred-save lifecycle, choosing an adapter (inMemory, redis, hindsight, mem0, honcho), and devtools events.
SkillScore96Maintained
Automatic
◆AI Engineer pack
Last verified 9/28/2026
What it changes
Passed 23 of 24 test cases with the skill, and 7 of 24 without it.
Without skill29%
With skill96%
Checks it passed that the model alone missed
States that the default role is 'recall+save'.
Uses memoryMiddleware from @tanstack/ai-memory.
Implements save accepting scope and turn parameters.
and 21 more in the full report
16 fixed7 passed either way1 still failing0 broke
Pass-rate lift
+67 pp
Tokens
-10%
Agent turns
0%
Response time
-48%
Model gemini-3.6-flashMeasured 9/28/2026v323 of 24 cases passed with skill
Tokens, turns and time describe resource use, not a dollar price.
See it in action
One of 16 test cases the skill fixed. Same model, same prompt, with and without the skill.
1 of 16
Prompt
What is the default value of the `role` parameter in `memoryMiddleware` when omitted from configuration?
What was checked, without and with the skill
Checked
Without skill
With skill
States that the default role is 'recall+save'.
Missed
Passed
case-21 · gemini-3.6-flash · 9/28/2026 · answers are capped and redacted
What's inside
The instructions your model reads when the skill loads.
SKILL.md108 linessingle file
TanStack AI Memory Middleware
Use this when adding server-side memory to a chat() call. Everything lives in
@tanstack/ai-memory. A memory adapter is a single contract with two verbs — recall
and save — and the middleware is thin: it recalls into the system prompt before the
model runs and defers save after the turn finishes.
When to reach for it
A user expects "remember what I told you last time."
Per-user or per-thread context that must survive across sessions.
A hosted memory service (mem0, Honcho, Hindsight).
Do NOT use this just to keep recent messages — that's the messages array on chat().
Memory is for cross-turn / cross-session recall, not within-turn history.
Wire it up
import { chat, toServerSentEventsResponse } from '@tanstack/ai'
import { openaiText } from '@tanstack/ai-openai'
import { memoryMiddleware } from '@tanstack/ai-memory'
import { inMemory } from '@tanstack/ai-memory/in-memory'
import { requireSession } from './auth'
const memory = inMemory() // dev/tests only — see the in-memory skill
export async function POST(request: Request) {
const { messages } = await request.json()
// Resolved by your auth layer from cookies/headers — never from the request body.
const session = await requireSession(request)
const stream = chat({
adapter: openaiText('gpt-5.5'),
messages,
context: { session },
middleware: [
memoryMiddleware({
adapter: memory,
// Derive scope server-side from trusted session state.