Layer 3: Full-stack primitives
The app around the agent: compute, data, files, durable pipelines, schedules.
In this layer: Workers, D1, R2, KV, Workflows, Queues (plus Cron).
Workers
What it is: Serverless compute on every Cloudflare location. Your agent, your API, your Custom Domain.
Use it when: Always: your Worker serves the chat UI, POST /api/chat and /mcp.
// wrangler.jsonc: your team card gives the account id and the hostname
"account_id": "<TEAM_ACCOUNT_ID>",
"routes": [{ "pattern": "<TEAM_HOSTNAME>", "custom_domain": true }]
Basics: Workers
Advanced: Custom Domains
D1
What it is: Serverless SQLite. Tables, joins, migrations.
Use it when: An audit log of what the agent proposed and what a human approved.
// npx wrangler d1 create agent-db
await env.DB.prepare('INSERT INTO actions (id, proposal, approved_by) VALUES (?, ?, ?)')
.bind(id, proposal, approver).run();
Basics: D1
Advanced: Migrations
R2
What it is: Object storage with no egress fees.
Use it when: Storing Browser Run screenshots as evidence, or reports the agent generates.
await env.BUCKET.put(`evidence/${id}.png`, png, { httpMetadata: { contentType: 'image/png' } });
Basics: R2
Advanced: Workers API
KV
What it is: Global key-value store for read-heavy config and caches.
Use it when: Feature flags or a known-good baseline your watcher compares against.
await env.KV.put('baseline:se', JSON.stringify(vitals), { expirationTtl: 3600 });
Basics: KV
Advanced: KV API
Workflows
What it is: Durable multi-step execution with retries, sleeps and a pause for a human.
Use it when: Publish, purge both zones, verify, and wait for approval before the risky step.
const plan = await step.do('plan purge', async () => planPurge(event.payload));
const ok = await step.waitForEvent<{ approved: boolean }>(
'await approval', { type: 'purge-approval', timeout: '1 hour' });
if (ok.payload.approved) await step.do('purge', () => purge(plan));
Basics: Workflows
Advanced: Events and parameters
Queues (plus Cron)
What it is: Buffered, retried background work. Cron Triggers run a Worker on a schedule.
Use it when: Fan out a scan of every market page, or run a watcher every 15 minutes.
await env.QUEUE.send({ market: 'se', url });
// wrangler.jsonc: "triggers": { "crons": ["*/15 * * * *"] }
Basics: Queues · Cron Triggers
Advanced: Agents SDK schedules