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

latest release: agents@0.8.0
13 hours ago

Minor Changes

  • #1150 81a8710 Thanks @threepointone! - feat: add sanitizeMessageForPersistence hook and built-in Anthropic tool payload truncation

    • New protected hook: sanitizeMessageForPersistence(message) — override this method to apply custom transformations to messages before they are persisted to storage. Runs after built-in sanitization. Default is identity (returns message unchanged).
    • Anthropic provider-executed tool truncation: Large string values in input and output of provider-executed tool parts (e.g. Anthropic code_execution, text_editor) are now automatically truncated. These server-side tool payloads can exceed 200KB and are dead weight once the model has consumed the result.

    Closes #1118

  • #1138 36e2020 Thanks @threepointone! - Drop Zod v3 from peer dependency range — now requires zod ^4.0.0. Replace dynamic import("ai") with z.fromJSONSchema() from Zod 4 for MCP tool schema conversion, removing the ai runtime dependency from the agents core. Remove ensureJsonSchema().

Patch Changes

  • #1151 b0c52a5 Thanks @whoiskatrin! - fix(ai-chat): simplify turn coordination API

    • rename waitForPendingInteractionResolution() to waitUntilStable() and make it wait for a fully stable conversation state, including queued continuation turns
    • add resetTurnState() for scoped clear handlers that need to abort active work and invalidate queued continuations
    • demote isChatTurnActive(), waitForIdle(), and abortActiveTurn() to private — their behavior is subsumed by waitUntilStable() and resetTurnState()
    • harden pending-interaction bookkeeping so rejected tool-result and approval applies do not leak as unhandled rejections
  • #1106 3184282 Thanks @threepointone! - fix: abort/stop no longer creates duplicate split messages (issue #1100)

    When a user clicked stop during an active stream, the assistant message was split into two separate messages. This happened because onAbort in the transport immediately removed the requestId from activeRequestIds, causing onAgentMessage to treat in-flight server chunks as a new broadcast.

    • WebSocketChatTransport: onAbort now keeps the requestId in activeRequestIds so in-flight server chunks are correctly skipped by the dedup guard
    • useAgentChat: onAgentMessage now cleans up the kept ID when receiving done: true, preventing a minor memory leak
  • #1142 5651ece Thanks @whoiskatrin! - fix(ai-chat): serialize chat turns and expose turn control helpers

    • queue onChatMessage() + _reply() work so user requests, tool continuations, and saveMessages() never stream concurrently
    • make saveMessages() wait for the queued turn to finish before resolving, and reuse the request id for reply cleanup
    • skip queued continuations and saveMessages() calls that were enqueued before a chat clear
    • capture saveMessages() context (_lastClientTools, _lastBody) at enqueue time so a later request cannot overwrite it before execution
    • add protected isChatTurnActive(), waitForIdle(), abortActiveTurn(), hasPendingInteraction(), and waitForPendingInteractionResolution() helpers for subclass code that needs to coordinate active turns and pending tool interactions
  • #1096 0d0b7d3 Thanks @threepointone! - fix(ai-chat): prevent duplicate messages after tool calls and orphaned client IDs

    • CF_AGENT_MESSAGE_UPDATED handler no longer appends when message not found in client state, fixing race between transport stream and server broadcast
    • _resolveMessageForToolMerge reconciles IDs by toolCallId regardless of tool state, preventing client nanoid IDs from leaking into persistent storage

Don't miss a new agents release

NewReleases is sending notifications on new releases.