Build stateful AI agents using the Cloudflare Agents SDK. Load when creating agents with persistent state, scheduling, RPC, MCP servers, email handling, or streaming chat. Covers Agent class, AIChatAgent, state management, and Code Mode for reduced token usage.
SkillScore100Maintained
Automatic
◆AI Engineer pack
Last verified 8/18/2026
What it changes
Passed 22 of 22 test cases with the skill, and 7 of 22 without it.
Without skill32%
With skill100%
Checks it passed that the model alone missed
State updates use this.setState.
The answer lists ai as a dependency.
The response specifies using Code Mode.
and 25 more in the full report
15 fixed7 passed either way0 still failing0 broke
Pass-rate lift
+68 pp
Tokens
+10%
Agent turns
0%
Response time
-58%
Model gemini-3.6-flashMeasured 8/18/2026v122 of 22 cases passed with skill
Tokens, turns and time describe resource use, not a dollar price.
See it in action
One of 15 test cases the skill fixed. Same model, same prompt, with and without the skill.
1 of 15
Prompt
Inside onChatMessage of a streaming chat agent, what helper function converts the agent's stored messages array into model-compatible messages for streamText?
What was checked, without and with the skill
Checked
Without skill
With skill
The messages array is converted using convertToModelMessages.
Missed
Passed
case-19 · gemini-3.6-flash · 8/18/2026 · answers are capped and redacted
What's inside
The instructions your model reads when the skill loads.
SKILL.md155 linessingle file
Cloudflare Agents SDK
Build persistent, stateful AI agents on Cloudflare Workers using the agents npm package.
FIRST: Verify Installation
npm install agents
Agents require a binding in wrangler.jsonc:
{
"durable_objects": {
// "class_name" must match your Agent class name exactly
"bindings": [{ "name": "Counter", "class_name": "Counter" }]
},
"migrations": [
// Required: list all Agent classes for SQLite storage
{ "tag": "v1", "new_sqlite_classes": ["Counter"] }
]
}
Choosing an Agent Type
Use Case
Base Class
Package
Custom state + RPC, no chat
Agent
agents
Chat with message persistence
AIChatAgent
@cloudflare/ai-chat
Building an MCP server
McpAgent
agents/mcp
Key Concepts
Agent base class provides state, scheduling, RPC, MCP, and email capabilities
AIChatAgent adds streaming chat with automatic message persistence and resumable streams