getting-started

A getting-started guide for building AI agents on Cloudflare's global network. The example agent keeps state between requests and updates a React web interface in real time through WebSockets.

In plain words
What is it for?
Use it to create a counter agent project, connect agent code to a React frontend, configure TypeScript and Vite, and add callable methods with the required decorator settings.
Why use it?
It gives developers a starting project and the required configuration when they are new to Cloudflare Agents. It also shows which server, client, and build files the starter project contains.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/cloudflare/agents/getting-started
Clone the repo
git clone --depth 1 https://github.com/cloudflare/agents
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,962 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01962
Opus 5 $0.00000 $0.00981
Sonnet 5 $0.00000 $0.00392
Haiku 4.5 $0.00000 $0.00196

Measured yesterday against content hash 57d33268d985, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

getting-started scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

async fetch(request: Request, env: Env, ctx: ExecutionContext) {
docs/agents/getting-started.md · 306 lines

How it starts

The opening of the file, as written. The whole thing — 306 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Getting Started

Build AI agents that persist, think, and act. Agents run on Cloudflare's global network, maintain state across requests, and connect to clients in real-time via WebSockets.

What you'll build: A counter agent with persistent state that syncs to a React frontend in real-time.

Time: ~10 minutes


Create a New Project

npm create cloudflare@latest -- --template cloudflare/agents-starter
cd my-agent
npm install

This creates a project with:

  • src/server.ts - Your agent code
  • src/client.tsx - React frontend
  • wrangler.jsonc - Cloudflare configuration
  • tsconfig.json - Extends agents/tsconfig for correct decorator and module settings
  • vite.config.ts - Includes the agents/vite plugin for decorator support

The starter template includes two SDK integrations that are required for @callable() decorators. If you are setting up a project manually, add both:

tsconfig.json — extends agents/tsconfig, which sets target: "ES2021" and other recommended options:

{
  "extends": "agents/tsconfig"
}

vite.config.ts — includes the agents() plugin, which handles TC39 decorator transforms (required because Vite 8's Oxc transpiler does not support them yet):

import { cloudflare } from "@cloudflare/vite-plugin";
import react from "@vitejs/plugin-react";
import agents from "agents/vite";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [agents(), react(), cloudflare()]
});

Start the dev server:

npm run dev

Open http://localhost:5173 to see your agent in action.


Your First Agent

Let's build a simple counter agent from scratch. Replace src/server.ts:

import { Agent, routeAgentRequest, callable } from "agents";

// Define the state shape
type CounterState = {
  count: number;
};

// Create the agent
export class Counter extends Agent<Env, CounterState> {
  // Initial state for new instances
  initialState: CounterState = { count: 0 };

  // Methods marked with @callable can be called from the client
  @callable()
  increment() {
    this.setState({ count: this.state.count + 1 });
    return this.state.count;
  }

  @callable()
  decrement() {
    this.setState({ count: this.state.count - 1 });
    return this.state.count;
  }

  @callable()
  reset() {
    this.setState({ count: 0 });
  }
}

// Route requests to agents
export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext) {
    return (
      (await routeAgentRequest(request, env)) ??
      new Response("Not found", { status: 404 })
    );
  }
};

Read the full file on GitHub · 306 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 306 lines · 0 tokens per session scan A 57d33268d985

Subscribe to this mod's changes

getting-started is an agent published in the GitHub repository cloudflare/agents (5,498 stars, last pushed 2d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,962 tokens. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.