スキル一覧に戻る
2Rds

cloudflare-agents-sdk

by 2Rds

0🍴 0📅 2026年1月18日
GitHubで見るManusで実行

SKILL.md


name: Cloudflare Agents SDK description: This skill should be used when the user asks to "build an AI agent", "create a chatbot", "use Cloudflare Agents SDK", "stateful AI agent", "WebSocket agent", or is developing AI agents on Cloudflare infrastructure. version: 1.0.0

Cloudflare Agents SDK

Build stateful AI agents on Cloudflare using the Agents SDK with Durable Objects, WebSocket support, and persistent state.

Quick Start

npm create cloudflare@latest -- my-agent --template=cloudflare/agents-starter
cd my-agent
wrangler dev

Basic Agent

import { Agent } from "cloudflare-agents";

export class MyAgent extends Agent {
  initialState = {
    messages: [],
    context: {}
  };

  async onMessage(connection, message) {
    // Process message
    const data = JSON.parse(message);

    // Update state (auto-persisted)
    this.setState({
      ...this.state,
      messages: [...this.state.messages, data]
    });

    // Send response
    connection.send(JSON.stringify({ response: "Received" }));
  }
}

Chat Agent (AI-Powered)

import { AIChatAgent } from "cloudflare-agents";

export class ChatBot extends AIChatAgent {
  async onMessage(connection, message) {
    const response = await this.ai.complete({
      model: "@cf/meta/llama-2-7b-chat-int8",
      messages: this.state.messages
    });

    connection.send(response.text);
  }
}

Scheduled Tasks

// Run in 60 seconds
this.schedule(60);

// Run at specific time
this.schedule("2024-12-31T23:59:59Z");

// Cron schedule
this.schedule("0 * * * *"); // Every hour

SQLite Queries

// Query with template literals (safe from injection)
const users = await this.sql`
  SELECT * FROM users
  WHERE id = ${userId}
  AND active = ${true}
`;

WebSocket Connection

// Client-side
const ws = new WebSocket("wss://your-domain.com/agents/MyAgent/instance-id");

ws.onmessage = (event) => {
  console.log(JSON.parse(event.data));
};

ws.send(JSON.stringify({ type: "chat", message: "Hello!" }));

For deployment and cost considerations, see cloudflare-workers and cloudflare-cost-optimization skills.

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です