Repository navigation
feat(agents)!: support Pi 1.6 - #2925
Merged
Merged
Conversation
Pi packages to ~1.6.0 (pi-tui 1.6.0 exact) in agents, the Pi examples and experimental/pi-recovery, and the pi-agent-core>pi-ai override to ~1.6.0. Pi 1.6 stores pi.tool v4 and pi.generation v3, which Pi 1.5 does not run, so the harness docs now warn against rolling back to an agents version on Pi 1.5. The changeset names the version and links its changelog.
pi-ai continues an Anthropic message thread for a session on api.anthropic.com, sending only the new messages. A live check showed AI Gateway forwards the thread field and the message-threads beta header on both the provider-native and /run routes, so the wire keeps pi-ai's default. Pin that a second turn continues the thread with only the new message and the beta header.
…ols array pi-ai openai-completions stopped sending "tools": [] when a request has no tools but its history has tool calls (Pi 7a6bd5a), with compat.requiresToolsWithToolHistory to restore it. Our wire builds tools itself and fills the flag as false; pin that a turn with no tools after tool calls omits tools.
pi-durable added signals, tools that park, gates and hook tasks (earendil-works/pi@473515f). - SubmissionDraft gained notify ({ taskId, key }), which delivers SubmissionSettled to a parked task when the submission settles. The contract test flagged it; PiSubmitOptions now passes it through, with docs. - A tool parked on a signal alone makes pi.wake() report { active: false } with no time. A new test proves the harness then sets no wake job or alarm, survives eviction, and finishes the call when the signal is delivered. The lifecycle docs say so.
…wire pi-ai's parseChunkUsage now falls back to usage.reasoning_tokens when completion_tokens_details.reasoning_tokens is missing or 0 (earendil-works/pi@86918f9). usageFromOpenAI mirrors it field for field, so it does too.
pi-durable now takes `onAbort: "keep"` on an input submission: the input stays queued through a conversation abort, and the next input places it. Expose it as `PiSubmitOptions.onAbort` (type `PiOnAbort`), keep the contract type test in step, and document how `abort()` treats such inputs. Upstream: earendil-works/pi@e67aa1a
pi-tui b7bb7ca made Component.render() return readonly string[] and Container cache its output (breaking). The Channels TUI's TextBlock returned Markdown's cached lines as string[], which no longer typechecks; it now declares readonly string[]. No Channels component modifies render output in place, and TranscriptView builds a new array, so the caching needs no other change.
…esponses wire pi-ai now records the replayed reasoning items OpenAI withheld from the model (input_transformations, such as prefix_mismatch after compaction on GPT-6.2) as an openai_input_transformations diagnostic inside processResponsesStream. The Responses wire uses that processor and appends its own cloudflare diagnostic beside it, so the new diagnostic reaches users with no code change; this test keeps it that way. It fails with the recording removed from pi-ai.
pi-ai's parseChunkUsage falls back to usage.cached_tokens, which Kimi reports on its final usage chunk (earendil-works/pi@d3ab2af). usageFromOpenAI now does the same, so those reads count as cacheRead and come out of input. The new test fails without the fallback.
🦋 Changeset detectedLatest commit: 3e899ee The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
Contributor
🔴 agents import sizes: 1 entry point over threshold
Changed exports (1)
How this worksEach runtime export is bundled on its own, minified, and gzipped. Changes smaller than 100 B, or smaller than 1% and 1 KiB, are ignored. Growth over 10% or 5 KiB is marked 🔴. This report is informational and does not fail CI. The workflow artifact contains every measurement. Compared |
pi-ai resends a rejected thread continue in full, and retries strict tools over Anthropic's limits without strict, only when the error is the Anthropic SDK's own APIError. The wire handed pi-ai a stand-in client that threw CloudflareAIError, so neither fallback ever ran: a turn after a thread expired (a few minutes idle, while pi-ai's thread state outlives the turn) failed instead of starting a new thread. Hand pi-ai a fetch instead of a client. pi-ai builds its own SDK client, the fetch routes the SDK's request through the gateway, and the SDK turns a vendor error response into its own error. The typed Cloudflare error is still what a failed stream reports. The thread test's comment no longer claims it shows AI Gateway forwards `thread`: it uses a fake binding. That was checked live.
Pi requires a host to arm its wake before anything that can start work: submit, signal, abort, or a registry change. The only way to signal a parked tool was harness.pi().signal(), which skips that. With onWake, Pi arms the job right after the commit, but without it the woken call had no job and no alarm, so a crash while it ran left it stranded until something else touched the object. - Add harness.signal(), which schedules the wake first. - Abort, withdraw and reset go through the same admission: stopping a parked call runs its cancel(), and reset runs kept inputs. - continue() takes notify, as Pi accepts it on every draft; the contract test now checks continue's options too. - Tests for a signal without onWake surviving a crash, a park with a deadline waking from the alarm, aborting a parked call after eviction, a beforeTool gate, and a tool waiting on a subagent, including a crash and an abort while the subagent runs. - pi.md: "Tools that wait" replaces the notify section. Its subagent sample is Pi's own pattern: the child is owned by the call, so aborting the parent stops it and a rerun finds it again, and the result is the child's answer. It also covers cancel(), gates rerunning on each open, and pending()/busy() while a call is parked.
The Pi and browser example views kept only tool slots that were running, so a call parked on a signal or a time disappeared and the UI showed "Waiting for the model". Keep sleeping and waiting slots, marked parked, and say the tool is waiting.
…ccurately Cached tokens are counted as cache reads, not reasoning tokens. Mention harness.signal(), continue()'s notify and the Anthropic thread fallback. Drop the pending "supports Pi 1.5.2" changeset, which would ship in the same release as "Pi 1.5 is no longer supported".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moves the Pi harness, the pi-ai models and the Pi tool adapters from Pi 1.5 to Pi 1.6.0. Pi 1.6 writes stored data that Pi 1.5 can't run, so
agentsdrops Pi 1.5 (~1.5.0→~1.6.0;pi-tuiexact). Nothing inagentsused the parts of Pi's API that 1.6 renamed or removed, so the only API changes here are additions.PiHarness: signals, tools that park,beforeToolgates, and hook tasks. A tool parked on a signal alone sets no wake job or alarm, survives eviction, and finishes when the signal arrives.harness.signal()does that;harness.pi().signal()doesn't, so withoutonWakea crash while the woken call ran left it stranded.abort()andreset(), which can start work too, now go through the same path.fetchinstead of a stand-in client. pi-ai builds its own SDK client, so a vendor error is the SDK's ownAPIError, which is what pi-ai's thread and strict-tools fallbacks check for. Before, a turn after a thread expired failed instead of starting a new thread (on main too).pi.md's "Tools that wait" covers signals,cancel(), gates and parked calls. Its subagent sample is Pi's own pattern: the child is owned by the call, so aborting the parent stops it.onWakesurviving a crash, a park with a deadline, aborting a parked call, abeforeToolgate and a tool waiting on a subagent. Others pin Pi behavior we rely on without code of our own, some of it from Pi 1.5.x: Pi's multi-row SQLite commits round-trip text on a real Durable Object, the chat-completions wire never sends"tools": [], and OpenAI'sopenai_input_transformationsdiagnostic arrives next to ours.~1.6.0, andpi.mdwarns against rolling back below Pi 1.6.Pi 1.6 also fixes, with no code here: O(n²) owner-chain walks, unhandled rejections from
Submission.wait()on close, and more retried provider socket errors.Harness.close()(viaPiHarness.dispose()) now frees pi-ai's per-session state.createAIfromagents/models/pi-aiis 17.1 KiB gzip larger, almost all from pi-ai'sopenaiSDK going from 7.19 to 7.59, which the chat-completions wire pulls in throughconvertMessages.Merge Danger
Once a conversation runs on Pi 1.6, it writes
pi.toolv4 andpi.generationv3, which Pi 1.5 (agents 0.33) can't run. Rolling a Worker back below this release blocks those conversations' tool calls and model requests (task_too_old). Rolling forward again is fine.They must move to Pi 1.6. Code that uses pi-durable directly follows its breaking changes:
RunEndTaskisHookTask, a tool'sexecute()may return a park,untilis optional on sleeping tasks, and code-mode namespaces come fromExtension.namespace. pi-durable is documented as experimental, with API changes in minor releases.