github cloudflare/agents @cloudflare/ai-chat@0.4.0

8 hours ago

Minor Changes

  • #1264 95b4d6a Thanks @threepointone! - Rename durableStreaming to unstable_chatRecovery. Fix abort controller leak when onChatMessage throws. Wrap all 4 chat turn paths (WS, auto-continuation, programmatic, continueLastTurn) in runFiber when enabled. Guard _chatRecoveryContinue against stale continuations via targetAssistantId in schedule payload.

  • #1256 dfab937 Thanks @threepointone! - Add durable fiber execution to the Agent base class.

    runFiber(name, fn) registers work in SQLite, holds a keepAlive ref, and enables recovery via onFiberRecovered after DO eviction. ctx.stash() and this.stash() checkpoint progress that survives eviction.

    AIChatAgent gains unstable_chatRecovery — when enabled, each chat turn is wrapped in a fiber. onChatRecovery provides provider-specific recovery (Workers AI continuation, OpenAI response retrieval, Anthropic synthetic message). continueLastTurn() appends to the interrupted assistant message seamlessly.

    Think now extends Agent directly (no mixin). Fiber support is inherited from the base class.

    Breaking (experimental APIs only):

    • Removed withFibers mixin (agents/experimental/forever)
    • Removed withDurableChat mixin (@cloudflare/ai-chat/experimental/forever)
    • Removed ./experimental/forever export from both packages
    • Think no longer has a fibers flag — recovery is automatic via alarm housekeeping

Patch Changes

  • #1270 87b4512 Thanks @threepointone! - Wire Session into Think as the storage layer, achieving full feature parity with AIChatAgent plus Session-backed advantages.

    Think (@cloudflare/think):

    • Session integration: this.messages backed by session.getHistory(), tree-structured messages, context blocks, compaction, FTS5 search
    • configureSession() override for context blocks, compaction, search, skills (sync or async)
    • assembleContext() returns { system, messages } with context block composition
    • onChatResponse() lifecycle hook fires from all turn paths
    • Non-destructive regeneration via trigger: "regenerate-message" with Session branching
    • saveMessages() for programmatic turn entry (scheduled responses, webhooks, proactive agents)
    • continueLastTurn() for extending the last assistant response
    • Custom body persistence across hibernation
    • sanitizeMessageForPersistence() hook for PII redaction
    • messageConcurrency strategies (queue/latest/merge/drop/debounce)
    • resetTurnState() extracted as protected method
    • unstable_chatRecovery with runFiber wrapping on all 4 turn paths
    • onChatRecovery() hook with ChatRecoveryContext
    • hasPendingInteraction() / waitUntilStable() for quiescence detection
    • Re-export Session from @cloudflare/think
    • Constructor wraps onStart — subclasses never need super.onStart()

    agents (agents/chat):

    • Extract AbortRegistry, applyToolUpdate + builders, parseProtocolMessage into shared agents/chat layer
    • Add applyChunkToParts export for fiber recovery

    AIChatAgent (@cloudflare/ai-chat):

    • Refactor to use shared AbortRegistry from agents/chat
    • Add continuation flag to OnChatMessageOptions
    • Export getAgentMessages() and tool part helpers
    • Add getHttpUrl() to useAgent return value

Don't miss a new agents release

NewReleases is sending notifications on new releases.