chmonitor

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

PlatformRecommended storeWhy
Cloudflare Workersd1Managed SQL, easy to inspect/migrate/export
Docker / self-hostedpostgresReuse existing infrastructure
KubernetespostgresStandard managed database pattern
Any platformagentstateCloud-hosted, no infrastructure to manage
Local developmentmemoryNo setup; data is ephemeral

Auto-selection order

When CONVERSATION_STORE_BACKEND is not set, the server picks the first available backend:

  1. AgentState — when AGENTSTATE_API_KEY is set and CONVERSATION_STORE_BACKEND is not explicitly d1, postgres, or memory.
  2. Cloudflare D1 — when the CHM_CLOUD_D1 binding is present (Cloudflare Workers only).
  3. Postgres — when DATABASE_URL is set.
  4. 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 present

Cloudflare-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-conversations

The 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/db

Also 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=memory

Use 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.

On this page