How to Build Hibernating Agent Tools With Cloudflare Agents SDK v0.34.0
Image: Cloudflare changelog card for the Agents SDK Pi 1.6 release. Long-running AI agents hit an expensive wall the moment they need a human to click "Approve" or wait five minutes for a subagent. Keeping a stateful se
Image: Cloudflare changelog card for the Agents SDK Pi 1.6 release.
Long-running AI agents hit an expensive wall the moment they need a human to click "Approve" or wait five minutes for a subagent. Keeping a stateful serverless container or Durable Object awake while a user reads a Slack message wastes compute and risks hitting execution timeouts.
On November 20, 2026, Cloudflare released Agents SDK v0.34.0, upgrading PiHarness to Pi 1.6. The headline change lets a Pi tool park itself while waiting for a person, a deadline, or another agent session, releasing its active invocation so the underlying Durable Object can hibernate or even be evicted until a signal wakes it back up.
How parked tools and signals work in Pi 1.6
In previous versions, a tool waiting on external input had to block or manage custom state-machine boilerplate outside the tool call. In Pi 1.6, a tool's execute handler can return a sleep object specifying target signals or a deadline instead of returning a final tool output.
While that tool is parked, the session's overall run remains open, yet no JavaScript invocation stays pinned in memory. Once your application receives the user's answer or webhook callback, calling this.harness.signal(taskId, SignalDef, key, payload) wakes the Durable Object and re-runs the tool from the top with the delivered signal value.
To wire up a human-in-the-loop prompt, start by defining a versioned signal schema with defineSignal from @earendil-works/pi-durable and @earendil-works/pi-schema. For example, you might declare an Answer signal named app.answer at version 1 with a string text field. Inside your tool's execute({ question }, api, context) handler, call api.readSignal(Answer, "answer", context) first. If a signal value is already present, return { output: [{ type: "text", text: answer.value.text }] } immediately. Otherwise, trigger your UI notification with showQuestion(api.taskId, question) and return { sleep: { signals: [Answer.key("answer")] } } so the object can hibernate safely.
Because execute runs again from the beginning when harness.signal() fires, checking api.readSignal(Answer, "answer", context) at the top of the handler keeps the tool idempotent and avoids duplicate UI prompts. Beyond human-in-the-loop questions, Pi 1.6 extends this same parking pattern to two other workflows:
-
Subagent coordination:
submit()andcontinue()now accept anotifyoption so a parked parent tool wakes automatically when a child session settles. -
Approval gates: A
beforeToolhook can park a tool call prior to execution, letting you enforce manual sign-off before destructive API calls run.
Expand
Cloudflare Blog illustration for building durable execution on Workers
Image: Cloudflare Blog
Session seeding, abort safety, and Pi 1.5 vs. Pi 1.6
Agents SDK v0.34.0 also fixes several friction points around session initialization, interrupted turns, and multi-tab chat recovery. Teams migrating from Pi 1.5 should review how the core lifecycle primitives changed.
| Capability | Pi 1.5 Behavior | Pi 1.6 in Agents SDK v0.34.0 |
|---|---|---|
| Waiting for human or subagent input | No parked tools; waiting needs your own state handling | Tool returns sleep on signals/deadlines; Durable Object hibernates |
| Signal delivery API | (await harness.pi()).signal() |
harness.signal() directly on PiHarness
|
| Seeding existing transcript | Manual post-create writes |
init option on harness.root(), sessions.create(), and sessions.fork()
|
| Queued messages on abort | Follow-up input could be dropped on stop |
submit(input, { onAbort: "keep" }) preserves queued messages |
| Failed HTTP and WebSocket errors | Returned error details in response | Generic 500 HTTP / 1011 WS close unless onFetchError() is implemented |
Because harness.root() now creates the root session on first use, you can seed an existing conversation transcript atomically in the same commit that initializes the session. Call harness.root() before reaching the root session through harness.pi(), and pass Pi's init payload to write initial messages right when the session is created. That removes a common race condition where an imported chat history appeared one turn late or failed to persist if a user disconnected immediately after opening a thread. For teams also pairing agents with headless browsers, this fits neatly alongside Cloudflare's browser tooling for AI agents.
Reliability fixes for chat, scheduling, and provider drops
Beyond the headline parking API, Pi 1.6 addresses several subtle production bugs that affected multi-tab chat apps and long-running provider streams. Chat actions including stop, clear, regenerate, and resume now synchronize reliably across browser tabs and during Durable Object recovery. If a user hits stop in one browser window while another tab is streaming, both views settle cleanly without leaving orphaned state.
On the scheduling side, Cloudflare fixed a race condition where a schedule, queue item, or Task run that had been cancelled or replaced could still execute again. Provider resiliency is improved as well: Pi now retries a wider set of dropped provider connections, and when Anthropic can no longer continue an existing message thread, agents/models/pi-ai resends the full conversation instead of failing the turn outright. Make sure your cleanup handlers call PiHarness.dispose() to free per-session state held by Pi AI.
Breaking changes, MCP errors, and model defaults
Upgrading to Agents SDK v0.34.0 introduces several breaking API changes that will fail silently or throw at runtime if you skip them. First, failed requests no longer leak internal error details by default: HTTP failures return a generic 500 and failed WebSocket upgrades close with code 1011. If your client UI expects structured error payloads, implement onFetchError() explicitly to choose the exact response body and status.
Second, MCP client error handling is stricter. When an MCP server requires the user to re-authenticate, the SDK throws MCPAuthorizationRequiredError containing an error.authUrl link you should surface to the user. A failed MCP server also stays in a failed state until your code explicitly calls reconnectMcpServer(id), preventing silent retry loops against broken external servers.
Third, if you import @earendil-works/pi-durable directly, RunEndTask has been renamed to HookTask, and code mode namespaces now come from Extension.namespace. On the model side, ai.image() and Pi AI's ai.images() now target FLUX.2 image models, claudeCode() defaults to claude-sonnet-5-5, and example templates move off Workers AI models retired on November 20, 2026.
Expand
Cloudflare Blog illustration for a scheduling system built on Workers and Durable Objects
Image: Cloudflare Blog
The one-way upgrade rule you cannot ignore
Cloudflare highlights one critical operational constraint in the v0.34.0 changelog: once a conversation runs on Pi 1.6, Pi 1.5 cannot execute its tool calls or model requests. That means you cannot roll back to a Pi 1.5 deployment if you hit a bug after live traffic touches a session.
Treat this deployment as a strict forward-only migration. Before pushing v0.34.0 to production, spin up a staging Worker with isolated Durable Object namespaces and exercise your harness.signal(), beforeTool, and harness.root() paths end-to-end. Verify that your frontend handles MCPAuthorizationRequiredError by routing users to error.authUrl and exposes a trigger for reconnectMcpServer(id). Confirm that onFetchError() returns the error shapes your client expects, and double-check that PiHarness.dispose() runs cleanly on teardown. Once live sessions touch Pi 1.6, keep a fast hotfix pipeline ready so you can roll forward cleanly if any edge case surfaces.
Originally published on Mango Developer.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.
