cloudflare / cloudflare/agents

Feature Request: Pick and choose Agent functionality

Open
#846 5 comments 0 reactions 1 assignee Claimed by @mattzcarey View on GitHub
enhancement
Dominant language
TypeScript
Stars
5.6k
Forks
711
Avg merge
1d 20h
Merged PRs (30d)
53

Description

_(edit by @threepointone: see https://github.com/cloudflare/agents/issues/846#issuecomment-3859948772)_

## Problem

Currently, all 5 database tables are created in the Agent constructor on every instantiation:
- `cf_agents_state`
- `cf_agents_schedules`
- `cf_agents_queues`
- `cf_agents_mcp_servers`
- `cf_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

1. **Lazy table creation**: Create tables on-demand when features are first used, rather than upfront in the constructor

2. **New `AgentConfig` type**: Allow explicitly disabling features via configuration, with helpful error messages if disabled features are accessed

```ts
export type AgentConfig = {
disableStatePersistence?: boolean;
disableScheduling?: boolean;
disableQueue?: boolean;
disableMcp?: boolean;
disableWorkflows?: boolean;
};
```

### Example usage:
```ts
class MinimalAgent extends Agent {
// 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.