Observability Rewrite with Diagnostics Channels
The observability system has been completely redesigned, replacing the previous console.log() and custom Observability.emit() interface with structured events published to diagnostics channels. This new approach is silent by default with zero overhead when no subscribers are listening.
Events are organized into seven named channels: agents:state, agents:rpc, agents:message, agents:schedule, agents:lifecycle, agents:workflow, and agents:mcp. Each event includes a type, payload, and timestamp. Developers can subscribe to specific channels using the typed subscribe() helper from agents/observability for type-safe event access.
In production environments, all diagnostics channel messages are automatically forwarded to Tail Workers without requiring subscription code in the agent itself. The legacy Observability override interface remains supported for users who need custom event filtering or forwarding to external services.
KeepAlive Methods Prevent Agent Eviction
New keepAlive() and keepAliveWhile() methods prevent Durable Objects from being evicted during long-running operations. Durable Objects normally evict after 70-140 seconds of inactivity, which can interrupt streaming LLM responses, external API calls, or multi-step computations.
keepAlive() creates a 30-second heartbeat schedule that resets the inactivity timer, returning a disposer function to cancel when complete. keepAliveWhile() wraps async functions with automatic cleanup—the heartbeat starts before execution and stops when it completes. Multiple concurrent callers each get independent disposers, and AIChatAgent automatically calls keepAlive() during streaming responses.
MCP Connection Waiting
AIChatAgent now waits for MCP server connections to settle before calling onChatMessage, ensuring this.mcp.getAITools() returns the complete tool set. This is especially important after Durable Object hibernation when connections are being restored asynchronously. The waitForMcpConnections property allows configuration: default waits up to 10 seconds, true waits indefinitely, and false disables waiting.