cloudflare / cloudflare/agents
Feature request: stream-only persistence mode for AIChatAgent (disable cf_ai_chat_agent_messages)
- Dominant language
- TypeScript
- Stars
- 5.6k
- Forks
- 711
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 53
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.5`
- `agents`: `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_chunks`
- `cf_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
```ts
export class ChatAgent extends AIChatAgent {
persistence = {
messages: "external", // default could remain "sqlite"
streams: "sqlite"
};
}
```
Alternative:
```ts
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.
Contributor guide
Assessment
This issue has not been assessed yet.