-
Notifications
You must be signed in to change notification settings - Fork 447
Description
Summary
We use AIChatAgent primarily for resumable streaming, while our source of truth for chat history is Postgres.
We want to keep stream resume reliability but avoid duplicate message persistence in Durable Object SQLite.
Environment
@cloudflare/ai-chat:0.1.5agents:0.6.0- Runtime: Cloudflare Workers + Durable Objects (SQLite)
- External message store: Postgres
Current behavior
AIChatAgent always creates and writes to cf_ai_chat_agent_messages.
Even when apps persist chat history externally, DO SQLite still stores full messages.
We already clean resumable stream tables on completion/error:
cf_ai_chat_stream_chunkscf_ai_chat_stream_metadata
But message persistence in cf_ai_chat_agent_messages still remains and keeps growing.
Problem
This causes:
- duplicate storage (Postgres + DO SQLite)
- extra SQLite row writes
- avoidable SQLite stored data costs
Expected behavior
Provide a built-in mode to keep resumable streaming only, while disabling DO message history persistence.
Example desired behavior:
- keep stream chunk buffering/replay for
resume: true - keep minimal request context needed for tool continuation
- skip writes to
cf_ai_chat_agent_messages
Suggested API
export class ChatAgent extends AIChatAgent<Env> {
persistence = {
messages: "external", // default could remain "sqlite"
streams: "sqlite"
};
}Alternative:
new AIChatAgent({ persistMessagesInSQLite: false })Workarounds tried
- maxPersistedMessages limits retained rows but does not avoid writes.
- Manual cleanup of stream tables solves chunk retention only, not message-table persistence.
Why this matters
Many production apps already persist chat history in their own DB and only need DO SQLite for resumable stream replay.
A stream-only mode would reduce storage and cost while preserving reliability.