Skip to main content
This guide covers everything you need to configure agents for local development and production deployment, including wrangler.jsonc setup, type generation, environment variables, and the Cloudflare dashboard.

wrangler.jsonc

The wrangler.jsonc file configures your Cloudflare Worker and its bindings. Here’s a complete example for an agents project:
wrangler.jsonc

Key Fields

compatibility_flags

The nodejs_compat flag is required for agents:
This enables Node.js compatibility mode, which agents depend on for crypto, streams, and other Node.js APIs.

durable_objects.bindings

Each agent class needs a binding:
When name and class_name differ:
This is useful when you want environment variable-style naming (COUNTER_DO) but more descriptive class names (CounterAgent).

migrations

Migrations tell Cloudflare how to set up storage for your Durable Objects:

assets

For serving static files (HTML, CSS, JS):
With a binding, you can serve assets programmatically:

ai

For Workers AI integration:
Access in your agent:

Generating Types

Wrangler can generate TypeScript types for your bindings.

Automatic Generation

Run the types command:
This creates or updates worker-configuration.d.ts with your Env type.

Custom Output Path

Specify a custom path:

Without Runtime Types

For cleaner output (recommended for agents):
This generates just your bindings without Cloudflare runtime types.

Example Generated Output

env.d.ts

Adding to package.json

Add a script for easy regeneration:
package.json

Environment Variables and Secrets

Local Development (.env)

Create a .env file for local secrets (add to .gitignore):
.env
Access in your agent:

Production Secrets

Use wrangler secret for production:

Non-Secret Variables

For non-sensitive configuration, use vars in wrangler.jsonc:
All values must be strings. Parse numbers/booleans in code:

Environment-Specific Variables

Use env sections for different environments (e.g. staging, production):
Deploy to specific environment:

Local Development

Starting the Dev Server

With Vite (recommended for full stack apps):
Without Vite:

Local State Persistence

Durable Object state is persisted locally in .wrangler/state/:

Clearing Local State

To reset all local Durable Object state:
Or restart with fresh state:

Inspecting Local SQLite

You can inspect agent state directly:

Dashboard Setup

Automatic Resources

When you deploy, Cloudflare automatically creates:
  • Worker - Your deployed code
  • Durable Object namespaces - One per agent class
  • SQLite storage - Attached to each namespace

Viewing Durable Objects

1

Go to Cloudflare Dashboard

2

Select Workers and Pages

Select your account → Workers & Pages
3

Click your Worker

Click your Worker name
4

View Durable Objects

Go to Durable Objects tab
Here you can:
  • See all Durable Object namespaces
  • View individual object instances
  • Inspect storage (keys and values)
  • Delete objects

Real-time Logs

View live logs from your agents:
Or in the dashboard:
  1. Go to your Worker
  2. Click Logs tab
  3. Enable real-time logs
Filter by:
  • Status (success, error)
  • Search text
  • Sampling rate

Analytics

The dashboard shows:
  • Request count
  • Error rate
  • CPU time
  • Duration percentiles
  • Durable Object metrics

Production Deployment

Basic Deploy

This:
  1. Bundles your code
  2. Uploads to Cloudflare
  3. Applies migrations
  4. Makes it live on *.workers.dev

Custom Domain

Add a route in wrangler.jsonc:
Or use a custom domain (simpler):

Preview Deployments

Deploy without affecting production:

Rollbacks

Roll back to a previous version:

Multi-Environment Setup

Environment Configuration

Define environments in wrangler.jsonc:

Deploying to Environments

Separate Durable Objects

Each environment gets its own Durable Objects. Staging agents don’t share state with production agents.

Migrations

Migrations manage Durable Object storage schema changes.

Adding a New Agent

Add to new_sqlite_classes in a new migration:

Renaming an Agent Class

Use renamed_classes:
Important: Also update:
  1. The class name in code
  2. The class_name in bindings
  3. Export statements

Deleting an Agent Class

Use deleted_classes:
This permanently deletes all data for that class.

Migration Best Practices

  1. Never modify existing migrations - Always add new ones
  2. Use sequential tags - v1, v2, v3 (or use dates: 2025-01-15)
  3. Test locally first - Migrations run on deploy
  4. Back up production data - Before renaming or deleting

Troubleshooting

”No such Durable Object class”

The class isn’t in migrations:

“Cannot find module” in types

Regenerate types:

Secrets not loading locally

Check that .env exists and contains the variable:

Migration tag conflict

Migration tags must be unique. If you see conflicts: