← CloudflareCONTENT HISTORY

Update to Cloudflare

Snapshot Sep 30, 2026 · 23:18 UTC · version 0.1.2

Collection source: not recorded for this historical snapshot.

WHAT CHANGED · RULE-BASED ANALYSIS

First saved snapshot

No earlier snapshot is available to establish a change.

Compare saved observations

Download comparison JSON
Full technical diff · 0 changed fields
Full snapshot data
{
  "name": "agents-sdk",
  "description": "Build AI agents on Cloudflare Workers using the Agents SDK. Load when creating stateful agents, durable workflows, real-time WebSocket apps, scheduled tasks, MCP servers, or chat applications. Covers Agent class, state management, callable RPC, Workflows integration, and React hooks. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.",
  "included_files": [
    {
      "relative_path": "LICENSE.txt",
      "size_in_bytes": 10776
    },
    {
      "relative_path": "agents/openai.yaml",
      "size_in_bytes": 342
    },
    {
      "relative_path": "assets/cloudflare-small.svg",
      "size_in_bytes": 1221
    },
    {
      "relative_path": "assets/cloudflare.png",
      "size_in_bytes": 1187
    },
    {
      "relative_path": "references/callable.md",
      "size_in_bytes": 2128
    },
    {
      "relative_path": "references/codemode.md",
      "size_in_bytes": 5421
    },
    {
      "relative_path": "references/email.md",
      "size_in_bytes": 3552
    },
    {
      "relative_path": "references/mcp.md",
      "size_in_bytes": 3584
    },
    {
      "relative_path": "references/state-scheduling.md",
      "size_in_bytes": 3796
    },
    {
      "relative_path": "references/streaming-chat.md",
      "size_in_bytes": 4186
    },
    {
      "relative_path": "references/workflows.md",
      "size_in_bytes": 3887
    }
  ],
  "skill_md_contents": "---\nname: agents-sdk\ndescription: Build AI agents on Cloudflare Workers using the Agents SDK. Load when creating stateful agents, durable workflows, real-time WebSocket apps, scheduled tasks, MCP servers, or chat applications. Covers Agent class, state management, callable RPC, Workflows integration, and React hooks. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.\n---\n\n# Cloudflare Agents SDK\n\nYour knowledge of the Agents SDK may be outdated. **Prefer retrieval over pre-training** for any Agents SDK task.\n\n## Retrieval Sources\n\nFetch current docs from `https://github.com/cloudflare/agents/tree/main/docs` before implementing.\n\n| Topic | Doc | Use for |\n|-------|-----|---------|\n| Getting started | `docs/getting-started.md` | First agent, project setup |\n| State | `docs/state.md` | `setState`, `validateStateChange`, persistence |\n| Routing | `docs/routing.md` | URL patterns, `routeAgentRequest`, `basePath` |\n| Callable methods | `docs/callable-methods.md` | `@callable`, RPC, streaming, timeouts |\n| Scheduling | `docs/scheduling.md` | `schedule()`, `scheduleEvery()`, cron |\n| Workflows | `docs/workflows.md` | `AgentWorkflow`, durable multi-step tasks |\n| HTTP/WebSockets | `docs/http-websockets.md` | Lifecycle hooks, hibernation |\n| Email | `docs/email.md` | Email routing, secure reply resolver |\n| MCP client | `docs/mcp-client.md` | Connecting to MCP servers |\n| MCP server | `docs/mcp-servers.md` | Building MCP servers with `McpAgent` |\n| Client SDK | `docs/client-sdk.md` | `useAgent`, `useAgentChat`, React hooks |\n| Human-in-the-loop | `docs/human-in-the-loop.md` | Approval flows, pausing workflows |\n| Resumable streaming | `docs/resumable-streaming.md` | Stream recovery on disconnect |\n\nCloudflare docs: https://developers.cloudflare.com/agents/\n\n## Capabilities\n\nThe Agents SDK provides:\n\n- **Persistent state** - SQLite-backed, auto-synced to clients\n- **Callable RPC** - `@callable()` methods invoked over WebSocket\n- **Scheduling** - One-time, recurring (`scheduleEvery`), and cron tasks\n- **Workflows** - Durable multi-step background processing via `AgentWorkflow`\n- **MCP integration** - Connect to MCP servers or build your own with `McpAgent`\n- **Email handling** - Receive and reply to emails with secure routing\n- **Streaming chat** - `AIChatAgent` with resumable streams\n- **React hooks** - `useAgent`, `useAgentChat` for client apps\n\n## FIRST: Verify Installation\n\n```bash\nnpm ls agents  # Should show agents package\n```\n\nIf not installed:\n```bash\nnpm install agents\n```\n\n## Wrangler Configuration\n\n```jsonc\n{\n  \"durable_objects\": {\n    \"bindings\": [{ \"name\": \"MyAgent\", \"class_name\": \"MyAgent\" }]\n  },\n  \"migrations\": [{ \"tag\": \"v1\", \"new_sqlite_classes\": [\"MyAgent\"] }]\n}\n```\n\n## Agent Class\n\n```typescript\nimport { Agent, routeAgentRequest, callable } from \"agents\";\n\ntype State = { count: number };\n\nexport class Counter extends Agent<Env, State> {\n  initialState = { count: 0 };\n\n  // Validation hook - runs before state persists (sync, throwing rejects the update)\n  validateStateChange(nextState: State, source: Connection | \"server\") {\n    if (nextState.count < 0) throw new Error(\"Count cannot be negative\");\n  }\n\n  // Notification hook - runs after state persists (async, non-blocking)\n  onStateUpdate(state: State, source: Connection | \"server\") {\n    console.log(\"State updated:\", state);\n  }\n\n  @callable()\n  increment() {\n    this.setState({ count: this.state.count + 1 });\n    return this.state.count;\n  }\n}\n\nexport default {\n  fetch: (req, env) => routeAgentRequest(req, env) ?? new Response(\"Not found\", { status: 404 })\n};\n```\n\n## Routing\n\nRequests route to `/agents/{agent-name}/{instance-name}`:\n\n| Class | URL |\n|-------|-----|\n| `Counter` | `/agents/counter/user-123` |\n| `ChatRoom` | `/agents/chat-room/lobby` |\n\nClient: `useAgent({ agent: \"Counter\", name: \"user-123\" })`\n\n## Core APIs\n\n| Task | API |\n|------|-----|\n| Read state | `this.state.count` |\n| Write state | `this.setState({ count: 1 })` |\n| SQL query | `` this.sql`SELECT * FROM users WHERE id = ${id}` `` |\n| Schedule (delay) | `await this.schedule(60, \"task\", payload)` |\n| Schedule (cron) | `await this.schedule(\"0 * * * *\", \"task\", payload)` |\n| Schedule (interval) | `await this.scheduleEvery(30, \"poll\")` |\n| RPC method | `@callable() myMethod() { ... }` |\n| Streaming RPC | `@callable({ streaming: true }) stream(res) { ... }` |\n| Start workflow | `await this.runWorkflow(\"ProcessingWorkflow\", params)` |\n\n## React Client\n\n```tsx\nimport { useAgent } from \"agents/react\";\n\nfunction App() {\n  const [state, setLocalState] = useState({ count: 0 });\n\n  const agent = useAgent({\n    agent: \"Counter\",\n    name: \"my-instance\",\n    onStateUpdate: (newState) => setLocalState(newState),\n    onIdentity: (name, agentType) => console.log(`Connected to ${name}`)\n  });\n\n  return (\n    <button onClick={() => agent.setState({ count: state.count + 1 })}>\n      Count: {state.count}\n    </button>\n  );\n}\n```\n\n## References\n\n- **[references/workflows.md](references/workflows.md)** - Durable Workflows integration\n- **[references/callable.md](references/callable.md)** - RPC methods, streaming, timeouts\n- **[references/state-scheduling.md](references/state-scheduling.md)** - State persistence, scheduling\n- **[references/streaming-chat.md](references/streaming-chat.md)** - AIChatAgent, resumable streams\n- **[references/mcp.md](references/mcp.md)** - MCP server integration\n- **[references/email.md](references/email.md)** - Email routing and handling\n- **[references/codemode.md](references/codemode.md)** - Code Mode (experimental)\n"
}

SHA-256: fb0625ebd7474956e3a58891dc951aa26961b2b86d114f18e4cd1e7da33d4317