Cloudflare Agents: Build and Deploy AI Agents on Cloudflare’s Edge
Cloudflare Agents is a managed platform for deploying AI agents. The platform runs on Cloudflare’s edge network. The agents are written in TypeScript or Python. The agents can use Cloudflare Workers, Cloudflare D1 (the SQLite-based database), Cloudflare R2 (the S3-compatible object store), and Cloudflare AI Gateway. The deployment is one command. The pricing is usage-based with a generous free tier. After two months of running several production agents on the platform, I have a clear view of what works and what does not. This is what Cloudflare Agents does, what it costs, and the trade-offs.
What Cloudflare Agents actually is
The platform is a managed runtime for AI agents. The agents are defined as code (TypeScript or Python). The code is deployed via Wrangler (Cloudflare’s CLI). The agents run on Cloudflare Workers (V8 isolates, fast cold start, low memory). The agents can use any Cloudflare product (D1, R2, KV, Durable Objects, AI Gateway). The agents can call any LLM (OpenAI, Anthropic, Workers AI, or your own). The platform handles scaling, fault tolerance, and observability. The total operational overhead is near zero. The trade-off is that you are locked into the Cloudflare space. The lock-in is real. The benefits are real too.
Here is what you actually get when you commit to the Cloudflare ecosystem:
- Workers: serverless functions that run on the edge with sub-millisecond cold starts
- D1: serverless SQLite database replicated globally with low latency
- R2: S3-compatible object storage with zero egress fees
- AI Gateway: a unified proxy for all LLM calls with caching and rate limiting
- Workers AI: Cloudflare’s serverless GPU platform for running models on the edge
The decision is whether the lock-in is worth the operational simplicity.
What Workers AI brings to the table
Workers AI is Cloudflare’s serverless GPU platform. The model catalog includes Llama, Mistral, Qwen, and a few others. The pricing is per-token, with a generous free tier (10,000 neurons per day, which is enough for personal use). The latency is low because the models run on Cloudflare’s edge. The integration is straightforward. You call the model from your Worker code, the model runs, the response comes back. The trade-off is that the model catalog is smaller than the OpenAI or Anthropic catalogs. most use cases is to use Workers AI for simple queries and the OpenAI or Anthropic API for complex queries. The model routing is a future feature. The current behavior is one model per agent.
What D1 brings to the table
D1 is Cloudflare’s serverless SQLite database. The database is replicated globally. The latency is low because the data is served from the edge. The pricing is generous (5GB of storage, 5 million reads per day, 100,000 writes per day for free). The use cases for an AI agent include: conversation history, user preferences, tool call audit logs, and any structured data the agent needs to persist. The trade-off is that D1 is SQLite. If you need Postgres, MySQL, or any other RDBMS, D1 is not the right tool. AI agents is to use D1 for structured data and R2 for unstructured data (files, images, etc.). The combination is the storage layer for an agent.
What the deployment actually looks like
The deployment is one command: wrangler deploy. The command takes the code in your working directory, bundles it, uploads it to Cloudflare, and registers it as a Worker. The total time is about 30 seconds. The agent is then available at the URL Cloudflare assigns. The URL is stable. The URL can be customized. The cost per request is the Workers cost ($0.50 per million requests) plus the AI cost (the model tokens used). The free tier covers 100,000 requests per day. The trade-off is that you need to learn Wrangler and the Cloudflare landscape. The learning curve is moderate. The documentation is good. The community is large. The recommendation is to start with the Cloudflare Workers Quickstart and work your way up to agents.
What the cost actually is
The cost is usage-based. The components are: Workers (compute, $0.50 per million requests, free tier 100K/day), Workers AI (model inference, $X per million tokens depending on model, free tier 10K neurons/day), D1 (database, $0.75 per GB/month storage, 5M reads/day free), R2 (object storage, $0.015 per GB/month, 10GB free), and AI Gateway (the LLM proxy, $0.05 per million tokens processed). The total monthly cost for a personal agent that does 1,000 requests per day with 500 tokens per request is roughly $0.30. The cost scales linearly. The cost is hard to predict for a production agent because it depends on traffic. The recommendation is to set up cost alerts in the Cloudflare dashboard. The alerts will tell you if the cost spikes. The mitigations are: rate limiting, caching, and using cheaper models for simple queries.
What the multi-agent coordination actually looks like
Cloudflare Agents supports a concept called “agent workflows” where multiple agents coordinate via a shared state. The shared state is typically a Durable Object (a stateful serverless primitive). Each agent can read the state, write the state, and pass messages to other agents via the state. The pattern is similar to the actor model in Erlang. The use cases I have implemented: a “research agent” that delegates to a “summarizer agent” that delegates to a “writer agent” that produces the final output. The coordination is simple. The state is in one place. The agents are independent. The fault tolerance is built in. The trade-off is the cognitive overhead of designing the agent workflow. The simpler approach (one agent that does everything) is easier to reason about but less scalable. simple use cases is one agent. complex use cases is multiple agents.
What the production deployment actually looks like
The production deployment uses Cloudflare’s Secrets store for API keys, Cloudflare’s Analytics for observability, and Cloudflare’s Logpush for log aggregation. The setup is documented well. The setup takes about 2 hours. The operational overhead after setup is near zero. Cloudflare handles the scaling, the fault tolerance, the security, and the observability. The cost is the usage-based pricing. The trade-off is the lock-in. The lock-in is real. The benefits are real. The recommendation for production agents is to use Cloudflare Agents if the lock-in is acceptable. The alternative is to use a more portable platform (like AWS Lambda or Google Cloud Run) with a custom agent framework. The cost is more operational overhead. The benefit is more portability. The decision is yours.
What I would do differently
If I were starting over, I would do two things differently. The first is to start with Cloudflare Pages instead of Workers for the static frontend. Pages is simpler. Pages deploys from a Git repo. Pages handles the build. Pages is the right answer for a static frontend. The second is to use Cloudflare’s Vectorize (the vector database) for the agent’s RAG (retrieval-augmented generation) instead of building my own with D1. Vectorize is purpose-built for embeddings. Vectorize is faster. Vectorize is the right answer for RAG. The setup is straightforward. The migration is a refactor. Doing it from the start is cheaper. If you are building a RAG agent, use Vectorize. If you are building a general-purpose agent, use D1 + Workers AI.