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.

referenceswebhooks-push.md

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

Webhooks & Push Notifications

Webhooks

Fetch https://developers.cloudflare.com/agents/communication-channels/webhooks/index.md for complete documentation.

Route external webhooks to agent instances via onRequest:

export default {
  async fetch(req: Request, env: Env) {
    const url = new URL(req.url);
    if (url.pathname.startsWith("/webhooks/")) {
      const entityId = url.pathname.split("/")[2];
      const agent = getAgentByName(env.MyAgent, entityId);
      return agent.fetch(req);
    }
    return routeAgentRequest(req, env);
  }
};

In the agent:

export class MyAgent extends Agent<Env, State> {
  async onRequest(request: Request) {
    const signature = request.headers.get("X-Signature");
    if (!verifySignature(signature, await request.text(), this.env.WEBHOOK_SECRET)) {
      return new Response("Unauthorized", { status: 401 });
    }
    const payload = JSON.parse(await request.text());
    this.queue("processWebhook", payload);
    return new Response("OK", { status: 202 });
  }
}

Tips: Respond quickly (200/202), verify signatures, deduplicate with stored event IDs, use queue() for async processing.

Push Notifications

Fetch https://developers.cloudflare.com/agents/communication-channels/webhooks/push-notifications/index.md for complete documentation.

Web Push via VAPID from agents. Store subscriptions in agent state, send via web-push.

npm install web-push
import webpush from "web-push";

export class NotifyAgent extends Agent<Env, State> {
  @callable()
  async subscribe(subscription: PushSubscription) {
    this.setState({
      ...this.state,
      subscriptions: [...this.state.subscriptions, subscription]
    });
  }

  async sendReminder(payload: { message: string }, schedule: Schedule) {
    for (const sub of this.state.subscriptions) {
      try {
        await webpush.sendNotification(sub, JSON.stringify({
          title: "Reminder",
          body: payload.message
        }), {
          vapidDetails: {
            subject: "mailto:you@example.com",
            publicKey: this.env.VAPID_PUBLIC_KEY,
            privateKey: this.env.VAPID_PRIVATE_KEY
          }
        });
      } catch (err) {
        if (err.statusCode === 404 || err.statusCode === 410) {
          // Remove expired subscription
        }
      }
    }
  }
}

VAPID keys: generate with npx web-push generate-vapid-keys, store as secrets.

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.