All skills
cloudflare avatar

/agents-sdk

@41e0d19 official
by cloudflarecloudflare/skills3k stars
298

Build, debug, or review Cloudflare Agents SDK applications using the agents package.

Use this Skill: https://skilld.dev/gh/cloudflare/skills/agents-sdk

This session only. Nothing lands on disk.

referencesconfiguration.md

≈463 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Configuration

Fetch https://developers.cloudflare.com/agents/runtime/operations/configuration/index.md for complete documentation.

Wrangler Config (wrangler.jsonc)

{
  "name": "my-agent",
  "main": "src/index.ts",
  "compatibility_date": "2025-01-28",
  "compatibility_flags": ["nodejs_compat"],
  "durable_objects": {
    "bindings": [
      { "name": "MyAgent", "class_name": "MyAgent" },
      { "name": "ChatAgent", "class_name": "ChatAgent" }
    ]
  },
  "migrations": [
    { "tag": "v1", "new_sqlite_classes": ["MyAgent", "ChatAgent"] }
  ],
  "ai": { "binding": "AI" },
  "assets": {
    "directory": "./dist/client",
    "binding": "ASSETS",
    "not_found_handling": "single-page-application",
    "run_worker_first": true
  }
}

Key Rules

  • Every agent class needs a DO binding AND a new_sqlite_classes migration entry
  • nodejs_compat is required
  • Never edit old migrations — add a new tag (e.g. v2) for new classes
  • Do NOT enable experimentalDecorators in tsconfig — it breaks @callable
  • For Workers AI locally, set "ai": { "binding": "AI", "remote": true } in .dev.vars or config
  • Use wrangler secret put for secrets, never hardcode them

Vite Setup

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

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

Type Generation

npx wrangler types

This generates env.d.ts with typed bindings. Regenerate after changing wrangler.jsonc.

tsconfig

Extend the agents tsconfig for correct settings:

{
  "extends": ["agents/tsconfig"],
  "include": ["src/**/*.ts", "src/**/*.tsx"],
  "compilerOptions": { "paths": { "~/*": ["./src/*"] } }
}

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill provides reference documentation and configuration guidelines for building, debugging, and reviewing applications using the Cloudflare Agents SDK. It consists entirely of educational markdown files and contains no executable code or security risks.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    8 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 41e0d19. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 5 hours ago.

Activeupdated 7 hours ago
  • MCP
  • cloudflare
  • workers
  • agents
  • state-management
  • websocket
  • durable-objects
  • scheduling
  • workflows
  • observable

README badge

README badge for cloudflare/skills/agents-sdk

Builds stateful AI agents on Cloudflare Workers using Durable Objects, with APIs for persistent state, callable RPC methods, scheduling, workflows, durable execution, queues, and streaming chat. Covers the full lifecycle of agent development from configuration through observability, with experimental support for voice, browser automation, and MCP integration.

Generated from the current SKILL.md.

Does this work with existing Cloudflare Workers projects?
Yes. Use the 'Add to existing project' guide to install the SDK into an existing Workers app. You'll need to configure durable objects and migrations in wrangler.jsonc.
What state management does the SDK provide?
SQLite-backed persistent state that auto-syncs to clients via setState(). State changes trigger validateStateChange() and onStateUpdate() hooks, and the SDK includes built-in SQL query support.
Can I use this with chat applications?
Yes. The SDK includes AIChatAgent for streaming chat with tools, message persistence, and resumable streams. It requires @cloudflare/ai-chat and ai packages.
Does this support background workflows and scheduled tasks?
Yes. The SDK provides AgentWorkflow for durable multi-step tasks, schedule() / scheduleEvery() for one-time and recurring tasks, and runFiber() for work that survives durable object eviction.
Can I connect to external MCP servers or build MCP servers with this?
Yes. The SDK includes MCP client integration to connect to external MCP servers and McpAgent to build MCP servers with configurable transports (HTTP, SSE, RPC).

Generated from the current SKILL.md. These answers refresh after source changes.