智能体
developers.cloudflare.com ·
@Cloudflare Developers
Cloudflare Agents SDK 支持 Pi 1.5:减少存储写入并降低内存占用
Cloudflare Agents SDK v0.33.0 将 PiHarness 升级至 Pi 1.5。官方称流式输出改为批量持久化,SQLite 下长回答存储事务约减少 27 倍、并行工具轮次减少 5.7 倍,CPU 降约四分之一;2048 会话基准中单 harness 从 88 提升至 459 agent runs/s;500KB 工具调用流式处理的内存占用下降。默认设置下崩溃可能丢失约 1 秒流式进度。另新增 session.watch()、session.continue()、defaults.maxTurns,移除 retry() 与 parked 状态,并支持在 code mode 中调用 browserTool。
AI推荐理由 Cloudflare 官方 changelog 给出 Agents SDK v0.33.0 升级 PiHarness 至 Pi 1.5 的具体性能数据:SQLite 下长回答存储事务约减少 27 倍、并行工具轮次减少 5.7 倍、CPU 降约四分之一,2048 会话基准从 88 提升到 459 agent runs/s,并说明批量持久化可能丢失约 1 秒流式进度。信息密度高、可验证,但属厂商自测基准,未提供独立复现,且为 SDK 版本更新而非范式突破。
78
正文
Agents SDK v0.33.0 upgrades [`PiHarness`](https://developers.cloudflare.com/agents/harnesses/pi/) to [Pi 1.5 ↗︎](https://github.com/earendil-works/pi/blob/v1.5.0/packages/durable/CHANGELOG.md#150---2026-11-02). The release reduces storage transactions while streaming, improves throughput across many sessions, and reduces memory use when streaming large tool calls.
#### Performance improvements
* **Far fewer storage writes while streaming.** Pi stores streamed answers and tool output in batches, within a second of each update, instead of on every update. Over SQLite, this cuts storage transactions by about 27x for long answers and 5.7x for turns with parallel tools, and CPU by about a quarter.
* **Higher throughput across many sessions.** Pi's scheduler no longer rechecks every conversation on each commit. In a SQLite benchmark with 2,048 sessions, one Pi harness went from 88 to 459 agent runs per second.
* **Less memory on large answers.** Streaming a 500 KB tool call used to take about 20 seconds of CPU and a 100 MB heap. Pi now appends new text instead of copying it on every update.
Streaming updates remain visible immediately, but are persisted in batches. With the default settings, a crash can lose up to about one second of streamed progress. Refer to [Recovery](https://developers.cloudflare.com/agents/harnesses/pi/#recovery) to configure this interval.
#### Session and tool updates
* **A view of each session.** [`session.watch()`](https://developers.cloudflare.com/agents/harnesses/pi/#watch-sessions-from-clients) replaces `session.events()`. It returns the newest transcript entries and the session's live state, such as the answer being streamed, running tools, and why the last run ended without an answer.
* **Continue without adding a message.** The new `session.continue()` API starts a new run using the existing transcript, for example after a model error or when a run reaches its turn limit.
* **Turn limit.** `defaults.maxTurns` caps the tool rounds a run can take in new sessions.
* **Tasks that keep crashing end.** Pi now ends a task cut off by its restart limit instead of parking it. `retry()` and the `parked` status are removed.
* **Browser in Pi's code mode.** Scripts in [Pi's code mode](https://developers.cloudflare.com/agents/tools/browser/#use-it-in-pis-code-mode) can call `browserTool` and pass its screenshots to `image()`. `browserTool` also stops when the harness aborts its call.
#### Continue an unanswered conversation
For an existing session and submission `operationId`, check the result before offering a continuation. For example, after resolving a model error:
```
const result = await session.wait(operationId);
if (result.status === "unanswered" && result.reason === "model_error") {
const receipt = await session.continue({
operationId: `${operationId}:continue`,
});
const continued = await session.wait(receipt.operationId);
console.log(continued.status, continued.text);
}
```
```
const result = await session.wait(operationId);
if (result.status === "unanswered" && result.reason === "model_error") {
const receipt = await session.continue({
operationId: `${operationId}:continue`,
});
const continued = await session.wait(receipt.operationId);
console.log(continued.status, continued.text);
}
```
This starts a new run without appending a user message. The session must be idle. If the transcript already ends in an answer, the operation returns `unanswered` with reason `nothing_to_answer`. Refer to [Work with sessions](https://developers.cloudflare.com/agents/harnesses/pi/#work-with-sessions).
#### Upgrade
Once a conversation runs on Pi 1.5, Pi 1.4 cannot read it. After upgrading, roll forward to fix deployment issues rather than rolling back to Pi 1.4.
Update callers of `session.events()` to use `session.watch()`, and remove uses of `retry()` and the `parked` status. Refer to the [Pi Durable 1.5.0 changelog ↗︎](https://github.com/earendil-works/pi/blob/v1.5.0/packages/durable/CHANGELOG.md#150---2026-11-02) for the full list of breaking changes.
The [Agents SDK v0.33.0 changelog ↗︎](https://github.com/cloudflare/agents/blob/main/packages/agents/CHANGELOG.md#0330) has step-by-step upgrade instructions. Point your coding agent at them and upgrade today:
Copy promptPrompt copied!