The Platform For Building Agents.

Build agents on Cloudflare — the platform designed for durable execution, serverless inference, and pricing that scales up (and down).

What are agents?

Agentic AI goes beyond traditional generative AI by integrating autonomy, goal-directed reasoning, and adaptive decision-making. Unlike standard generative models, which passively respond to prompts, agentic AI actively plans, iterates, and interacts with its environment to achieve complex objectives.

01 | Comprehensive Product Suite

Build agentic AI. Entirely on Cloudflare.

Cloudflare’s extensive suite of products allows you to build AI agents entirely under one platform.

1. Get user input

To start building an agent, we'll first need to get input from the user. Be it email, chat, or voice, Cloudflare can help you receive input in whichever form you prefer.

2. Ask AI

To plan and reason through the next course of action, or generate content, the agent will have to connect to an Large-Language Model (LLM). You can connect to an LLM running directly on Cloudflare or use AI Gateway to connect to popular providers.

3. Guarantee execution

Next, to make sure all the steps take action, the agent will need an execution engine that combines state and compute:

Sometimes, you will need to go back to the LLM, and re-evaluate the plan based on new variables, and we support that too.

4. Take action

Finally, the agent will need access to tools in order to complete the tasks. Tools provide a structured way for agents and workflows to invoke APIs, manipulate data, and integrate with external systems.

02 | Low Cost

Scale up.
Or down.

Inference is hard to predict and spiky in nature, unlike training. GPU utilization is, on average, only 20-40% — with one-third of organizations utilizing less than 15%.

Workers AI allows customers to save by only paying for usage. No guessing or committing to hardware that goes unused.

What you pay for on a hyperscaler

What you pay for
on Cloudflare

Only pay for
what you use.

CPU Time

Wall Time

1ms

LLM Call

.5ms

API Call

.75ms

500ms

250ms

Wall Clock Time vs. CPU Time

With Cloudflare Workers, you only pay for , or the time actually spent executing a task, as opposed to , time waiting on I/O. When it comes to agents, your agent can often be blocked on external resources outside of your control, whether a slow API, an LLM or a human in the loop.

WebSocket Hibernation

Many agents rely on WebSockets for communication, which require long-running connections. With WebSocket hibernation built into Durable Objects, when there's no activity, the Durable Object can shut down, while still maintaining the connection, resulting in cost-savings for you.

“At Knock we’re using the Cloudflare Agents SDK to build and ship our remote MCP server, helping deliver an exceptional developer experience to our customers in no time at all.ˮ

— Chris Bell, CTO, Knock

03 | Code Example

$

Lunch Agent

An agent that helps pick lunch for coworkers in an office.

import { Agent, unstable_callable as callable } from 'agents';
import { searchMenusByAgent, chooseWinners } from '../utils';

export class LunchAgent extends Agent<Env, LunchState> {
	onStart() {
		this.schedule('weekdays at 11:30pm', 'chooseLunch');
		this.schedule('daily at 5pm', 'resetLunch');
	}

	@callable()
	async nominateRestaurant(restaurantName: string) {
		// Uses a Browser Search tool to find restaurant info
		// Finds menu and stores it into Vectorize
		// On success updates Agent state with available restaurants
		await this.env.RESTAURANT_RESEARCHER_WORKFLOW.create({
			restaurantName,
			agent: this.name,
			near: this.state.officeAddress,
		});
	}

	@callable()
	async searchRestaurants(query: string) {
		// Uses Vector store results filtered by Metadata limited
		// To this agent
		const results = await searchMenusByAgent(query, this.name);
		return results.map((result) => result.metadata.restaurantName);
	}

	@callable()
	async vote(username: string, restaurantName: string) {
		const votes = this.state.todaysVotes;
		votes.push({
			username,
			restaurantName,
		});
		// Send update to all connected eaters
		this.setState({
			...this.state,
			todaysVotes: votes,
		});
	}

	async resetLunch() {
		const state = this.state;
		state.todaysVotes = [];
		state.todaysRuling = undefined;
		this.setState(state);
	}

	async chooseLunch() {
		const restaurantWinners = chooseWinners(this.state.todaysVotes);
		const { response } = await this.env.AI.run("@cf/meta/llama-3.3-70b-instruct-fp8-fast", {
			messages: [
				{role: "system", content: `
					You help deliver results to a bunch of co-workers who are choosing lunch together.
					The user is going to provide you with the options.
					Your task is to make the choice sound exciting so people who voted for something
                    else feel validated.
					`},
				{role: "user", content: restaurantWinners?.join(", ") as string}
			],
		});
		this.setState({
			...this.state,
			todaysRuling: response
		})
	}
}

export type Restaurant = {
	cuisine: string;
	name: string;
	address: string;
};

export type Vote = {
	username: string;
	restaurantName: string;
};

export type LunchState = {
	officeAddress: string;
	todaysVotes: Vote[];
	todaysRuling?: string;
	restaurants: Restaurant[];
};

Cloudflare Terms of Use