Agents SDK v0.8.0: readable state, idempotent schedules, typed AgentClient, and Zod 4
Key Points
- agent.state is readable in useAgent and AgentClient
- schedule(..., {idempotent:true}) prevents duplicate schedule rows
- AgentClient gains full TypeScript inference and stub proxy
Summary
Agents SDK v0.8.0 adds readable agent state on both useAgent (React) and AgentClient (vanilla JS), introduces idempotent scheduling to avoid duplicate Durable Object schedule rows, brings full TypeScript inference and a stub proxy to AgentClient, and upgrades several packages to Zod v4. The release also includes reliability fixes (AI chat and keepAlive) and a new TanStack AI integration for @cloudflare/codemode.
Key Points
-
Readable state
- useAgent and AgentClient expose a reactive state property (agent.state) populated from initialState or setState().
- State starts undefined — use optional chaining (agent.state?.field) for safe access.
- onStateUpdate remains supported and typed when using generics.
-
Idempotent schedule()
- schedule(..., { idempotent: true }) deduplicates schedule rows by (type, callback, payload) to avoid accumulation across Durable Object restarts.
- Cron schedules are idempotent by default; delayed/date schedules support opt-in idempotency.
- Calling schedule repeatedly with the same parameters returns the existing row; pass { idempotent: false } to override.
- New console warnings: missing idempotent in onStart(), and duplicate-row warnings when many stale rows are processed.
-
Typed AgentClient and RPC stubs
- AgentClient accepts an optional agent generic for full call/stub inference; stub exposes RPC-style proxy methods.
- State and onStateUpdate become typed from the agent type.
- Advanced RPC types (AgentMethods, AgentStub, RPCMethods) are exported from agents/client.
-
Zod migration
- agents, @cloudflare/ai-chat, and @cloudflare/codemode now require zod ^4.0.0; Zod v3 is no longer supported. Update dependencies accordingly.
-
Other notable changes
- @cloudflare/ai-chat: serialization and duplicate-message bugs fixed (queued onChatMessage/_reply, stop behavior, tool call persistence).
- keepAlive() / keepAliveWhile(): removed experimental tag; now use in-memory ref counting (no schedule rows) and share a single alarm cycle.
- @cloudflare/codemode/tanstack-ai: new entry point to integrate TanStack AI's chat() as an alternative streaming adapter.
Migration & Upgrade
- Run: npm i agents@latest @cloudflare/ai-chat@latest
- Ensure your projects and dependencies use zod ^4.0.0 and update TypeScript typings where you adopt AgentClient generics.
Practical tips for engineers
- Replace onStateUpdate-only patterns with agent.state and optional chaining for concise reads and partial state spreads for updates.
- Make schedule calls in onStart() idempotent to avoid duplicate one-shot rows across restarts.
- Add the agent generic to AgentClient for editor autocompletion and safer RPC usage.
- Verify third-party libraries that depend on Zod and bump to v4 before upgrading the SDK.