building-ai-agent-on-cloudflare

Builds stateful AI agents on Cloudflare Workers using the Agents SDK with WebSockets and scheduled tasks.

Updated Mar 1, 2026
One-click install
npx skills add https://github.com/involvex/dev --skill building-ai-agent-on-cloudflare-involvex
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: building-ai-agent-on-cloudflare
Source: https://github.com/involvex/dev/tree/main/.claude/skills/building-ai-agent-on-cloudflare
Command: npx skills add https://github.com/involvex/dev --skill building-ai-agent-on-cloudflare-involvex

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires agents, zod, wrangler, and includes references (resource) components.

What problem does it solve? Building AI agents that maintain persistent state, handle real-time WebSocket connections, and run scheduled background tasks requires complex infrastructure. This Skill generates complete agent implementations on Cloudflare Workers using the Agents SDK, handling state persistence, client synchronization, and deployment configuration. ## Core Features & Use Cases - Stateful Agent Generation: Creates Agent classes with automatic state persistence via setState(), embedded SQLite storage, and real-time sync to connected clients. - Real-Time Chat & Streaming: Implements WebSocket-based chat agents with AIChatAgent, resumable streaming, and React hooks via useAgent. - Advanced Patterns: Provides reference implementations for tool calling, RAG with Vectorize, multi-agent orchestration, human-in-the-loop approvals, and scheduled cron tasks. - Use Case: A developer wants a customer support chatbot that remembers conversation history per user, streams LLM responses, and schedules follow-up reminders. This Skill produces the agent code, wrangler.toml configuration, and client integration. ## Quick Start Ask the AI to build a Cloudflare AI chat agent with persistent message history and WebSocket streaming using the Agents SDK.

Frequently Asked Questions about building-ai-agent-on-cloudflare

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build an AI agent on Cloudflare Workers?▼

Create a project with npm create cloudflare@latest using the agents-starter template, then extend the Agent class with onConnect, onMessage, and setState methods. Deploy with wrangler deploy after configuring Durable Object bindings in wrangler.toml.

How to add persistent state to a Cloudflare agent?▼

Use this.setState() to persist JSON-serializable data that survives Durable Object evictions and syncs to all connected clients. For large datasets or complex queries, use the embedded SQLite database via this.sql tagged templates.

Does the Cloudflare Agents SDK support scheduled tasks?▼

Yes, agents support scheduled tasks via this.schedule() with delay in seconds, a specific Date, or cron expressions for recurring jobs. Scheduled callbacks must be defined as methods on the Agent class and can be managed with getSchedules() and cancelSchedule().

Why is my Cloudflare agent state not persisting?▼

State fails to persist when you mutate this.state directly instead of calling setState(), or when clients connect to different agent instance IDs. Each unique ID gets an isolated agent instance with its own storage.

Can Cloudflare agents do tool calling with LLMs?▼

Yes, agents can register tools with Zod schemas and pass them to Workers AI models via the tools parameter. When the model returns tool_calls, the agent executes the handler and sends results back for a final response.