-
Notifications
You must be signed in to change notification settings - Fork 348
Description
(edit by @threepointone: see #846 (comment))
Problem
Currently, all 5 database tables are created in the Agent constructor on every instantiation:
cf_agents_statecf_agents_schedulescf_agents_queuescf_agents_mcp_serverscf_agents_workflows
Many agents only use a subset of these features (e.g., just state management for a simple stateful agent), but still incur the overhead of creating all tables.
Cost Impact
Cloudflare Durable Objects are billed based on storage and operations. Currently:
- Every Agent instance creates 5 SQLite tables on instantiation
- Many agents only use 1-2 features (e.g., just state management)
- This results in unnecessary storage overhead and write operations
At scale (thousands of agent instances), this can lead to meaningful cost increases for users who don't need all features. Lazy table creation would ensure users only pay for storage they actually use.
Proposed Solution
-
Lazy table creation: Create tables on-demand when features are first used, rather than upfront in the constructor
-
New
AgentConfigtype: Allow explicitly disabling features via configuration, with helpful error messages if disabled features are accessed
export type AgentConfig = {
disableStatePersistence?: boolean;
disableScheduling?: boolean;
disableQueue?: boolean;
disableMcp?: boolean;
disableWorkflows?: boolean;
};Example usage:
class MinimalAgent extends Agent<Env> {
// Only uses state - disable everything else
config = {
disableScheduling: true,
disableQueue: true,
disableMcp: true,
disableWorkflows: true
};
}Benefits
- Reduced costs: Users only pay for storage they actually use
- Faster initialization: Fewer SQL operations on agent startup
Implementation
I have a working implementation ready if this approach sounds reasonable. All existing tests pass, with one test helper updated to accommodate the lazy creation pattern.