@cloudflare/ai-chat@0.5.3
cloudflare/agents@cloudflare/ai-chat@0.5.3Apr 28, 2026by github-actions[bot]
AI Summary
This patch release adds external cancellation support to AIChatAgent's `saveMessages` and `continueLastTurn` methods via AbortSignal, along with protected `abortRequest` and `abortAllRequests` methods for subclasses. It also tightens the peer dependency on `agents` from >=0.8.7 to >=0.11.7 to reflect tested versions.
Key Highlights
- Added AbortSignal support to `saveMessages` and `continueLastTurn` for external cancellation of programmatic turns
- Introduced protected `abortRequest(id)` and `abortAllRequests()` methods for subclass use
- Extended `SaveMessagesResult.status` to include 'aborted' status alongside 'completed' and 'skipped'
- Tightened `agents` peer dependency floor from >=0.8.7 to >=0.11.7 (produces warning for older versions)
New Features
- AbortSignal support in `AIChatAgent.saveMessages` and `continueLastTurn` for cancelling AI inference mid-stream
- Protected `abortRequest(id, reason?)` method for cancelling specific turns by ID
- Protected `abortAllRequests()` method for cancelling all active turns
- New 'aborted' status in `SaveMessagesResult` when inference is cancelled
- Clean signal listener detachment after turn completion to prevent memory leaks
Full Release Notes
### Patch Changes
- [`ca510d4`](https://github.com/cloudflare/agents/commit/ca510d4fecbecb07d0d3cdad7d78c32cc226275e) Thanks [@threepointone](https://github.com/threepointone)! - Tighten the `agents` peer dependency floor from `>=0.8.7` to `>=0.11.7` to reflect the current monorepo set we actually test against. Upper bound (`<1.0.0`) is unchanged.
No runtime change in `@cloudflare/ai-chat` itself. The visible effect for consumers: pairing the latest `@cloudflare/ai-chat` with a stale `agents` (`<0.11.7`) now produces a peer warning where it previously did not. That's the intended signal — `agents` versions older than 0.11.7 are no longer tested against this `@cloudflare/ai-chat`.
- [#1411](https://github.com/cloudflare/agents/pull/1411) [`2fa68be`](https://github.com/cloudflare/agents/commit/2fa68bea891e1bd8f30839586c2519627f364b0c) Thanks [@threepointone](https://github.com/threepointone)! - Add `options.signal` to `AIChatAgent.saveMessages` and `continueLastTurn` for external cancellation of programmatic turns, plus protected `abortRequest(id)` / `abortAllRequests()` methods ([#1406](https://github.com/cloudflare/agents/issues/1406)).
`saveMessages` and `continueLastTurn` accept a second `SaveMessagesOptions` argument:
```typescript
const result = await this.saveMessages(messages, {
signal: controller.signal,
});
if (result.status === "aborted") {
// Inference loop terminated mid-stream; partial chunks persisted.
}
```
The signal is linked to AIChatAgent's per-turn `AbortController` and produces the same end state as a `chat-request-cancel` WebSocket message: the inference loop's signal aborts, partial chunks persist, the result reports `status: "aborted"`, and `onChatResponse` fires with the same status. Pre-aborted signals short-circuit before any model work runs. Listeners are detached cleanly when the turn finishes, so the same long-lived signal can be passed to many turns without leaking.
`abortRequest(id, reason?)` and `abortAllRequests()` are protected entry points for subclasses that want to cancel turns without tracking ids.
`SaveMessagesResult.status` now includes `"aborted"` alongside `"completed"` and `"skipped"`. Existing callers that only switch on `"completed"` are unaffected.
**Limitations.**
- `AbortSignal` cannot cross Durable Object RPC. Construct the controller inside the DO that calls `saveMessages`.
- The signal lives in memory only. If the DO hibernates mid-turn and `chatRecovery` is enabled, the recovered turn runs without the original signal.
See [`cloudflare/agents#1406`](https://github.com/cloudflare/agents/issues/1406) for the motivating use case.