Agents SDK v0.7.0 — observability rewrite, keepAlive, waitForMcpConnections
Key Points
- Observability now uses diagnostics_channel events
- keepAlive() prevents Durable Object eviction during long tasks
- waitForMcpConnections ensures MCP tools available before onChatMessage
Summary
Agents SDK v0.7.0 rewrites observability to use structured diagnostics channels (zero overhead when unused), adds keepAlive() and keepAliveWhile() to prevent Durable Object eviction during long-running work, and introduces waitForMcpConnections so MCP tools are available before onChatMessage runs. Several MCP and tool-related quality-of-life and security improvements are included.
Key Points
- Observability
- Replaces console/Observability.emit with diagnostics_channel events (type, payload, timestamp).
- Events routed to named channels (agents:rpc, agents:workflow, agents:mcp, agents:message, etc.).
- Use agents/observability.subscribe(channel, handler) for typed, type-safe subscriptions.
- In production, Tail Workers automatically receive diagnosticsChannelEvents — no agent subscription required.
- keepAlive() / keepAliveWhile()
- keepAlive() creates a 30s heartbeat schedule to reset Durable Object inactivity timers; returns a disposer to cancel it.
- keepAliveWhile(fn) starts the heartbeat for the duration of an async function and stops automatically.
- Multiple concurrent callers are independent; AIChatAgent automatically uses keepAlive() during streaming.
- Marked experimental (API may change).
- waitForMcpConnections
- AIChatAgent waits for MCP server connections before invoking onChatMessage to ensure this.mcp.getAITools() returns the full toolset.
- Configuration: {timeout: 10000} (default), true (wait indefinitely), false (do not wait). Call this.mcp.waitForConnections() for manual control.
- Other improvements
- addMcpServer deduplicates by name+normalized URL; callbackHost optional for non-OAuth servers; server URLs validated to block private/metadata ranges.
- addToolOutput supports state: "output-error" with errorText for custom denial flows.
- onChatMessage options now include requestId for logging/correlation.
Upgrade
Run:
npm i agents@latest @cloudflare/ai-chat@latest
Notes
- Observability is silent and zero-cost when no subscribers are present.
- Review the Observability and Schedule docs for full event and API references.