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} ` |
Crea agenti AI con stato utilizzando Cloudflare Agents SDK. Caricamento durante la creazione di agenti con stato persistente, pianificazione, server RPC, MCP, gestione della posta elettronica o chat in streaming. Copre la classe dell'agente, AIChatAgent, la gestione dello stato e la modalità codice per un utilizzo ridotto dei token. Fonte: elithrar/dotfiles.