cloudflare-agents
БесплатноБез исполняемых скриптовНе проверенCloudflare Agents SDK - Build and deploy AI-powered agents on Cloudflare's edge with real-time WebSocket communication, persistent state, SQL storage, task…
Об этом скилле
Cloudflare Agents SDK Skill
The Cloudflare Agents SDK enables you to build and deploy AI-powered agents that run on Cloudflare's global edge network. Agents can autonomously perform tasks, communicate with clients in real-time via WebSockets, call AI models, persist state, schedule tasks, run asynchronous workflows, browse the web, query data from databases, support human-in-the-loop interactions, and act as MCP (Model Context Protocol) servers or clients.
Core Value: Agents deploy on Cloudflare's Durable Objects - stateful micro-servers that can scale to tens of millions and run close to users for low-latency interactivity.
When to Use This Skill
This skill should be triggered when:
- Building AI agents that need persistent state and real-time communication
- Creating chatbots or conversational AI interfaces on Cloudflare Workers
- Implementing WebSocket-based real-time applications
- Deploying agents with embedded SQL databases (SQLite)
- Scheduling tasks with delays, dates, or cron expressions
- Building human-in-the-loop approval workflows for AI tool execution
- Creating or connecting to MCP (Model Context Protocol) servers
- Deploying stateful AI applications on edge infrastructure
- Building multi-user collaborative AI applications
- Integrating with Vercel AI SDK on Cloudflare Workers
Quick Reference
Installation
# Add to existing Workers project
npm i agents
# Or create new project from starter template
npm create cloudflare@latest agents-starter -- --template=cloudflare/agents-starter
# Navigate and run
cd agents-starter
mv .env.local .env
npm install
npm run dev
Package Imports
// Core Agent classes
import { Agent } from "agents";
import { AIChatAgent } from "agents/ai-chat-agent";
import { McpAgent } from "agents/mcp";
// Client-side
import { AgentClient } from "agents/client";
// React hooks
import { useAgent } from "agents/react";
import { useAgentChat } from "agents/ai-react";
// Routing
import { routeAgentRequest, getAgentByName } from "agents";
Basic Agent Setup
import { Agent, routeAgentRequest } from "agents";
// Define your Agent class
export class MyAgent extends Agent<Env, State> {
// Optional: Set initial state
initialState = {
counter: 0,
messages: [],
};
// Called when agent starts or resumes
async onStart() {
console.log("Agent started");
}
// Handle HTTP requests
async onRequest(request: Request): Promise<Response> {
return new Response("Hello from Agent!");
}
// Handle WebSocket connections
async onConnect(connection: Connection, ctx: ConnectionContext) {
console.log(`Client connected: ${connection.id}`);
}
// Handle WebSocket messages
async onMessage(connection: Connection, message: WSMessage) {
const data = JSON.parse(message as string);
connection.send(JSON.stringify({ received: data }));
}
// Handle state updates
onStateUpdate(state: State, source: "server" | Connection) {
console.log("State updated:", state);
}
}
// Export default handler with routing
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
return routeAgentRequest(request, env);
},
};
Configuration (wrangler.jsonc)
{
"name": "my-agent",
"main": "src/index.ts",
"compatibility_date": "2025-01-01",
"compatibility_flags": ["nodejs_compat"],
"observability": {
"enabled": true
},
"durable_objects": {
"bindings": [
{
"name": "MY_AGENT",
"class_name": "MyAgent"
}
]
},
"migrations": [
{
"tag": "v1",
"new_sqlite_classes": ["MyAgent"]
}
]
}
Agent API Reference
Agent Class
The base class for all agents, providing lifecycle hooks and capabilities.
class Agent<Env, State> {
// Properties
env: Env; // Environment bindings
state: State; // Current state (read-only)
initialState?: State; // Optional default state
// Lifecycle hooks
onStart(): void | Promise<void>;
onRequest(request: Request): Response | Promise<Response>;
onConnect(connection: Connection, ctx: ConnectionContext): void;
onMessage(connection: Connection, message: WSMessage): void;
onError(connection: Connection, error: Error): void;
onClose(connection: Connection, code: number, reason: string, wasClean: boolean): void;
onStateUpdate(state: State, source: "server" | Connection): void;
// State management
setState(state: Partial<State>): void;
// SQL database
sql`query`: SQLResult;
// Task scheduling
schedule(when: number | Date | string, callback: string, data?: any): string;
getSchedule(id: string): Schedule | undefined;
getSchedules(criteria?: ScheduleCriteria): Schedule[];
cancelSchedule(id: string): void;
// MCP integration
addMcpServer(name: string, url: string, ...): void;
removeMcpServer(id: string): void;
getMcpServers(): McpServer[];
}
Установить cloudflare-agents в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл cloudflare-agents?
Cloudflare Agents SDK - Build and deploy AI-powered agents on Cloudflare's edge with real-time WebSocket communication, persistent state, SQL storage, task scheduling, MCP integration, and human-in-the-loop workflows.
Как установить скилл cloudflare-agents?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл cloudflare-agents запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic