agents-sdk

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

5|Updated Feb 2, 2026
One-click install
npx skills add https://github.com/sergiodxa/monorepo --skill agents-sdk-sergiodxa
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: agents-sdk
Source: https://github.com/sergiodxa/monorepo/tree/main/.agents/skills/agents-sdk
Command: npx skills add https://github.com/sergiodxa/monorepo --skill agents-sdk-sergiodxa

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires agents, @cloudflare/ai-chat, @cloudflare/codemode, ai, @ai-sdk/openai, @modelcontextprotocol/sdk, postal-mime, zod, and includes references (resource) components.

What problem does it solve? Building AI agents that persist state, schedule tasks, handle streaming chat, and orchestrate tools requires significant boilerplate on serverless platforms. This Skill provides the patterns and APIs of the Cloudflare Agents SDK so you can implement durable, stateful agents without rediscovering configuration details. ## Core Features & Use Cases - Stateful Agents: Use the Agent base class with automatic SQLite state persistence, scheduling, queues, and WebSocket RPC via the @callable decorator. - Streaming Chat: Use AIChatAgent for chat with automatic message persistence and resumable streams, plus React hooks for the client. - MCP & Code Mode: Connect to MCP servers, build your own MCP server with McpAgent, and use Code Mode to generate executable code instead of individual tool calls to reduce token usage. - Use Case: Create a chat agent that remembers conversation history across sessions, schedules a daily summary task via cron, and orchestrates multiple MCP tools in a single generated code execution. ## Quick Start Create a Cloudflare Worker agent class extending Agent with typed state, register it in wrangler.jsonc durable object bindings and migrations, and route requests with routeAgentRequest.

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 with typed state, set initialState, and use this.setState() for automatic SQLite persistence. Register the class in wrangler.jsonc durable object bindings and migrations, then route requests with routeAgentRequest.

What is the difference between Agent and AIChatAgent?▼

Agent is the base class for custom state, scheduling, and RPC without chat. AIChatAgent from @cloudflare/ai-chat adds streaming chat with automatic message persistence and resumable streams, ideal for conversational interfaces.

How do I schedule recurring tasks in a Cloudflare agent?▼

Use this.schedule() with a Date, a delay in seconds, or a cron expression like "0 * * * *" for hourly runs. The named method receives the payload, and cron schedules automatically reschedule while one-time schedules are deleted.

When should I use Code Mode instead of tool calls?▼

Use Code Mode when chaining multiple tool calls, applying conditional logic across tools, orchestrating multiple MCP servers, or when token budget is constrained. It generates executable JavaScript in a single pass instead of multiple LLM round-trips.

Can Cloudflare agents receive and reply to emails?▼

Yes, implement the onEmail method on your Agent and configure Cloudflare Email Routing to forward to your Worker. Parse raw email content with postal-mime and reply using this.replyToEmail with a send_email binding in wrangler.jsonc.