Skip to main content
guidesSource-backed
Cloudflare logo

Build Cloudflare Workers AI Agents With Durable State

A practical architecture guide for building AI agents on Cloudflare Workers with Workers AI inference and durable per-agent state. Use the Agents API, Durable Objects, bindings, and Workers observability to keep agent sessions reliable across requests.

by MkDev11·added 2026-06-04·
Review first review before installing

Open the source and read safety notes before installing.

Citation facts

Source-backed facts for citing this resource, derived directly from the registry — also available as plain text for AI assistants.

Source URLs
https://developers.cloudflare.com/agents/, https://github.com/JSONbored/awesome-claude/blob/main/content/guides/cloudflare-workers-ai-agents-durable-state.mdx
Brand
Cloudflare
Brand domain
cloudflare.com
Brand asset source
brandfetch
Safety notes
Keep model output reviewable before it triggers irreversible product actions, external messages, or billing-sensitive work., Store only the durable state the agent needs; avoid persisting full prompts, files, or transcripts when summaries or structured state are enough., Add idempotency and replay handling for events that may retry, arrive out of order, or resume after an agent instance restarts.
Privacy notes
Workers logs, Durable Object storage, Workers AI prompts, model outputs, request headers, and bound service data may contain user or business context., Redact sensitive fields before logging and define retention for prompts, intermediate reasoning, tool results, and conversation state., Separate staging and production state so test prompts and generated outputs cannot leak into live sessions.
Author
MkDev11
Submitted by
MkDev11
Claim status
unclaimed
Last verified
2026-06-04

Decision playbook

Review trust signals before you adopt

Signals are present but mixed. Use the checklist below to confirm the source and operational safety for your environment.

Compare context
Selected

0

Current score

78

Baseline

Delta

No baseline selected

No major trust-signal divergence detected in the current selection.

Source and provenance checks

Complete

Confirm ownership and provenance before trusting install instructions.

  • Source link availableRequired

    Open the canonical repository and verify ownership.

    Done
  • Source provenance statusRequired

    Marked as source-backed.

    Done
  • Metadata reviewed

    Registry metadata indicates a reviewed listing.

    Done

Safety and privacy checks

Complete

Validate risk disclosures before installation or API wiring.

  • Safety notes presentRequired

    Review the listed safety guidance before running commands.

    Done
  • Privacy notes presentRequired

    Review data handling notes before connecting accounts or secrets.

    Done
  • Trust level risk gateRequired

    Trust level does not block evaluation.

    Done

Package and install checks

Needs review

Check package metadata and artifact integrity signals.

  • Install payload available

    Install or copy payload is available for review.

    Done
  • Package verification flag

    No package verification flag provided.

    Pending
  • Checksum metadata

    No checksum provided for downloaded artifact.

    Pending

Compare-driven decision checks

Needs review

Use compare context to validate trade-offs before adoption.

  • Compare tray has multiple entries

    Add at least one more entry to compare trust differences.

    Pending
  • Baseline comparison available

    No baseline peer selected yet.

    Pending
  • Diverging trust signals identified

    No major trust-signal divergence found.

    Pending

Setup at a glance

Copy & paste

Copy-ready — paste the snippet to get started.

Adoption plan

Balanced adoption plan

Current risk score 16/100. Use staged verification before broader rollout.

Risk 16

Pre-adoption checks

Validate source and review signals before any execution.

  • Confirm source provenanceRequired

    Source URL/provenance metadata is present.

    Done
  • Confirm metadata review state

    Listing has review metadata.

    Done
  • Verify install payload

    Install/config payload exists and can be inspected.

    Done

Security checks

Confirm safety, privacy, and package integrity signals.

  • Review safety notesRequired

    Safety notes are present.

    Done
  • Review privacy notesRequired

    Privacy notes are present.

    Done
  • Verify package integrity metadata

    No package verification/checksum metadata.

    Pending

Rollout

Adopt in controlled steps based on the selected plan.

  • Run in isolated sandbox firstRequired

    Use a constrained sandbox and observe behavior across multiple tasks.

    Pending
  • Roll out graduallyRequired

    Roll out to a small cohort before wider usage.

    Pending
  • Set monitoring and fallback

    Define rollback path and monitor errors after adoption.

    Pending

Evidence readiness

Evidence readiness matrix · balanced

Required evidence gates are covered (5/6 signals complete).

Risk 15

Source provenance

Present

Source repository/provenance is listed.

Required in this preset

Metadata review

Present

Review metadata is present.

Required in this preset

Safety notes

Present

Safety notes are present.

Required in this preset

Privacy notes

Present

Privacy notes are present.

Optional in this preset

Package integrity

Missing

Package integrity metadata is missing.

Optional in this preset

Install payload

Present

Install payload is available.

Required in this preset

Required evidence gates are covered for this preset.

Decision timeline

Decision timeline · balanced

5/6 steps complete with no blocking gaps for this preset.

Risk 14

triage

Confirm source provenanceRequired

Source/provenance metadata is available.

Done

triage

Check metadata review statusRequired

Review metadata is available.

Done

verify

Review safety notesRequired

Safety notes are available.

Done

verify

Review privacy notes

Privacy notes are available.

Done

verify

Validate package integrity metadata

Package integrity metadata is missing.

Pending

rollout

Verify install payload and commandsRequired

Install payload is available.

Done

No required blockers for this timeline preset.

Prerequisite readiness

Prerequisite readiness

4 prerequisites to line up before setup. Have accounts and credentials ready first.

0/4 ready
Account & credentials2Configuration1General1

Safety & privacy surface

Safety & privacy surface

3 safety and 3 privacy notes across 5 risk areas. Review closely: credentials & tokens, network access.

5 areas
  • SafetyGeneralKeep model output reviewable before it triggers irreversible product actions, external messages, or billing-sensitive work.
  • SafetyLocal filesStore only the durable state the agent needs; avoid persisting full prompts, files, or transcripts when summaries or structured state are enough.
  • SafetyGeneralAdd idempotency and replay handling for events that may retry, arrive out of order, or resume after an agent instance restarts.
  • PrivacyNetwork accessWorkers logs, Durable Object storage, Workers AI prompts, model outputs, request headers, and bound service data may contain user or business context.
  • PrivacyData retentionRedact sensitive fields before logging and define retention for prompts, intermediate reasoning, tool results, and conversation state.
  • PrivacyCredentials & tokensSeparate staging and production state so test prompts and generated outputs cannot leak into live sessions.

Safety notes

  • Keep model output reviewable before it triggers irreversible product actions, external messages, or billing-sensitive work.
  • Store only the durable state the agent needs; avoid persisting full prompts, files, or transcripts when summaries or structured state are enough.
  • Add idempotency and replay handling for events that may retry, arrive out of order, or resume after an agent instance restarts.

Privacy notes

  • Workers logs, Durable Object storage, Workers AI prompts, model outputs, request headers, and bound service data may contain user or business context.
  • Redact sensitive fields before logging and define retention for prompts, intermediate reasoning, tool results, and conversation state.
  • Separate staging and production state so test prompts and generated outputs cannot leak into live sessions.

Prerequisites

  • A Cloudflare account with Workers, Workers AI, and Durable Objects available for the target environment.
  • Wrangler and a Worker project configured for TypeScript or JavaScript.
  • A clear state boundary, such as one agent per user, workspace, conversation, job, or document.
  • Test prompts, expected model responses, and sample state transitions for local or staging validation.

Schema details

Install type
copy
Reading time
8 min
Difficulty score
63
Troubleshooting
Yes
Breaking changes
No
Skill and platform metadata
Retrieval sources
https://developers.cloudflare.com/agents/https://developers.cloudflare.com/agents/api-reference/store-and-sync-state/https://developers.cloudflare.com/workers-ai/https://developers.cloudflare.com/workers-ai/get-started/workers-wrangler/https://developers.cloudflare.com/durable-objects/
Full copyable content
## TL;DR

Cloudflare Workers can handle the request path, Workers AI can run model
inference, and Durable Objects or the Agents runtime can hold the state that
needs to survive between requests. The design trick is to keep the model call
stateless and make the agent state explicit: session facts, workflow progress,
tool results, retry markers, and user-visible decisions.

Use this guide when you want an edge-deployed agent that can remember where it
is in a task without turning every prompt into a large, fragile transcript.

## Prerequisites & Requirements

- [ ] {"task": "Cloudflare project", "description": "Workers, Workers AI, and Durable Objects are available in the account/environment"}
- [ ] {"task": "Wrangler config", "description": "Bindings for Workers AI, Durable Objects, and any storage services are configured per environment"}
- [ ] {"task": "State model", "description": "You know whether state is scoped by user, workspace, conversation, job, or document"}
- [ ] {"task": "Evaluation data", "description": "Sample prompts and expected state transitions exist for local or staging checks"}

## Core Concepts Explained

### Workers handle the edge request path

Workers are the HTTP entry point for your agent. They route requests, validate
input, call the right Agent or Durable Object instance, and return a response to
the client.

### Workers AI handles inference

Workers AI is the model execution layer. Keep calls to the model explicit and
record the metadata you need to debug outputs later, such as model name, prompt
version, request id, latency, and outcome category.

### Durable state belongs outside the prompt

Prompts are context, not a database. Durable Objects and the Agents runtime give
you a place to store state that must survive a request: workflow step, compact
memory, preferences, pending tool results, retry markers, and approval status.

### Bindings make dependencies visible

Cloudflare bindings connect a Worker to platform resources such as Workers AI,
Durable Objects, D1, KV, R2, Queues, or environment-specific configuration.
Keeping those dependencies in bindings makes deployments easier to review than
hidden service URLs scattered through code.

## Step-by-Step Implementation Guide

1. **Choose the agent identity.** Decide what one durable agent represents: a
   user, conversation, workspace, document, long-running job, or external
   workflow. This identity determines the Durable Object key or Agent instance
   you route to.

2. **Define the state schema.** Start with structured fields instead of a raw
   transcript. Useful fields include `status`, `summary`, `pendingAction`,
   `lastModel`, `promptVersion`, `lastError`, `retryCount`, and a compact list
   of facts the agent must remember.

3. **Configure bindings per environment.** Bind Workers AI for inference and the
   Durable Object or Agents runtime for state. Keep staging and production
   bindings separate so test runs cannot touch live state.

4. **Route requests through the state owner.** The Worker should validate input,
   identify the agent instance, load or update state, call Workers AI when
   needed, and write back the resulting state transition.

5. **Keep model prompts small and sourced from state.** Build each model prompt
   from the current request, compact durable state, and any retrieved facts. Do
   not rely on a growing conversation transcript as the only memory layer.

6. **Make tool and event handling idempotent.** Store request ids, step ids, or
   external event ids so retries do not duplicate user-visible work. If a model
   response proposes an action, save the proposal and require a separate
   confirmation path for important actions.

7. **Log operational metadata.** Use Workers logs to capture request ids, agent
   ids, state version, model, latency, outcome, and error class. Redact prompt
   content and user data unless your team has a clear retention policy.

8. **Test state transitions, not just responses.** A good test checks that the
   agent moves from one durable state to the next after a prompt, retry, timeout,
   or invalid model output.

9. **Add migration and reset paths.** Durable state lives beyond one deploy.
   Keep versioned state readers, a migration plan for schema changes, and a
   reset path for broken or abandoned agent instances.

## Reference Implementation

The Agents SDK (`agents` package) gives you an `Agent` class with built-in
durable state. Each agent instance has typed state via `initialState`,
`this.state`, and `this.setState`, plus a private embedded SQLite database via
`this.sql`. State is automatically persisted, so it survives across requests and
agent restarts without a separate store. The example below keeps a compact
session record in state and calls Workers AI for inference.

```typescript
import { Agent, routeAgentRequest } from "agents";

interface Env {
  AI: Ai;
}

interface SessionState {
  status: "idle" | "working" | "done";
  summary: string;
  turns: number;
  lastModel: string;
}

export class AssistantAgent extends Agent<Env, SessionState> {
  // Persisted automatically and available on every request as this.state.
  initialState: SessionState = {
    status: "idle",
    summary: "",
    turns: 0,
    lastModel: "",
  };

  async onRequest(request: Request): Promise<Response> {
    const { prompt } = (await request.json()) as { prompt: string };

    // Build the model input from durable state, not a growing transcript.
    const model = "@cf/meta/llama-3.1-8b-instruct";
    const response = await this.env.AI.run(model, {
      prompt: `Context summary: ${this.state.summary}\nUser: ${prompt}`,
    });

    // Write the next durable state transition.
    this.setState({
      ...this.state,
      status: "working",
      turns: this.state.turns + 1,
      lastModel: model,
    });

    return Response.json({ response, turns: this.state.turns });
  }
}

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    // Routes to the right agent instance by name, creating it on first use.
    return (
      (await routeAgentRequest(request, env)) ||
      new Response("Not found", { status: 404 })
    );
  },
} satisfies ExportedHandler<Env>;
```

Bind Workers AI in your Wrangler config so `this.env.AI` resolves at runtime:

```toml
[ai]
binding = "AI"
```

For relational reads and writes that should not live in the state object, each
agent instance exposes a private SQLite database through `this.sql`:

```typescript
const [user] = this.sql<User>`SELECT * FROM users WHERE id = ${userId}`;
this.sql`INSERT INTO messages (id, text) VALUES (${id}, ${text})`;
```

## Where State Should Live

The platform gives you several places to keep agent state. Pick the narrowest
one that fits the access pattern.

| Layer | API surface | Scope / consistency | Best for |
| --- | --- | --- | --- |
| Agent state | `this.state` / `this.setState` (Agents SDK) | Per-agent instance, auto-persisted, synced to clients | Compact session memory, workflow status, counters |
| Agent SQL | `this.sql` (embedded SQLite per instance) | Per-agent instance, strongly consistent | Relational per-agent records, structured history |
| Durable Object storage | `ctx.storage` Storage API (incl. `sql.exec`) | Per-object, strongly consistent | Custom state machines outside the Agents SDK |
| D1 | `env.DB` binding | Shared across Workers, serverless SQL | Cross-agent / global relational data |
| KV | `env.KV` binding | Eventually consistent, global reads | Config, feature flags, cacheable lookups |
| R2 | `env.BUCKET` binding | Object storage | Large files, artifacts, exports |

The Agents SDK builds on Durable Objects, so `this.state` and `this.sql` are
durable per agent identity. Reach for raw Durable Object `ctx.storage` only when
you need a custom object outside the SDK; use D1, KV, or R2 for data that must be
shared beyond a single agent instance.

## Architecture Checklist

- [ ] {"task": "Agent identity is stable", "description": "Every request routes to the intended user, conversation, job, or workspace instance"}
- [ ] {"task": "State is structured", "description": "Durable memory uses fields and compact summaries instead of unbounded transcripts"}
- [ ] {"task": "Bindings are explicit", "description": "Workers AI, Durable Objects, and storage services are configured through environment bindings"}
- [ ] {"task": "Model calls are observable", "description": "Model name, prompt version, latency, outcome, and error class are logged without sensitive prompt text"}
- [ ] {"task": "Retries are safe", "description": "Events and tool proposals include ids so duplicate delivery does not duplicate work"}
- [ ] {"task": "State versions are handled", "description": "The app can read old state and migrate or reset it safely"}
- [ ] {"task": "Staging is isolated", "description": "Test prompts, state, and logs stay separate from production sessions"}

## When to Use This Pattern

Use Workers AI plus durable state when:

- The agent must remember progress across HTTP requests or WebSocket messages.
- A user may close the client and return to the same task later.
- The model call can be stateless, but the workflow cannot.
- You need an edge-hosted runtime with platform bindings and deployable
  observability.

Choose a simpler stateless Worker when:

- Each request can be answered from the request body alone.
- There is no need to resume, retry, compact, or inspect agent state.
- Logs and analytics are enough to understand behavior after the response.

## Troubleshooting

- **The agent forgets previous work**: check that state is written after each
  transition and that requests route to the same durable identity.
- **State grows too quickly**: replace raw transcripts with summaries, facts,
  counters, and links to external records.
- **Retries duplicate actions**: store request or event ids before performing
  user-visible work.
- **A deploy breaks old sessions**: add state-version handling and migrate old
  records lazily when the agent loads them.
- **Logs are too noisy or sensitive**: log ids, versions, timings, and outcome
  classes, then keep prompt content out of default logs.

## Duplicate Check

This guide is distinct from existing Cloudflare tool and skill entries. Those
entries describe Cloudflare Agents SDK, Workers AI, deploy readiness, or general
Cloudflare capability packs; this entry is a guide for designing the durable
state boundary of a Workers AI agent and validating the resulting architecture.

## References

- Cloudflare Agents documentation - https://developers.cloudflare.com/agents/
- Agents: store and sync state - https://developers.cloudflare.com/agents/api-reference/store-and-sync-state/
- Cloudflare Workers AI - https://developers.cloudflare.com/workers-ai/
- Workers AI with Wrangler - https://developers.cloudflare.com/workers-ai/get-started/workers-wrangler/
- Cloudflare Durable Objects - https://developers.cloudflare.com/durable-objects/
- Workers bindings - https://developers.cloudflare.com/workers/runtime-apis/bindings/
- Workers Logs - https://developers.cloudflare.com/workers/observability/logs/workers-logs/

About this resource

TL;DR

Cloudflare Workers can handle the request path, Workers AI can run model inference, and Durable Objects or the Agents runtime can hold the state that needs to survive between requests. The design trick is to keep the model call stateless and make the agent state explicit: session facts, workflow progress, tool results, retry markers, and user-visible decisions.

Use this guide when you want an edge-deployed agent that can remember where it is in a task without turning every prompt into a large, fragile transcript.

Prerequisites & Requirements

  • {"task": "Cloudflare project", "description": "Workers, Workers AI, and Durable Objects are available in the account/environment"}
  • {"task": "Wrangler config", "description": "Bindings for Workers AI, Durable Objects, and any storage services are configured per environment"}
  • {"task": "State model", "description": "You know whether state is scoped by user, workspace, conversation, job, or document"}
  • {"task": "Evaluation data", "description": "Sample prompts and expected state transitions exist for local or staging checks"}

Core Concepts Explained

Workers handle the edge request path

Workers are the HTTP entry point for your agent. They route requests, validate input, call the right Agent or Durable Object instance, and return a response to the client.

Workers AI handles inference

Workers AI is the model execution layer. Keep calls to the model explicit and record the metadata you need to debug outputs later, such as model name, prompt version, request id, latency, and outcome category.

Durable state belongs outside the prompt

Prompts are context, not a database. Durable Objects and the Agents runtime give you a place to store state that must survive a request: workflow step, compact memory, preferences, pending tool results, retry markers, and approval status.

Bindings make dependencies visible

Cloudflare bindings connect a Worker to platform resources such as Workers AI, Durable Objects, D1, KV, R2, Queues, or environment-specific configuration. Keeping those dependencies in bindings makes deployments easier to review than hidden service URLs scattered through code.

Step-by-Step Implementation Guide

  1. Choose the agent identity. Decide what one durable agent represents: a user, conversation, workspace, document, long-running job, or external workflow. This identity determines the Durable Object key or Agent instance you route to.

  2. Define the state schema. Start with structured fields instead of a raw transcript. Useful fields include status, summary, pendingAction, lastModel, promptVersion, lastError, retryCount, and a compact list of facts the agent must remember.

  3. Configure bindings per environment. Bind Workers AI for inference and the Durable Object or Agents runtime for state. Keep staging and production bindings separate so test runs cannot touch live state.

  4. Route requests through the state owner. The Worker should validate input, identify the agent instance, load or update state, call Workers AI when needed, and write back the resulting state transition.

  5. Keep model prompts small and sourced from state. Build each model prompt from the current request, compact durable state, and any retrieved facts. Do not rely on a growing conversation transcript as the only memory layer.

  6. Make tool and event handling idempotent. Store request ids, step ids, or external event ids so retries do not duplicate user-visible work. If a model response proposes an action, save the proposal and require a separate confirmation path for important actions.

  7. Log operational metadata. Use Workers logs to capture request ids, agent ids, state version, model, latency, outcome, and error class. Redact prompt content and user data unless your team has a clear retention policy.

  8. Test state transitions, not just responses. A good test checks that the agent moves from one durable state to the next after a prompt, retry, timeout, or invalid model output.

  9. Add migration and reset paths. Durable state lives beyond one deploy. Keep versioned state readers, a migration plan for schema changes, and a reset path for broken or abandoned agent instances.

Reference Implementation

The Agents SDK (agents package) gives you an Agent class with built-in durable state. Each agent instance has typed state via initialState, this.state, and this.setState, plus a private embedded SQLite database via this.sql. State is automatically persisted, so it survives across requests and agent restarts without a separate store. The example below keeps a compact session record in state and calls Workers AI for inference.

import { Agent, routeAgentRequest } from "agents";

interface Env {
  AI: Ai;
}

interface SessionState {
  status: "idle" | "working" | "done";
  summary: string;
  turns: number;
  lastModel: string;
}

export class AssistantAgent extends Agent<Env, SessionState> {
  // Persisted automatically and available on every request as this.state.
  initialState: SessionState = {
    status: "idle",
    summary: "",
    turns: 0,
    lastModel: "",
  };

  async onRequest(request: Request): Promise<Response> {
    const { prompt } = (await request.json()) as { prompt: string };

    // Build the model input from durable state, not a growing transcript.
    const model = "@cf/meta/llama-3.1-8b-instruct";
    const response = await this.env.AI.run(model, {
      prompt: `Context summary: ${this.state.summary}\nUser: ${prompt}`,
    });

    // Write the next durable state transition.
    this.setState({
      ...this.state,
      status: "working",
      turns: this.state.turns + 1,
      lastModel: model,
    });

    return Response.json({ response, turns: this.state.turns });
  }
}

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    // Routes to the right agent instance by name, creating it on first use.
    return (
      (await routeAgentRequest(request, env)) ||
      new Response("Not found", { status: 404 })
    );
  },
} satisfies ExportedHandler<Env>;

Bind Workers AI in your Wrangler config so this.env.AI resolves at runtime:

[ai]
binding = "AI"

For relational reads and writes that should not live in the state object, each agent instance exposes a private SQLite database through this.sql:

const [user] = this.sql<User>`SELECT * FROM users WHERE id = ${userId}`;
this.sql`INSERT INTO messages (id, text) VALUES (${id}, ${text})`;

Where State Should Live

The platform gives you several places to keep agent state. Pick the narrowest one that fits the access pattern.

Layer API surface Scope / consistency Best for
Agent state this.state / this.setState (Agents SDK) Per-agent instance, auto-persisted, synced to clients Compact session memory, workflow status, counters
Agent SQL this.sql (embedded SQLite per instance) Per-agent instance, strongly consistent Relational per-agent records, structured history
Durable Object storage ctx.storage Storage API (incl. sql.exec) Per-object, strongly consistent Custom state machines outside the Agents SDK
D1 env.DB binding Shared across Workers, serverless SQL Cross-agent / global relational data
KV env.KV binding Eventually consistent, global reads Config, feature flags, cacheable lookups
R2 env.BUCKET binding Object storage Large files, artifacts, exports

The Agents SDK builds on Durable Objects, so this.state and this.sql are durable per agent identity. Reach for raw Durable Object ctx.storage only when you need a custom object outside the SDK; use D1, KV, or R2 for data that must be shared beyond a single agent instance.

Architecture Checklist

  • {"task": "Agent identity is stable", "description": "Every request routes to the intended user, conversation, job, or workspace instance"}
  • {"task": "State is structured", "description": "Durable memory uses fields and compact summaries instead of unbounded transcripts"}
  • {"task": "Bindings are explicit", "description": "Workers AI, Durable Objects, and storage services are configured through environment bindings"}
  • {"task": "Model calls are observable", "description": "Model name, prompt version, latency, outcome, and error class are logged without sensitive prompt text"}
  • {"task": "Retries are safe", "description": "Events and tool proposals include ids so duplicate delivery does not duplicate work"}
  • {"task": "State versions are handled", "description": "The app can read old state and migrate or reset it safely"}
  • {"task": "Staging is isolated", "description": "Test prompts, state, and logs stay separate from production sessions"}

When to Use This Pattern

Use Workers AI plus durable state when:

  • The agent must remember progress across HTTP requests or WebSocket messages.
  • A user may close the client and return to the same task later.
  • The model call can be stateless, but the workflow cannot.
  • You need an edge-hosted runtime with platform bindings and deployable observability.

Choose a simpler stateless Worker when:

  • Each request can be answered from the request body alone.
  • There is no need to resume, retry, compact, or inspect agent state.
  • Logs and analytics are enough to understand behavior after the response.

Troubleshooting

  • The agent forgets previous work: check that state is written after each transition and that requests route to the same durable identity.
  • State grows too quickly: replace raw transcripts with summaries, facts, counters, and links to external records.
  • Retries duplicate actions: store request or event ids before performing user-visible work.
  • A deploy breaks old sessions: add state-version handling and migrate old records lazily when the agent loads them.
  • Logs are too noisy or sensitive: log ids, versions, timings, and outcome classes, then keep prompt content out of default logs.

Duplicate Check

This guide is distinct from existing Cloudflare tool and skill entries. Those entries describe Cloudflare Agents SDK, Workers AI, deploy readiness, or general Cloudflare capability packs; this entry is a guide for designing the durable state boundary of a Workers AI agent and validating the resulting architecture.

References

Source citations

Add this badge to your README

Show that Build Cloudflare Workers AI Agents With Durable State is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.

Listed on HeyClaude
[![Listed on HeyClaude](https://heyclau.de/badge/guides/cloudflare-workers-ai-agents-durable-state.svg)](https://heyclau.de/entry/guides/cloudflare-workers-ai-agents-durable-state)

How it compares

Build Cloudflare Workers AI Agents With Durable State side by side with 3 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.

3 trust signals differ across this comparison (Package trust, Source provenance, Submitter).

Next steps differ across entries — use the actions in the table below to copy install commands and source links per resource.

Field

A practical architecture guide for building AI agents on Cloudflare Workers with Workers AI inference and durable per-agent state. Use the Agents API, Durable Objects, bindings, and Workers observability to keep agent sessions reliable across requests.

Open dossier

Run AI inference and serverless functions on Cloudflare Workers AI: call hosted models like Llama, Whisper, and Stable Diffusion through the Workers AI binding, deploy with wrangler, and use D1/R2/KV storage plus the free daily Neuron allocation.

Open dossier

Cloudflare framework for building, deploying, and running AI agents on Workers with durable platform primitives.

Open dossier

Expert Cloudflare capability skill for designing workers that combine D1, KV, and R2 with clear consistency, caching, and security boundaries.

Open dossier
Next stepsDiffers
Trust
Review statusReviewedMaintainer reviewedReviewedMaintainer reviewedReviewedMaintainer reviewedReviewedMaintainer reviewed
Package trustDiffersPackage not verifiedPackage verified2025-10-16Package not verifiedPackage verified2026-04-10
Source provenanceDiffersSource-backedNo submission linkSource-backedNo submission link
SubmitterDiffersMkDev11
Install riskReview firstLow riskReview firstLow risk
Notes Safety ✓ Privacy ✓ Safety ✓ Privacy ✓ Safety · Privacy · Safety ✓ Privacy ✓
BrandCloudflare logoCloudflareCloudflare logoCloudflareCloudflare logoCloudflareCloudflare logoCloudflare
Categoryguidesskillstoolsskills
SourceSource-backedFirst-partySource-backedFirst-party
AuthorMkDev11JSONboredCloudflareJSONbored
Added2026-06-042025-10-162026-04-272026-04-10
Platforms
Harness
Source repo
Safety notesKeep model output reviewable before it triggers irreversible product actions, external messages, or billing-sensitive work. Store only the durable state the agent needs; avoid persisting full prompts, files, or transcripts when summaries or structured state are enough. Add idempotency and replay handling for events that may retry, arrive out of order, or resume after an agent instance restarts.Deploying with wrangler writes Workers and bindings to your Cloudflare account; review what you deploy, since it serves live traffic. Running Workers AI models consumes paid Neurons beyond the free daily allocation; set usage expectations before deploying inference at scale.— missingMay produce commands or configuration for live infrastructure, CI, releases, or indexing; test changes in staging or dry-run mode first. Use least-privilege API tokens and review workflow, deploy, DNS, cache, and release changes before applying them to production.
Privacy notesWorkers logs, Durable Object storage, Workers AI prompts, model outputs, request headers, and bound service data may contain user or business context. Redact sensitive fields before logging and define retention for prompts, intermediate reasoning, tool results, and conversation state. Separate staging and production state so test prompts and generated outputs cannot leak into live sessions.Requests sent to Workers AI models are processed on Cloudflare's network; review what data your function forwards to the model. Keep Cloudflare API tokens in wrangler's secret store or environment variables, never hard-coded or committed.— missingInputs can include repository metadata, workflow logs, deployment settings, domain names, analytics exports, and service configuration. Redact tokens, account IDs, private URLs, customer data, and proprietary deployment details before sharing generated reports or prompts.
Prerequisites
  • A Cloudflare account with Workers, Workers AI, and Durable Objects available for the target environment.
  • Wrangler and a Worker project configured for TypeScript or JavaScript.
  • A clear state boundary, such as one agent per user, workspace, conversation, job, or document.
  • Test prompts, expected model responses, and sample state transitions for local or staging validation.
  • Cloudflare account
  • Wrangler CLI 3.0+
  • Node.js 18+
  • @cloudflare/workers-types
— none listed
  • Cloudflare account and worker project
  • D1/KV/R2 bindings access
  • Defined data model and SLA targets
Install
npm install -g wrangler
curl -L https://heyclau.de/downloads/skills/cloudflare-workers-d1-kv-r2-capability-pack.zip -o cloudflare-workers-d1-kv-r2-capability-pack.zip && unzip -o cloudflare-workers-d1-kv-r2-capability-pack.zip -d ./cloudflare-workers-d1-kv-r2-capability-pack
Config
Citations
ClaimUnclaimedUnclaimedUnclaimedUnclaimed
Open 4 picks in the interactive comparison tool

Related guides

Signals

Loading live community signals…

More like this, weekly

A short, calm digest of reviewed Claude resources. Unsubscribe any time.