agents-sdk

Build stateful AI agents on Cloudflare Workers using the Agents SDK.

Updated Jun 22, 2026
One-click install
npx skills add https://github.com/aashahin/ai-skills --skill agents-sdk-aashahin
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: agents-sdk
Source: https://github.com/aashahin/ai-skills/tree/main/agents-sdk
Command: npx skills add https://github.com/aashahin/ai-skills --skill agents-sdk-aashahin

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building AI agents that maintain persistent state, handle real-time WebSocket connections, run scheduled tasks, and survive restarts requires complex infrastructure. This Skill provides up-to-date guidance for the Cloudflare Agents SDK, prioritizing retrieval from official docs over potentially outdated training knowledge. ## Core Features & Use Cases - Stateful Agents: Create agents with SQLite-backed persistent state, automatic client sync via setState, and @callable RPC methods over WebSocket. - Durable Background Work: Run Workflows, durable fibers, FIFO queues, retries with backoff, and cron/interval scheduling that survive Durable Object eviction. - Chat, MCP & Integrations: Build streaming chat agents with AIChatAgent, connect to or build MCP servers, handle email, webhooks, push notifications, and experimental voice/browser tools. - Use Case: Build a customer support chat agent that persists conversation history, schedules follow-up reminders, calls MCP tools, and streams responses to a React client with resumable streaming. ## Quick Start Ask the AI to create a Cloudflare Worker agent class with persistent state and a callable RPC method, then wire up routing and the wrangler configuration.

Frequently Asked Questions about agents-sdk

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?▼

Extend the Agent class from the agents package, define typed state with initialState, and update it via this.setState which persists to SQLite and broadcasts to clients. Register a Durable Object binding and a new_sqlite_classes migration in wrangler.jsonc, then route requests with routeAgentRequest.

How do I add streaming chat to a Cloudflare agent?▼

Extend AIChatAgent from @cloudflare/ai-chat and implement onChatMessage using streamText from the AI SDK, passing abortSignal and onFinish. On the client, combine useAgent with useAgentChat from @cloudflare/ai-chat/react for messages, input handling, and resumable streaming.

Can Cloudflare agents connect to MCP servers?▼

Yes, agents include a multi-server MCP client via this.addMcpServer, supporting OAuth flows and Streamable HTTP, SSE, or RPC transports. You can also build your own MCP server by extending McpAgent and serving it with MyMCP.serve.

Why does @callable break with experimentalDecorators in tsconfig?▼

Enabling experimentalDecorators in tsconfig conflicts with the decorators used by the Agents SDK and breaks @callable RPC methods. Extend the agents/tsconfig configuration instead, which sets the correct compiler options.

When should I use Workflows instead of agent queues?▼

Use the built-in queue() for background tasks under 30 seconds with sequential FIFO processing. Use AgentWorkflow for long-running multi-step tasks, automatic retries, and human-in-the-loop approval flows that must survive failures.