building-ai-agent-on-cloudflare

Build stateful AI agents on Cloudflare with WebSocket communication.

Updated Jan 4, 2026
One-click install
npx skills add https://github.com/devsanthoshmk/MKS-Agency --skill building-ai-agent-on-cloudflare-devsanthoshmk
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: building-ai-agent-on-cloudflare
Source: https://github.com/devsanthoshmk/MKS-Agency/tree/main/backend/.agents/skills/building-ai-agent-on-cloudflare
Command: npx skills add https://github.com/devsanthoshmk/MKS-Agency --skill building-ai-agent-on-cloudflare-devsanthoshmk

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Cloudflare Workers users need a production path to build chat and tool-enabled AI agents with persistent state, real-time messaging, and scheduled tasks without stitching together multiple backend services manually.

Core Features & Use Cases

  • Stateful Cloudflare Agents: Build agents with durable, per-session state that persists across connections using the Agents SDK and Durable Objects.
  • Real-time WebSocket Chat: Implement responsive agent conversations where clients connect, send messages, and receive streamed or immediate responses.
  • Tool Calling & Scheduled Tasks: Integrate deterministic tool execution and background scheduling so the agent can call external functions or run tasks later.
  • Use Case: Create a customer support chat agent that remembers conversation history, calls tools like order lookup, and schedules follow-ups for unresolved requests.

Quick Start

Tell your AI assistant: "Generate a Cloudflare Agents SDK WebSocket chat agent with persistent state, a schedule-based reminder method, and tool-calling support, then provide the complete src/index.ts and agent implementation for Workers deployment."

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 a stateful AI agent on Cloudflare Workers?

To build a stateful AI agent on Cloudflare, use the Agents SDK to configure a Durable Object class with Workers AI bindings, a routeAgentRequest fetch entry point, and onStart, onConnect, and onMessage handlers. This maintains persistent conversation context across client connections.

How does Cloudflare Agents SDK handle persistent WebSocket chat sessions?

The Agents SDK uses Durable Objects to maintain durable, per-session state for WebSocket chat. Clients connect via WebSocket, send messages, and receive responses while the agent preserves conversation history and state updates across disconnects and reconnects automatically.

Can I add tool calling and scheduled tasks to a Cloudflare AI agent?

Yes, the Agents SDK supports integrating deterministic tool calling and background scheduling within your Cloudflare AI agent. You can implement external function execution for tasks like order lookup and schedule follow-ups or reminders for unresolved requests.

What's the best way to maintain conversation history across WebSocket disconnects?

Using Durable Objects via the Agents SDK is the best way to maintain conversation history across disconnects. The agent persists state locally, allowing interactions to resume seamlessly with full context when the client reconnects.

Do I need Workers AI bindings to deploy a Cloudflare Agents SDK chatbot?

Yes, Workers AI bindings are required to deploy a Cloudflare Agents SDK chatbot. You must also configure a Durable Object class and implement the routeAgentRequest fetch entry point alongside state management and WebSocket connection handlers.

Why does my Cloudflare agent lose chat context between user sessions?

Your Cloudflare agent loses chat context because it lacks durable state management. Implement the Agents SDK with Durable Objects to persist per-session state and conversation history, ensuring context survives across WebSocket disconnects and reconnects.