chat / state-memory
AGENTS.md2.4k starsChanged 59 days agoMITView on GitHub
Guidance for coding agents working inside the in-memory state adapter package. 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-memory is the simplest state adapter — keeps all subscriptions, locks, caches, lists, and queues in process memory. Suitable for: - Local development and tutorials. - Single-process bots where durability is not a concern (and recovery from a restart is acceptable). - Tests — the…
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-pg/AGENTS.mdAGENTS.md
- packages/state-redis/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
4 rules. About 0 are common, 2 are distinctive, and 2 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.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 88
All keys are namespaced with ${keyPrefix}:${rawKey} so multiple adapter instances can coexist.
- Distinctive: line 153
Use a real distributed store instead.
- Distinctive: line 170
Use named exports throughout.
- Very specific: line 171
All key construction goes through a single prefixedKey(rawKey) helper.
≈ “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-memory
Guidance for coding agents working inside the in-memory state adapter package. 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-memory is the simplest state adapter — keeps
all subscriptions, locks, caches, lists, and queues in process
memory. Suitable for:
- Local development and tutorials.
- Single-process bots where durability is not a concern (and recovery from a restart is acceptable).
- Tests — the integration tests use it heavily because it has zero external dependencies and is deterministic.
It is not suitable for production multi-instance deployments. Pick
one of @chat-adapter/state-redis, @chat-adapter/state-ioredis, or
@chat-adapter/state-pg instead.
Directory layout
packages/state-memory/
├── src/
│ ├── index.ts # MemoryStateAdapter + createMemoryState
│ └── index.test.ts # complete contract tests
├── package.json
├── tsconfig.json
├── tsup.config.ts
├── vitest.config.ts
└── README.mdThere are no sub-modules — the in-memory adapter is small enough to live in a single file.
Build, test, typecheck
pnpm build
pnpm dev
pnpm test
pnpm test:watch
pnpm typecheck
pnpm clean
# from repo root
pnpm --filter @chat-adapter/state-memory build
pnpm --filter @chat-adapter/state-memory testThe contract tests verify the full Chat SDK StateAdapter interface;
this is the canonical reference implementation, so the test file
doubles as documentation for what each method should do.
Public surface
Main exports from src/index.ts:
createMemoryState(config?)— primary factory. Accepts no arguments by default; akeyPrefixis the only option (used to namespace several MemoryStateAdapter instances inside the same process).MemoryStateAdapterclass — implements the Chat SDKStateAdapterinterface. Public methods cover subscriptions (subscribe/unsubscribe/isSubscribed/listSubscriptions), locks (acquireLock/releaseLock/forceReleaseLock), key/value cache (get/set/delete), lists (appendToList/getList), and queues (enqueue/dequeue/peekQueue/clearQueue).MemoryStateAdapterConfig— configuration type.
Internal data model
The adapter keeps five maps in memory:
const subscriptions = new Set<string>();
const locks = new Map<string, { token: string; expiresAt: number }>();
const cache = new Map<string, { value: string; expiresAt?: number }>();
const lists = new Map<string, Array<{ value: string; expiresAt?: number }>>();
const queues = new Map<string, Array<{ value: string; expiresAt: number }>>();All keys are namespaced with ${keyPrefix}:${rawKey} so multiple
adapter instances can coexist.
Expired entries are cleaned up lazily — every read checks
expiresAt and returns undefined (or omits the entry from list /
queue results) when the TTL has passed. There is no background
sweeper.
Locking semantics
acquireLock issues a unique token per acquisition (UUID v4).
releaseLock only succeeds if the supplied token matches the stored
one — exactly the same semantics as the Redis adapters' SET NX PX
- Lua release script.
Because the entire adapter runs inside one process, the locking is cooperative. There is no contention model beyond JavaScript's single-threaded event loop, so two awaits in the same event loop tick can never race the lock.
forceReleaseLock deletes the entry unconditionally — used by the
Chat SDK's lock-conflict resolver.
Capabilities
- Persistence — no. State lives in process memory only.
- Multi-instance — no. Each Node process has its own state.
- Subscriptions — yes.
- Distributed locking — single-process only.
- Key-value cache — yes, with TTL.
- Lists — yes, with per-entry TTL.
- Queues — yes, with per-entry TTL.
- Automatic reconnect — n/a (no transport).
- Cluster / Sentinel — n/a.
- Key prefix namespacing — yes, via
keyPrefix.
Use cases
Local dev, especially when paired with the Web adapter:
import { Chat } from "chat"; import { createMemoryState } from "@chat-adapter/state-memory"; import { createWebAdapter } from "@chat-adapter/web"; const bot = new Chat({ userName: "mybot", adapters: { web: createWebAdapter({ userName: "mybot", getUser }) }, state: createMemoryState(), });- Unit and integration tests where a clean state adapter is desirable
per
describe. TheChattest kit (@chat-adapter/tests) wraps this adapter for contract test cases. - Tutorials — every getting-started example in the docs uses this adapter so readers don't need a Redis cluster on their laptop.
Anti-patterns
- Don't use it in production with multiple replicas. Each replica will hold its own subscription set; mentions can land on a replica that doesn't know the bot is subscribed.
- Don't share a
MemoryStateAdapteracross processes via IPC. Use a real distributed store instead. - Don't rely on
forceReleaseLockas a regular control-flow tool. It exists only to recover from a stuck lock when you can prove the holder is dead. - Don't grow lists unboundedly. Memory adapters have no eviction; trim list / queue lengths in your handler logic.
Testing approach
The bulk of the value of this package is the contract test suite in
index.test.ts. It exercises every method, every error case, and
every TTL boundary. When extending the StateAdapter interface,
update this file first — the test cases here become the spec the
Redis / Postgres adapters must also satisfy.
Coding conventions
- Use named exports throughout. No default exports.
- All key construction goes through a single
prefixedKey(rawKey)helper. Never inline string concatenation. - TTLs are stored as absolute epoch milliseconds — never as
duration values — so reads can compare against
Date.now()without per-entry math. - Errors thrown to chat-sdk callers are plain
Errorinstances; the in-memory adapter has no auth or network failure modes. - Top-level regex literals only.
Releases
Behavioural changes need a changeset (pnpm changeset, choose
@chat-adapter/state-memory 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/memory.mdx - README:
packages/state-memory/README.md - Core StateAdapter contract:
packages/chat/src/state.ts - Sibling state adapters:
packages/state-redispackages/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.

