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.
npx agentmods add agents/cloudflare/agents/stategit clone --depth 1 https://github.com/cloudflare/agentsWhat 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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00000 | $0.03238 |
| Opus 5 | $0.00000 | $0.01619 |
| Sonnet 5 | $0.00000 | $0.00648 |
| Haiku 4.5 | $0.00000 | $0.00324 |
Grade A, and why
state scanned grade A with 0 findings 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 2d ago.
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.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 513 lines — stays where its author put it; the contents beside it link to each section on GitHub.
State Management
Agents provide built-in state management with automatic persistence and real-time synchronization across all connected clients.
Overview
Agent state is:
- Persistent - Automatically saved to SQLite, survives restarts and hibernation
- Synchronized - Changes broadcast to all connected WebSocket clients instantly
- Bidirectional - Both server and clients can update state
- Type-safe - Full TypeScript support with generics
import { Agent } from "agents";
type GameState = {
players: string[];
score: number;
status: "waiting" | "playing" | "finished";
};
export class GameAgent extends Agent<Env, GameState> {
// Default state for new agents
initialState: GameState = {
players: [],
score: 0,
status: "waiting"
};
// React to state changes
onStateChanged(state: GameState, source: Connection | "server") {
if (source !== "server" && state.players.length >= 2) {
// Client added a player, start the game
this.setState({ ...state, status: "playing" });
}
}
addPlayer(name: string) {
this.setState({
...this.state,
players: [...this.state.players, name]
});
}
}
Defining Initial State
Use the initialState property to define default values for new agent instances:
type State = {
messages: Message[];
settings: UserSettings;
lastActive: string | null;
};
export class ChatAgent extends Agent<Env, State> {
initialState: State = {
messages: [],
settings: { theme: "dark", notifications: true },
lastActive: null
};
}
Type Safety
The second generic parameter to Agent<Env, State> defines your state type:
// State is fully typed
export class MyAgent extends Agent<Env, MyState> {
initialState: MyState = { count: 0 };
increment() {
// TypeScript knows this.state is MyState
this.setState({ count: this.state.count + 1 });
}
}
When Initial State Applies
Initial state is applied lazily on first access, not on every wake:
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.
- 2d ago First seen · 513 lines · 0 tokens per session scan A be95d021db4a
state 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 3,238 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other agents, from other repositories
API Tester Specialist
Specialist in creating and executing API tests. Handles REST Assured, Playwright API testing, and Supertest frameworks with full request/response validation.
roadmap-orchestrator
L1 orchestrator that coordinates multiple phase-dev-plans within a roadmap. Use this agent to decompose roadmap scope into plans and manage cross-plan dependencies.
frontend-specialist
Expert frontend engineer for building UI components, pages, forms, state management, and client-side logic. Adapts to any frontend framework based on project context.
atlas
End-to-end and acceptance test execution.
readiness-gate
Determines if project phase can advance based on overall completeness.
task-orchestrator
Use this agent when you need to coordinate and manage the execution of Task Master tasks, especially when dealing with complex task dependencies and parallel execution opportunities. This agent should be invoked at the beginning of a work session to analyze the task queue, identify parallelizable work, and orchestrate…