Store backends
Per-backend setup for conversation history — AgentState, Cloudflare D1, Postgres, Memory, and Browser defaults.
Pick the conversation store that fits your platform. Each backend uses the same build-time flag and a runtime backend selector.
Build-time flag required
All server-side backends require CHM_FEATURE_CONVERSATION_DB=true set before bun run build. Its client VITE_FEATURE_CONVERSATION_DB is derived from it at build time and baked into the bundle, so it cannot be changed without a rebuild. CONVERSATION_STORE_BACKEND is a runtime variable and can be set or changed without rebuilding.
Platform recommendation
| Platform | Recommended store | Why |
|---|---|---|
| Cloudflare Workers | d1 | Managed SQL, easy to inspect/migrate/export |
| Docker / self-hosted | postgres | Reuse existing infrastructure |
| Kubernetes | postgres | Standard managed database pattern |
| Any platform | agentstate | Cloud-hosted, no infrastructure to manage |
| Local development | memory | No setup; data is ephemeral |
Auto-selection order
When CONVERSATION_STORE_BACKEND is not set, the server picks the first available backend:
- AgentState — when
AGENTSTATE_API_KEYis set andCONVERSATION_STORE_BACKENDis not explicitlyd1,postgres, ormemory. - Cloudflare D1 — when the
CHM_CLOUD_D1binding is present (Cloudflare Workers only). - Postgres — when
DATABASE_URLis set. - Memory — fallback in development/CI.
Backend setup
Cloud-hosted conversation store. Works on all platforms. Requires an as_live_ prefixed key.
AGENTSTATE_API_KEY=as_live_xxx
# AGENTSTATE_AI_ENRICH=true # optional AI title enrichment
# CONVERSATION_STORE_BACKEND=agentstate # optional — auto-selected when key is presentCloudflare-only. Requires a provisioned D1 database and a Worker binding.
CONVERSATION_STORE_BACKEND=d1
CHM_CLOUD_D1_DATABASE_ID=<uuid>Provision and migrate:
bun run cf:setup-conversations
bun run cf:migrate-conversationsThe setup script creates the D1 database, stores the UUID in wrangler.toml, and adds the CHM_CLOUD_D1 binding. The migration script applies the schema. During CI deploys, set CHM_CLOUD_D1_DATABASE_ID as a secret so wrangler deploy includes the binding. Without it, the binding is excluded from the deploy.
Also accepts AGENT_CHM_CLOUD_D1_DATABASE_ID as an alias for CHM_CLOUD_D1_DATABASE_ID.
When to use: standard Cloudflare deployments that want queryable, exportable conversation history.
Any PostgreSQL-compatible database.
CONVERSATION_STORE_BACKEND=postgres
DATABASE_URL=postgresql://user:password@host:5432/dbAlso accepts POSTGRES_URL or POSTGRES_PRISMA_URL instead of DATABASE_URL. The runtime creates the conversations table and indexes if they do not exist. The database user needs CREATE TABLE, CREATE INDEX, SELECT, INSERT, UPDATE, and DELETE on the target schema.
When to use: Kubernetes, Docker, or any deployment with an existing Postgres instance.
Ephemeral in-process store. Lost on process restart.
CONVERSATION_STORE_BACKEND=memoryUse only in development or tests.
Default when VITE_FEATURE_CONVERSATION_DB is not true or when the user is unauthenticated. No server config needed. History is stored in browser localStorage. Clearing browser data loses history.
Deprecated alias
NEXT_PUBLIC_FEATURE_CONVERSATION_DB=true is equivalent to VITE_FEATURE_CONVERSATION_DB=true but is deprecated. Do not use it for new deployments.