chat / state-redis
AGENTS.md2.4k starsChanged 59 days agoMITView on GitHub
Guidance for coding agents working inside the Redis state adapter package (built on node-redis). The top-level repository AGENTS.md covers monorepo-wide build, lint, and release rules — read it first. This file documents the adapter-specific surface, conventions, and pitfalls. @chat-adapter/state-redis persists Chat SDK state in Redis using the redis (a.k.a. node-redis) client. It covers: - Subscriptions stored as a per-thread EXISTS flag. - Distributed locks via SET NX PX + a Lua release script for token-checked atomic release. - Key/value caching…
- Reads credentials
Trending
Quiet since March.thin dataabout the whole repository
Who's talking about vercel/chat
- @camilleroux.com“Un SDK TypeScript unifié pour créer des chatbots qui fonctionnent sur Slack, Teams, Google Chat, Discord, …”Bluesky · Mar 3, 2026 · 3 likes
- @technews4869.bsky.social“github.com/vercel/chat GitHub - vercel/chat: A unified TypeScript SDK for building chat bots across Slack, …”Bluesky · Mar 7, 2026 · 1 likes
- @yug1224.com“チャットアプリ開発に使える統一SDKを提供するツールらしい 様々なプラットフォーム対応で便利そうだな yug1224 starred vercel/chat https://github.com/vercel/chat”Bluesky · Mar 7, 2026 · 1 likes
- @news.humancoders.com“Vercel lance Chat SDK : un SDK TypeScript unifié pour créer des bots multi-plateformes”Bluesky · Mar 5, 2026 · 1 likes
- @github-trending-js.bsky.social“🔥 Hot Repo! 🔥 (100+ new stars) 📦 vercel / chat ⭐ 871 (+121) 🗒 TypeScript A unified TypeScript SDK for …”Bluesky · Feb 27, 2026 · 1 likes
The biggest 5 of 5 mentions linking to the repository that our crawl found. Each line is their own headline.
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository44 other files it gives its agents.
- AGENTS.mdAGENTS.md
- apps/docs/AGENTS.mdAGENTS.md
- chat-sdkAGENTS.md
- packages/adapter-discord/AGENTS.mdAGENTS.md
- packages/adapter-gchat/AGENTS.mdAGENTS.md
- packages/adapter-github/AGENTS.mdAGENTS.md
- packages/adapter-instagram/AGENTS.mdAGENTS.md
- packages/adapter-linear/AGENTS.mdAGENTS.md
- packages/adapter-messenger/AGENTS.mdAGENTS.md
- packages/adapter-notion/AGENTS.mdAGENTS.md
- packages/adapter-slack/AGENTS.mdAGENTS.md
- packages/adapter-teams/AGENTS.mdAGENTS.md
- packages/adapter-telegram/AGENTS.mdAGENTS.md
- packages/adapter-web/AGENTS.mdAGENTS.md
- packages/adapter-whatsapp/AGENTS.mdAGENTS.md
- packages/chat/src/adapters/AGENTS.mdAGENTS.md
- packages/create-chat-sdk/AGENTS.mdAGENTS.md
- packages/create-chat-sdk/_template/AGENTS.mdAGENTS.md
- packages/state-ioredis/AGENTS.mdAGENTS.md
- packages/state-memory/AGENTS.mdAGENTS.md
- packages/state-pg/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- packages/adapter-discord/CLAUDE.mdCLAUDE.md
- packages/adapter-gchat/CLAUDE.mdCLAUDE.md
- packages/adapter-github/CLAUDE.mdCLAUDE.md
- packages/adapter-linear/CLAUDE.mdCLAUDE.md
- packages/adapter-messenger/CLAUDE.mdCLAUDE.md
- packages/adapter-slack/CLAUDE.mdCLAUDE.md
- packages/adapter-teams/CLAUDE.mdCLAUDE.md
- packages/adapter-telegram/CLAUDE.mdCLAUDE.md
- packages/adapter-web/CLAUDE.mdCLAUDE.md
- packages/adapter-whatsapp/CLAUDE.mdCLAUDE.md
- packages/create-chat-sdk/CLAUDE.mdCLAUDE.md
- packages/create-chat-sdk/_template/CLAUDE.mdCLAUDE.md
- packages/state-ioredis/CLAUDE.mdCLAUDE.md
- packages/state-memory/CLAUDE.mdCLAUDE.md
- packages/state-pg/CLAUDE.mdCLAUDE.md
- packages/state-redis/CLAUDE.mdCLAUDE.md
- add-adapterSkill
- technical-writerSkill
- chat-sdkSkill
- chat-sdkSkill
- chat-sdkSkill
- chat-sdkSkill
The file
We split this AGENTS.md into the rules it gives an agent
6 rules. About 0 are common, 2 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 86
When neither url nor client is provided, the adapter falls back to REDIS_URL.
- Very specific: line 94
All keys are prefixed with keyPrefix: (default "chat-sdk:").
- Very specific: line 163
If you bring your own client:
- Distinctive: line 167
If your client has its own retry/timeout logic, it takes precedence.
- Distinctive: line 192
Use named exports throughout.
- Very specific: line 193
All key construction goes through a single prefixedKey helper — never inline string concatenation.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md — @chat-adapter/state-redis
Guidance for coding agents working inside the Redis state adapter
package (built on node-redis). The top-level repository
AGENTS.md covers monorepo-wide build, lint, and
release rules — read it first. This file documents the
adapter-specific surface, conventions, and pitfalls.
Overview
@chat-adapter/state-redis persists Chat SDK state in Redis using
the redis (a.k.a.
node-redis) client. It covers:
- Subscriptions stored as a per-thread
EXISTSflag. - Distributed locks via
SET NX PX+ a Lua release script for token-checked atomic release. - Key/value caching with optional TTL via
SETEX/EXPIRE. - Lists backed by Redis sorted sets (so list entries can have per-entry TTLs).
- Queues backed by Redis sorted sets keyed on enqueue time.
- Automatic key prefixing for multi-tenant isolation.
This is the recommended state adapter for production deployments on managed Redis services (Vercel KV, Upstash, AWS ElastiCache, Redis Cloud, etc.).
Directory layout
packages/state-redis/
├── src/
│ ├── index.ts # RedisStateAdapter + createRedisState
│ └── index.test.ts # full StateAdapter contract suite
├── package.json
├── tsconfig.json
├── tsup.config.ts
├── vitest.config.ts
└── README.mdThe package is intentionally small. Anything generic to Redis
adapters lives here; the ioredis variant in state-ioredis
re-implements the same surface against a different client.
Build, test, typecheck
pnpm build
pnpm dev
pnpm test
pnpm test:watch
pnpm typecheck
pnpm clean
# from repo root
pnpm --filter @chat-adapter/state-redis build
pnpm --filter @chat-adapter/state-redis testThe unit tests use an in-memory Redis stub backed by vi.fn(). There
is no requirement to run a real Redis server for the contract tests.
Public surface
Main exports from src/index.ts:
createRedisState(config?)— primary factory. Auto-detectsREDIS_URL(a.k.a.KV_URLfor Vercel KV).RedisStateAdapterclass — implements the Chat SDKStateAdapterinterface. Public methods cover subscriptions, locks, cache, lists, queues, plus adisconnect()for graceful shutdown.RedisStateAdapterConfig— configuration type.
Configuration
createRedisState({
url: process.env.REDIS_URL, // or KV_URL
client: existingRedisClient, // bring your own connected client
keyPrefix: "chat-sdk", // namespace prefix
logger: customLogger,
});When neither url nor client is provided, the adapter falls back
to REDIS_URL. Connection setup is lazy — the first call connects
the client and subsequent calls reuse it. The adapter never owns the
client lifecycle when the caller passes one in via client; in that
case disconnect() is a no-op.
Internal key layout
All keys are prefixed with keyPrefix: (default "chat-sdk:").
{prefix}:subs:{threadId} # SET-style subscription marker
{prefix}:lock:{lockId} # STRING with token value, PX TTL
{prefix}:cache:{cacheKey} # STRING value, optional EXPIRE
{prefix}:list:{listKey} # ZSET entries, score = epoch ms
{prefix}:queue:{queueKey} # ZSET entries, score = epoch ms
{prefix}:queue:{queueKey}:dedupe # SET of dedupe keys (queue items only)Sorted-set storage is used for lists and queues so per-entry TTLs
are achievable without KEYSPACE-NOTIFICATIONS magic. Reads filter
expired entries by score range; periodic ZREMRANGEBYSCORE calls
keep the index size bounded (the adapter runs them inline on each
write).
Locking semantics
acquireLock(lockId, ttlMs):
- Generates a unique token (UUID v4).
- Issues
SET {prefix}:lock:{lockId} {token} NX PX {ttlMs}. - Returns
{ token }on success,nullon contention.
releaseLock(lockId, token):
- Runs an embedded Lua script that compares the stored token against
the supplied one and
DELs only on match. - Returns
trueif the lock was held by the caller and released,falseotherwise.
forceReleaseLock(lockId) is DEL {prefix}:lock:{lockId} —
unconditional.
The Lua script is loaded with SCRIPT LOAD on first use and cached
by sha. If a Redis NOSCRIPT error fires, the adapter retries with
EVAL.
Capabilities
- Persistence — yes (Redis durability rules apply).
- Multi-instance — yes.
- Subscriptions — yes.
- Distributed locking — yes, atomic via Lua release script.
- Key-value cache — yes, with TTL.
- Lists — yes, with per-entry TTL via ZSET scores.
- Queues — yes, with per-entry TTL + dedupe set.
- Automatic reconnect — yes (delegated to
node-redis). - Cluster — yes, when the supplied client is a Redis Cluster
instance. Key prefixes use
{}braces around the hash slot to avoid CROSSSLOT errors on multi-key operations. - Sentinel — via
client— pass a Sentinel-awarenode-redisclient. - Key prefix namespacing — yes.
Vercel KV
Vercel KV is API-compatible with node-redis. The adapter detects
KV deployments by reading KV_URL (alias of REDIS_URL) and
configuring TLS automatically. No additional config needed.
Connection management
The adapter uses one Redis connection per RedisStateAdapter
instance. All commands run on the same client; transactions
(MULTI/EXEC) are used for the rare composite operations. Pipelines
are not used because the per-call latency is not the bottleneck.
If you bring your own client:
- The adapter assumes the client is already connected.
- The adapter does not call
disconnect()on it. - If your client has its own retry/timeout logic, it takes precedence.
Error handling
AuthenticationError is thrown for WRONGPASS/NOAUTH errors,
AdapterRateLimitError for LOADING (Redis is loading the data
set), and NetworkError for connection failures. Other errors
propagate as plain Error instances since they typically indicate
programmer error (bad key, wrong type, etc.).
Testing approach
- The contract tests in
index.test.tsmirror thestate-memorysuite. Both packages must stay green against the same set of assertions. - The Redis client is replaced with a
vi.fn()-backed stub that records commands and returns canned responses. Reach for the stub helpers (makeMockRedis) rather than rolling your own. - Real-Redis tests live in
packages/integration-tests/src/state-*.test.tsand run against a local Redis instance only whenREDIS_URLis exported.
Coding conventions
- Use named exports throughout. No default exports.
- All key construction goes through a single
prefixedKeyhelper — never inline string concatenation. - Wrap multi-step operations in
MULTI/EXECwhen atomicity matters (e.g. queue dedupe + enqueue). - TTLs are stored as absolute epoch milliseconds for ZSET-backed structures and converted to relative ms (PX) for STRING-backed ones.
- Top-level regex literals only.
- Errors thrown to chat-sdk callers come from
@chat-adapter/shared(AuthenticationError,AdapterRateLimitError,NetworkError).
Releases
Behavioural changes need a changeset (pnpm changeset, choose
@chat-adapter/state-redis plus chat if a public StateAdapter
type changed). README and AGENTS.md edits don't.
Where to look next
- User-facing docs:
apps/docs/content/adapters/official/redis.mdx - README:
packages/state-redis/README.md - Core StateAdapter contract:
packages/chat/src/state.ts - Sibling state adapters:
packages/state-memorypackages/state-ioredispackages/state-pg
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

