• 1 min read

Edge AI Chat Agent

A chat agent that runs entirely on Cloudflare: Workers, a Durable Object for conversation memory, and Llama 3.3 70B on Workers AI.

Cloudflare WorkersDurable ObjectsAgents SDKWorkers AITypeScript

What it is

A small chat assistant for questions about the Cloudflare developer platform, built on Cloudflare end to end. I built it in a day.

How it works

  • Worker. Routes WebSocket upgrades to the agent. It also has a plain POST /api/chat fallback that calls the agent over RPC.
  • Durable Object. One ChatAgent per session holds the message history. I chose it over KV or D1 because each new message has to see the previous one, and a Durable Object gives read-after-write consistency without fetching the whole history on every request.
  • Streaming. The agent reads the Workers AI server-sent events, sends each token to the browser as it arrives, then saves the full reply to state.
  • Front end. One static page on Cloudflare Pages that renders replies as Markdown.

Stack

TypeScript, Cloudflare Workers, Durable Objects (SQLite), Agents SDK, Workers AI, Cloudflare Pages, Wrangler.

Back to top