Build persistent, stateful AI agents on Cloudflare Workers using the agents npm package.
| Custom state + RPC, no chat | Agent | agents | | Chat with message persistence | AIChatAgent | @cloudflare/ai-chat | | Building an MCP server | McpAgent | agents/mcp |
| Persist state | this.setState({ count: 1 }) | | Read state | this.state.count | | Schedule task | this.schedule(60, "taskMethod", payload) | | Schedule cron | this.schedule("0 ", "hourlyTask") | | Cancel schedule | this.cancelSchedule(id) | | Queue task | this.queue("processItem", payload) | | SQL query | ` this.sqlSELECT FROM users WHERE id = ${id} ` |
Erstellen Sie zustandsbehaftete KI-Agenten mit dem Cloudflare Agents SDK. Wird geladen, wenn Agenten mit dauerhaftem Status, Planung, RPC, MCP-Servern, E-Mail-Verarbeitung oder Streaming-Chat erstellt werden. Deckt die Agentenklasse, den AIChatAgent, die Statusverwaltung und den Codemodus für eine reduzierte Token-Nutzung ab. Quelle: elithrar/dotfiles.