This site is not affiliated with or endorsed by Vercel, Inc. Read the docs, then deploy or run each experiment yourself.
AI

Memory Thread Lab

Multi-turn chat with Redis thread memory, TTL visualization, and an honest in-memory fallback.

Run this experiment yourself

Demos are not embedded on this site. Deploy a standalone copy on Vercel or run the experiment app locally.

Local development

cd apps/experiments/memory-thread-lab
pnpm install
pnpm dev

Then open http://localhost:3010.

This is an experimental demo. Use it as a starting point for your own projects.

Memory Thread Lab is a multi-turn chat that stores thread messages in Redis with a TTL (and shows remaining time), or falls back to process memory without TTL. Missing AI keys return 503.

Features

  • Multi-turn chat – prior messages passed to the model.
  • Redis TTL – thread keys expire; UI visualizes remaining time.
  • Memory fallback – honest note when Redis is absent.
  • Honest 503 when AI is not configured.

Server Reference

POST /api/chat

{ "message": "...", "threadId": "optional" }

GET /api/thread?id=...

Returns thread + TTL visualization.

DELETE /api/thread?id=...

Clears a thread.

StatusCause
503No AI provider
404Thread missing/expired
400Empty message / missing id

Implementation Details

Load thread

Redis GET or memory Map; clamp turns.

Reply + save

generateText with history; Redis SET with ex TTL.

Use Cases

  • Learn Redis memory patterns for chat.
  • Prototype short-lived conversational state.

Limitations

  • Demo TTL (~15 minutes); not a durable agent memory product.
  • Turn count capped.

Use in your project

Copy handlers from apps/experiments/memory-thread-lab/.

Deployment

Deploy on Vercel

Local Development

cd apps/experiments/memory-thread-lab
pnpm install
pnpm dev

Configuration

VariableRequiredPurpose
AI_GATEWAY_API_KEYYes (or OPENAI_API_KEY)Chat
UPSTASH_REDIS_REST_URL / TOKENNoThread memory + TTL

Vercel / Next.js Features Used

  • AI SDK generateText
  • Upstash Redis
  • Route Handlers

Next Steps

On this page