ai-persistence/stores

Implement MessageStore, RunStore, InterruptStore, and MetadataStore contracts for TanStack AI persistence adapters.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tanstack/ai-persistence, @tanstack/ai.

What problem does it solve?

@tanstack/ai-persistence ships contracts, not a database backend, so developers must implement the store interfaces themselves against their own database. This Skill defines the exact contracts, invariants, and conformance requirements needed to build a correct persistence adapter without subtle bugs like wiped histories or stuck approvals.

Core Features & Use Cases

  • Store Contract Reference: Defines MessageStore (full-replace saveThread), RunStore (idempotent createOrResume, required findActiveRun), InterruptStore (insert-if-absent create), and MetadataStore (composite namespace/key identity).
  • Composition & Shapes: Covers defineAIPersistence, named persistence shapes, and composePersistence overrides for mixing stores across backends.
  • Conformance Testing: Explains runPersistenceConformance with skip and skipMethods declarations so omitted optional methods fail loudly instead of passing silently.
  • Use Case: You are wiring TanStack AI chat persistence to Postgres and need to implement a RunStore that safely handles double-submits, reconnects via findActiveRun, and out-of-band cancellation via cancelRequested.

Quick Start

Ask the AI to implement a MessageStore and RunStore for your database following the ai-persistence store contracts and validate them with runPersistenceConformance.

Frequently Asked Questions about ai-persistence/stores

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

FAQPage Schema
How do I implement a persistence adapter for @tanstack/ai-persistence?

Implement the store interfaces you need (messages, runs, interrupts, metadata) against your database, then pass them to defineAIPersistence annotated with a named shape like ChatWithInterruptsPersistence. Validate the result with runPersistenceConformance from the testkit.

Why does withPersistence reject my persistence adapter?

withPersistence rejects adapters typed as bare AIPersistence because stores.messages is possibly undefined. Annotate your factory with a named shape such as ChatTranscriptPersistence or ChatWithInterruptsPersistence so the messages store is known present.

What is the difference between saveThread full-replace and append semantics?

saveThread is a full overwrite of the thread's message history, not an append. A one-message payload wipes prior history, so adapters must replace the stored thread rather than inserting rows incrementally.

Can I omit optional RunStore methods like listByThread?

Yes, listByThread and listReclaimable are optional and consumers feature-detect them, but findActiveRun is required. Any omitted optional method must be declared in skipMethods or the conformance suite fails.

Why does createOrResume break idempotent retries when implemented wrong?

createOrResume must return an existing run unchanged, preserving its stored usage, startedAt, and status. Overwriting existing runs breaks safe resume and double-submit handling, causing duplicate or reset agent runs.

Does @tanstack/ai-persistence include a database backend?

No, the package ships contracts plus memoryPersistence for dev and tests. Durable storage requires writing your own adapter for your database, with recipes available for Drizzle, Prisma, Cloudflare, and custom stacks.