Building Durable and Stateful Agents
From platform primitives to a deployed AI Agent.
Cloudflare
DEVELOPER WORKSHOP
01 / HANDS-ON WORKSHOP
01
Cloudflare
Meet the team
DEVELOPER WORKSHOP
MEET THE TEAM
02
Your Cloudflare team.
Portrait of Anu Razdan
Anu Razdan
Named Account Executive
anu@cloudflare.com
Portrait of Terry Mathew
Terry Mathew
Customer Engineer
tmathew@cloudflare.com
Portrait of Nikhil Buddhavarapu
Nikhil Buddhavarapu
CE, Developer & AI
nbuddhavarapu@cloudflare.com
Cloudflare
The route / 90 minutes
Understand. Build. Extend.
One application. Small changes. Observable results.

01 Foundations

Workers, bindings, storage, stateful compute.

02 Build the agent

Start with a wired agent. Add state, memory, tools and scheduling.

03 Beyond the lab

Internal app-building with VibeSDK and Void Platform.

15 min primer · 55 min build · 8 min platform discussion · 12 min questions / buffer
DEVELOPER WORKSHOP
THE ROUTE / 90 MINUTES
03
Cloudflare
Before you start
Three steps before you build.
Use your favourite editor or coding agent. OpenCode access is linked below.

Sign up for a free Cloudflare account

Local tools

Node.js 24+ and Git. Use the repo’s AGENTS.md with your coding agent.

Accept the lab invite

Create your Cloudflare login first, then accept your workshop lab invite.

DEVELOPER WORKSHOP
BEFORE YOU START
04
dash.cloudflare.com/sign-up
OPENCODE ACCESSOpenCodehttps://opencode.cf.prompt2prod.dev/
Cloudflare
Platform primer
A small set of composable primitives.
Compute + storage + AI. Pick the boundary that matches the job.
COMPUTE
STORAGE
AI + CONTROL

Workers

Request handlers + APIs

Durable Objects

Identity + stateful compute

Containers / Sandboxes

Linux execution + isolated code

R2

Object storage + artifacts

D1

Relational application data

KV

Read-heavy configuration

Workers AI

Model inference

AI Gateway

Model traffic + observability

Agents SDK / Workflows

Agent runtime + durable orchestration

DEVELOPER WORKSHOP
PLATFORM PRIMER
05
Cloudflare
Workers / the full-stack ecosystem
DEVELOPER WORKSHOP
WORKERS / THE FULL-STACK ECOSYSTEM
06
Workers runs full-stack applications.
Bring your framework. Add server rendering, APIs, assets and platform bindings.
React logo
ReactClient UI + Worker API
TanStack Start logo
TanStack StartSSR + server functions
Astro logo
AstroCloudflare adapter
Next.js logo
Next.jsvinext / OpenNext paths
vinext
vinextVite-based · beta · check compatibility
SvelteKit logo
SvelteKitadapter-cloudflare
Vue logo
VueVite SPA · Nuxt for SSR
Hono logo
HonoAPIs + middleware
Vite logo
ViteCloudflare Vite plugin
Framework support ≠ identical features. Choose the adapter and test the runtime compatibility.
Cloudflare
Bindings / the connective tissue
Everything is a binding.
Your Worker in the center. Capabilities on env. No resource API keys in your code.
DEVELOPER WORKSHOP
BINDINGS / THE CONNECTIVE TISSUE
07
WorkerenvR2env.BUCKETD1env.DBKVenv.CONFIGAIenv.AIDOenv.ROOMS
Capabilities on env · configured in Wrangler
● ● ●src/index.ts · all five bindings
export default {
  async fetch(req: Request, env: Env) {
    const flags = await env.CONFIG.get("flags", "json");
    await env.BUCKET.put("hello.txt", "Hello");
    const rows = await env.DB.prepare("SELECT 1").all();
    const ai = await env.AI.run(
      "@cf/zai-org/glm-4.7-flash",
      { messages: [{ role: "user", content: "Hi" }] }
    );
    const room = env.ROOMS.getByName("demo");
    const state = await room.fetch("https://room/state");
    return Response.json({ flags, rows, ai, ok: state.ok });
  }
} satisfies ExportedHandler<Env>;
Cloudflare
Wrangler / project configuration
Wrangler: configure, develop, deploy.
Wrangler is Cloudflare’s CLI. wrangler.jsonc defines your Worker, bindings and deployment settings.
DEVELOPER WORKSHOP
WRANGLER / PROJECT CONFIGURATION
08
● ● ●wrangler.jsonc · starter configuration excerpt
{
  "name": "cloudflare-agent-starter",
  "main": "src/server.ts",
  "compatibility_date": "2026-10-19",
  "ai": { "binding": "AI", "remote": true },
  "vars": { "AI_GATEWAY_ID": "<lab-gateway-id>" },
  "durable_objects": { "bindings": [
    { "name": "Assistant", "class_name": "Assistant" }
  ] }
}
A CLI + A CONFIG FILE
01
Configure

wrangler.jsonc declares the Worker and its bindings.

02
Develop locally

npm run dev uses Vite + Cloudflare tooling.

03
Build and deploy

npm run deploy builds and runs Wrangler.

CONFIGURATION / Entry point · runtime compatibility · bindings · variables · deployment environments
Use the repo’s complete config, including migrations. Set AI_GATEWAY_ID for your assigned lab account.
Cloudflare
Workshop / the starter
DEVELOPER WORKSHOP
WORKSHOP / THE STARTER
09
Start with a working agent.
Four checkpoints. One durable, stateful AI agent.
Streaming chat. Persistent conversations. Every model call through AI Gateway.
Agents SDK + Think provide the chat loop, WebSocket sync and message storage. You add the capabilities—not the plumbing.
STARTER REPOSITORYGitHubhttps://github.com/vnikhilbuddhavarapu/cloudflare-agent-starter
OPENCODE ACCESSOpenCodehttps://opencode.cf.prompt2prod.dev/
ONE INSTANCE NAME → ONE DURABLE OBJECT
01
Browser

Chat, streaming replies and WebSocket sync.

02
Assistant · Durable Object

Named compute with its own built-in SQLite.

03
Agents SDK + Think

Chat loop, transcript storage and tool execution.

04
AI Gateway → Workers AI

Every model call follows the configured gateway.

Each conversation has its own named agent and SQLite database. Each exercise has a test to turn green.
Cloudflare
CP01 / Validated shared settings
DEVELOPER WORKSHOP
CP01 / VALIDATED SHARED SETTINGS
10
One setting. Every tab.
Validated shared settings · add one capability, then prove it.
Add a response style: concise or detailed.
AGENT STATE / setState · validateStateChange · @callable
The browser requests a change. The server validates it, saves it and broadcasts the new state.
● ● ●CHECKPOINT TEST · red → green
npm run test:cp01
CP01 / FOLLOW THE CAPABILITY
01
Request a style

The browser calls a narrow server method.

02
Validate server-owned state

Reject direct client writes and invalid values.

03
Save + broadcast

Every tab on this instance sees the same setting.

PROVE IT
Change style in tab A → tab B updates. Refresh → the setting remains.
CP01 GUIDEGitHubOpen checkpoint instructions ↗
Cloudflare
CP02 / Bounded memory
DEVELOPER WORKSHOP
CP02 / BOUNDED MEMORY
11
Remember beyond the conversation.
Bounded memory · add one capability, then prove it.
Give the agent memory that is not chat history.
THINK CONTEXT BLOCK / bounded · writable · SQLite-backed
The model writes durable preferences into a context block. A token budget keeps that memory bounded.
● ● ●CHECKPOINT TEST · red → green
npm run test:cp02
CP02 / FOLLOW THE CAPABILITY
01
Write a preference

The model uses set_context to update memory.

02
Enforce the budget

Writes beyond the 1,000-token limit are rejected.

03
Recall on a later turn

SQLite memory survives clearing chat history.

PROVE IT
Save a preference → clear the chat → ask again. The preference survives.
CP02 GUIDEGitHubOpen checkpoint instructions ↗
Cloudflare
CP03 / Typed note tools
DEVELOPER WORKSHOP
CP03 / TYPED NOTE TOOLS
12
Useful tools. Checked inputs.
Typed note tools · add one capability, then prove it.
Let the model save and list durable notes.
AI SDK tool() / Zod schemas · SQLite · toolCallId
Validate the inputs, store the record and return structured results. A retry with the same call ID returns the original note.
● ● ●CHECKPOINT TEST · red → green
npm run test:cp03
CP03 / FOLLOW THE CAPABILITY
01
Validate with Zod

Trim and bound the note title and body.

02
Save once in SQLite

Use toolCallId as the operation key.

03
Return a tool result

The chat renders the input and structured result.

PROVE IT
Run the direct tool test. Then ask the model: a tool card and one saved note appear.
CP03 GUIDEGitHubOpen checkpoint instructions ↗
Cloudflare
CP04 / Durable reminders
DEVELOPER WORKSHOP
CP04 / DURABLE REMINDERS
13
Close the tab. Keep the promise.
Durable reminders · add one capability, then prove it.
Schedule reminders that outlive the browser.
this.schedule() / durable alarm · idempotent completion
A persisted schedule wakes the Durable Object when due. Completion is stored before clients are notified—and is safe to repeat.
● ● ●CHECKPOINT TEST · red → green
npm run test:cp04
CP04 / FOLLOW THE CAPABILITY
01
Register durable work

Validate the delay; this.schedule() takes seconds.

02
Wake the named agent

The alarm fires even with no connected tabs.

03
Complete idempotently

Persist pending → completed once; ignore repeats.

PROVE IT
Ask for 20 seconds → close every tab → reopen after it’s due. Status: completed.
CP04 GUIDEGitHubOpen checkpoint instructions ↗
Cloudflare
Beyond the workshop / agent capabilities
DEVELOPER WORKSHOP
BEYOND THE WORKSHOP / AGENT CAPABILITIES
14
Your agent can do more.
New channels. Longer-running work. Specialist agents.
CHANNELS + HUMAN OVERSIGHT
MORE WAYS TO GET WORK DONE

Email

Inbound mail + replies

Voice

Streaming speech · beta

Video

RealtimeKit / WebRTC

HITL

Human-in-the-loop approvals

Fibers

Checkpoint + recover work

Sub-agents

Delegate with isolated state

MCP tools

Connect external capabilities

Workflows

Durable steps + retries

Explore the Agents SDK primitives ↗
Cloudflare
CP05 / Deploy and submit
DEVELOPER WORKSHOP
CP05 / DEPLOY AND SUBMIT
15
Ship it. Share what you built.
Deploy your agent, then submit it with a short description of what you built.

Deploy

  • Set AI_GATEWAY_ID in wrangler.jsonc
  • Run npm run deploy to get your workers.dev URL
  • Open it, chat, and check your checkpoints work live

Submit

  • Your deployed URL
  • GitHub repo or code link, if shareable
  • A 2–3 sentence description of your agent
  • Checkpoints or stretch goals completed
CP05 GUIDEGitHubOpen deploy and submit instructions ↗
PROJECT SUBMISSION FORMhttps://forms.gle/B9PYQHPZwYJAsxFq9
No login by default: protect longer-lived deployments with Cloudflare Access or AI Gateway rate limits.
Cloudflare
DEVELOPER WORKSHOP
THANK YOU
16
Thank you!