agents 0.32.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-sdk-CpuRsjP5.d.ts +72 -0
- package/dist/browser/ai.js +2 -3
- package/dist/browser/ai.js.map +1 -1
- package/dist/browser/index.d.ts +29 -21
- package/dist/browser/index.js +937 -4
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/tools/ai-sdk.d.ts +5 -70
- package/dist/browser/tools/ai-sdk.js +9 -3
- package/dist/browser/tools/ai-sdk.js.map +1 -1
- package/dist/browser/tools/pi.d.ts +11 -8
- package/dist/browser/tools/pi.js +58 -11
- package/dist/browser/tools/pi.js.map +1 -1
- package/dist/browser/tools/tanstack-ai.d.ts +4 -4
- package/dist/browser/tools/tanstack-ai.js +3 -3
- package/dist/browser/tools/tanstack-ai.js.map +1 -1
- package/dist/{browser-D9RNpJuT.d.ts → browser-CI97khiJ.d.ts} +222 -94
- package/dist/{browser-tool-BhjCcNVE.d.ts → browser-tool-Cxtiwfua.d.ts} +2 -2
- package/dist/browser-tool-DOqT1oSD.js +360 -0
- package/dist/browser-tool-DOqT1oSD.js.map +1 -0
- package/dist/chat/react.js +1 -0
- package/dist/chat/react.js.map +1 -1
- package/dist/cli.js +63 -62
- package/dist/{connector-CM-uuxKM.js → connector-Dl098To-.js} +402 -3
- package/dist/connector-Dl098To-.js.map +1 -0
- package/dist/experimental/webmcp.js +1 -1
- package/dist/harness/pi/index.d.ts +73 -26
- package/dist/harness/pi/index.js +77 -83
- package/dist/harness/pi/index.js.map +1 -1
- package/dist/{input-schema-BQykTEp_.js → input-schema-0uUu392-.js} +2 -2
- package/dist/input-schema-0uUu392-.js.map +1 -0
- package/dist/{input-schema-B0Etuo-o.js → input-schema-waggtYrH.js} +2 -2
- package/dist/input-schema-waggtYrH.js.map +1 -0
- package/dist/mcp/client/x402.d.ts +8 -8
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +3 -3
- package/dist/mcp/index.js.map +1 -1
- package/dist/models/pi-ai/index.js +11 -141
- package/dist/models/pi-ai/index.js.map +1 -1
- package/dist/{session-7CDgVE0z.js → session-CRY0bGiI.js} +423 -411
- package/dist/session-CRY0bGiI.js.map +1 -0
- package/dist/{tool-helpers-BI7ifO2S.js → tool-helpers-F3_Wy2YX.js} +2 -2
- package/dist/{tool-helpers-BI7ifO2S.js.map → tool-helpers-F3_Wy2YX.js.map} +1 -1
- package/dist/web/fetch/tools/ai-sdk.js +1 -1
- package/dist/web/fetch/tools/pi.d.ts +4 -7
- package/dist/web/fetch/tools/pi.js +7 -6
- package/dist/web/fetch/tools/pi.js.map +1 -1
- package/dist/web/fetch/tools/tanstack-ai.js +1 -1
- package/dist/web/search/tools/ai-sdk.js +1 -1
- package/dist/web/search/tools/pi.d.ts +5 -4
- package/dist/web/search/tools/pi.js +5 -10
- package/dist/web/search/tools/pi.js.map +1 -1
- package/dist/web/search/tools/tanstack-ai.js +1 -1
- package/docs/browse-the-web.md +36 -3
- package/docs/harnesses/pi.md +50 -30
- package/docs/models-pi-ai.md +1 -1
- package/package.json +14 -8
- package/dist/browser-1eUbPvC2.js +0 -931
- package/dist/browser-1eUbPvC2.js.map +0 -1
- package/dist/browser-tool-DRan7Lk6.js +0 -497
- package/dist/browser-tool-DRan7Lk6.js.map +0 -1
- package/dist/connector-CM-uuxKM.js.map +0 -1
- package/dist/input-schema-B0Etuo-o.js.map +0 -1
- package/dist/input-schema-BQykTEp_.js.map +0 -1
- package/dist/session-7CDgVE0z.js.map +0 -1
package/docs/browse-the-web.md
CHANGED
|
@@ -76,7 +76,29 @@ this.registry.install({
|
|
|
76
76
|
- A returned screenshot comes back as an image in the tool result, so the model can see the page and a UI can show it from the transcript. pi-ai only sends the image to models that accept images; other models get the text alone.
|
|
77
77
|
- Each pi conversation gets its own active tab: `scope` defaults to the calling conversation, so sessions, forks, and subagents on one object do not drive each other's page. Pass `scope` as a string to share one tab, or as a function of the call (`(api) => string`) to choose.
|
|
78
78
|
- pi does not rerun a browser call cut off by an eviction, because the code may have clicked or submitted something. The model gets an interrupted result and can try again; the browser itself is still there.
|
|
79
|
-
|
|
79
|
+
|
|
80
|
+
#### In pi's code mode
|
|
81
|
+
|
|
82
|
+
pi-durable's code mode lets the model write one script that calls several tools. Install it beside the browser tool, and scripts can call `tools.browser({ code })` with no other setup:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { RemoteCodemodeSandbox } from "@earendil-works/pi-codemode/cloudflare";
|
|
86
|
+
import { createCodemodeExtension } from "@earendil-works/pi-durable/codemode";
|
|
87
|
+
|
|
88
|
+
this.registry.install(
|
|
89
|
+
createCodemodeExtension({
|
|
90
|
+
sandbox: new RemoteCodemodeSandbox({
|
|
91
|
+
// A CodemodeSandboxDurableObject deployed as its own Worker.
|
|
92
|
+
remote: () => this.env.CODEMODE_SANDBOX.getByName(this.ctx.id.toString())
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
- `tools.browser()` resolves to the run as an object, `{ status, executionId, result, error, logs, notice }`, on errors too, so check `status`.
|
|
99
|
+
- A screenshot's `result` is an image block. Pass it to `image()` so the model sees it.
|
|
100
|
+
- A script's browser calls run in its conversation's tab, one at a time, even under `Promise.all`.
|
|
101
|
+
- The browser code is still a string inside the script, and each call runs in its own Dynamic Worker, as a direct call does.
|
|
80
102
|
|
|
81
103
|
### TanStack AI
|
|
82
104
|
|
|
@@ -119,9 +141,10 @@ To show a screenshot, the model returns it from its code. The full result, image
|
|
|
119
141
|
- The model writes an async arrow function against a `browser` global: `browser.cdp({ method, params, sessionId })` sends a command, `browser.attachToTarget({ targetId })` switches tabs, `browser.spec()` lists the protocol's domains and `browser.spec({ domain })` returns one, and `browser.getDebugLog()` shows recent traffic. `sessionId: "active"` points at the tab it is working in, and that tab is remembered across turns.
|
|
120
142
|
- The code runs in a fresh Dynamic Worker for each call, with no network access: `browser` is its only way out.
|
|
121
143
|
- The tool's description covers the `browser` API and the CDP mistakes models commonly make, so the model does not need a discovery pass first.
|
|
122
|
-
- If several chats or users share one `Browser` (for example, many threads on one Durable Object), pass each one's id as `scope`: `browserTool({ browser, loader, scope: threadId })`. Each scope keeps its own active tab, so one chat never drives another's page, while cookies and logins stay shared. Tools that leave `scope` out share one tab. Calls in the same scope wait for each other; calls in different scopes run in parallel.
|
|
144
|
+
- If several chats or users share one `Browser` (for example, many threads on one Durable Object), pass each one's id as `scope`: `browserTool({ browser, loader, scope: threadId })`. Each scope keeps its own active tab, so one chat never drives another's page, while cookies and logins stay shared. Tools that leave `scope` out share one tab. Calls in the same scope wait for each other (and for your own sessions opened with `lock: true`); calls in different scopes run in parallel. The wait does not count toward `timeoutMs`.
|
|
123
145
|
- The result's `notice` tells the model what happened to its browser: it was lost (idle past `keepAliveMs`, closed, or crashed) and the code ran in a new one, another chat closed its tab or works in it too, or the page opened new tabs.
|
|
124
146
|
- Each call times out after `timeoutMs` (default 60 seconds).
|
|
147
|
+
- When the harness aborts a call (the user stops the chat, say), a call still waiting for its scope gives up, and a running call ends with an error result and frees its scope. Anything its code already did in the browser stays done.
|
|
125
148
|
- Results are cut to about 24,000 characters. A screenshot can be at most 1 MB, so a full-page screenshot of a long page fails; the model is told to capture the viewport or use JPEG instead.
|
|
126
149
|
|
|
127
150
|
### Configure the browser
|
|
@@ -161,10 +184,20 @@ try {
|
|
|
161
184
|
});
|
|
162
185
|
} finally {
|
|
163
186
|
const report = await session.close();
|
|
164
|
-
// { restarted, newTabs, tabClosed, tabShared }, or undefined if unused
|
|
187
|
+
// { restarted, newTabs, tabClosed, tabShared, notices }, or undefined if unused
|
|
165
188
|
}
|
|
166
189
|
```
|
|
167
190
|
|
|
191
|
+
`report.notices` is the report as sentences for the model, the ones `browserTool` puts in its `notice`.
|
|
192
|
+
|
|
193
|
+
To give model-written code the same `browser` object the tool does (in a sandbox of your own, say), pass it `session.functions`, the `browser.*` functions bound to the session, and describe them with `this.browser.functionDocs()`, which returns `{ functions, rules }`: the functions in Markdown and the rules for using them. Add rules about how your code runs, such as timeouts and what happens to screenshots.
|
|
194
|
+
|
|
195
|
+
Runs in one scope drive one tab, so if yours can overlap with each other or with `browserTool` calls, open the session with `lock: true`. It takes the scope's lock at its first call and holds it until `close()`; other locking sessions in the scope, including `browserTool` runs, wait for it in order rather than fail. Every function in `session.functions`, the hosts functions included, waits for the lock and rejects once the session is closed. Call `await session.lock({ signal })` first to wait up front, outside any time limit of your own. A `signal` bounds only its own call: that call rejects when it aborts, and the session leaves the queue once no call is still waiting. A call without one, such as the wait a function call makes, never gives up. `session.waitedForLockMs` says how long the session waited.
|
|
196
|
+
|
|
197
|
+
A session that has the lock holds it until `close()`, whatever happens to the run: aborting a signal, losing the browser, or dropping the session does not release it, and the scope's other locking sessions wait until the Durable Object restarts. Close every locking session in a `finally` block or your run's cleanup, including when connecting failed.
|
|
198
|
+
|
|
199
|
+
For pi's per-conversation tabs, `conversationScope(String(conversationId))` from `agents/browser` returns the scope pi's `browserTool` uses, `conversation:<id>`. It takes a string and throws on an empty one.
|
|
200
|
+
|
|
168
201
|
### Internal hostnames
|
|
169
202
|
|
|
170
203
|
Give the browser hostnames that your Durable Object serves instead of the internet: files in an R2 bucket, a folder in its workspace, a dev server in its sandbox, or another Worker. Each host has a `fetch` function that runs in your Durable Object, so it can use its bindings and state:
|
package/docs/harnesses/pi.md
CHANGED
|
@@ -11,10 +11,10 @@ Pi owns everything about a run: the transcript, the inbox of steers and follow-u
|
|
|
11
11
|
## Install the Pi packages
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
|
-
npm install agents @earendil-works/pi-durable @earendil-works/pi-ai @earendil-works/chord
|
|
14
|
+
npm install agents @earendil-works/pi-durable @earendil-works/pi-ai @earendil-works/pi-schema @earendil-works/chord
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
The
|
|
17
|
+
The four Pi packages are optional peer dependencies of `agents`, at `~1.5.0`. pi-durable is experimental, and its API can change in minor releases, so `agents` supports one Pi minor at a time. A new Pi minor can also store conversations in formats the previous one cannot read: after a conversation runs on Pi 1.5, rolling your Worker back to an `agents` version on Pi 1.4 leaves that conversation unreadable. Roll forward to fix a bad deploy instead. The examples use Workers AI through the `AI` binding. To configure the binding and choose other models, refer to [Models for pi-ai](../models-pi-ai.md).
|
|
18
18
|
|
|
19
19
|
## Create the harness
|
|
20
20
|
|
|
@@ -61,7 +61,7 @@ export class Assistant extends DurableObject<Env> {
|
|
|
61
61
|
| Option | What it is |
|
|
62
62
|
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
63
63
|
| `harness` | Required. Receives `{ storage, context, onWake }` and returns Pi's `Harness`, usually from `Harness.open`. Pass `onWake` to `Harness.open`, so the object can hibernate while Pi's tasks sleep (see [How recovery works](#how-recovery-works)). Models, the registry, `settings`, `env` and `onReport` are all yours to build here. |
|
|
64
|
-
| `defaults` | What a new session starts with: `model`, a pi-ai `Model` such as `ai("@cf/…")`, and `
|
|
64
|
+
| `defaults` | What a new session starts with: `model`, a pi-ai `Model` such as `ai("@cf/…")`, `thinkingLevel`, and `maxTurns`, the most tool rounds one run takes before it ends unanswered (`turn_limit`). Without a model, a session's prompts end unanswered (`no_model`) until one is set. |
|
|
65
65
|
|
|
66
66
|
Create the registry per object, as the `registry` field above does, not at module scope: Pi keeps every `Harness` subscribed to its registry until the `Harness` closes, and an evicted object never closes it.
|
|
67
67
|
|
|
@@ -74,13 +74,13 @@ A model in `defaults` or `session.setModel()` is stored by its provider and id o
|
|
|
74
74
|
Tools and system prompt sections are Pi extensions. An extension is a plain object with a `name`, `tools` and `sections`:
|
|
75
75
|
|
|
76
76
|
```ts
|
|
77
|
-
import { Type } from "@earendil-works/pi-ai";
|
|
78
77
|
import {
|
|
79
78
|
createRegistry,
|
|
80
79
|
type ToolRegistration
|
|
81
80
|
} from "@earendil-works/pi-durable";
|
|
81
|
+
import { obj, str } from "@earendil-works/pi-schema";
|
|
82
82
|
|
|
83
|
-
const WordCount =
|
|
83
|
+
const WordCount = obj({ text: str() });
|
|
84
84
|
|
|
85
85
|
const wordCount: ToolRegistration<typeof WordCount> = {
|
|
86
86
|
name: "word_count",
|
|
@@ -189,24 +189,42 @@ const receipt = await session.submit("Summarize the latest report", {
|
|
|
189
189
|
const result = await session.wait(receipt.operationId);
|
|
190
190
|
```
|
|
191
191
|
|
|
192
|
-
| Call
|
|
193
|
-
|
|
|
194
|
-
| `prompt(input)`
|
|
195
|
-
| `submit(input, { operationId, whenBusy, entry })` | Hands the input to Pi and returns as soon as Pi has saved it, without waiting for the model. If the session is already working, the input waits until that work finishes. With `whenBusy: "steer"`, it joins the running work instead, after the current round of tool calls. With `whenBusy: "reject"`, it is not admitted: `submit` rejects with Pi's `ConversationBusy` and nothing is saved, so the same `operationId` can be submitted again later. `entry` records where the input came from (see below). |
|
|
196
|
-
| `wait(operationId, signal?)`
|
|
197
|
-
| `steer(input)`
|
|
198
|
-
| `
|
|
199
|
-
| `
|
|
200
|
-
| `
|
|
201
|
-
| `messages()`
|
|
202
|
-
| `
|
|
203
|
-
| `
|
|
204
|
-
| `
|
|
205
|
-
| `
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
192
|
+
| Call | What it does |
|
|
193
|
+
| ----------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
194
|
+
| `prompt(input)` | Submits and waits: the answer, and the transcript after it. |
|
|
195
|
+
| `submit(input, { operationId, whenBusy, whenIdle, entry })` | Hands the input to Pi and returns as soon as Pi has saved it, without waiting for the model. If the session is already working, the input waits until that work finishes. With `whenBusy: "steer"`, it joins the running work instead, after the current round of tool calls. With `whenBusy: "reject"`, it is not admitted: `submit` rejects with Pi's `ConversationBusy` and nothing is saved, so the same `operationId` can be submitted again later. With `whenIdle: "reject"`, an idle session refuses the input the same way, with Pi's `ConversationIdle`, so it never starts a run of its own; with `whenBusy: "steer"`, the input joins the running work or is refused, without racing the run's end. `entry` records where the input came from (see below). |
|
|
196
|
+
| `wait(operationId, signal?)` | The operation's result once Pi settles it. Aborting `signal` stops only the wait, not the work. |
|
|
197
|
+
| `steer(input)` | `submit` with `whenBusy: "steer"`. |
|
|
198
|
+
| `continue({ operationId })` | Starts a run on the transcript as it is, without a new message, for example after a run ended unanswered. Only an idle session takes one: a busy one rejects with Pi's `ConversationBusy`. Inputs kept behind a failed run join it. A transcript that ends in an answer has nothing to continue: the operation settles `unanswered` with reason `nothing_to_answer`. |
|
|
199
|
+
| `abort(operationId?)` | Withdraws a queued operation, or with no id, stops everything running in the session. |
|
|
200
|
+
| `pending()` | Operations Pi has not settled yet: queued, or part of the running work. |
|
|
201
|
+
| `messages()` | Pi's transcript entries since the newest reset. |
|
|
202
|
+
| `watch(window?)` | Pi's view of the session: 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. Each change carries Pi's operations, for a client that forwards them. |
|
|
203
|
+
| `entries(query, limit)` | A page of the session's transcript, including entries before its resets. Pages a transcript longer than the view's window. |
|
|
204
|
+
| `reset(handoff?)` | Starts a new context, optionally from a handoff note. |
|
|
205
|
+
| `setModel(model)` | Changes this session's model. |
|
|
206
|
+
| `busy()` | Whether a run is going. |
|
|
207
|
+
|
|
208
|
+
`harness.prompt()`, `submit()`, `wait()`, `abort()`, `messages()` and `pending()` act on the root session, or on `{ session }`. `harness.sessions` has `create()`, `fork(from)`, `get(id)` and `list()`, which includes sessions subagents created. `ROOT_SESSION` is the root's id.
|
|
209
|
+
|
|
210
|
+
`messages()` and `watch()` are Pi's own records, not a UI-ready chat transcript. The example below projects them into one.
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
const watch = await session.watch();
|
|
214
|
+
render(watch.value);
|
|
215
|
+
watch.start(async (call) => {
|
|
216
|
+
if (call.kind === "value") render(call.value);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
function render(view: ConversationView): void {
|
|
220
|
+
const live = view.docs["pi.live"] as LiveState;
|
|
221
|
+
drawEntries(view.entries);
|
|
222
|
+
if (live.generation?.message) drawStreaming(live.generation.message);
|
|
223
|
+
if (live.runFailure) drawFailure(live.runFailure);
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
The window holds the newest 50 entries and grows to 100 before its oldest leave. To render a longer transcript, merge each value into Pi's `ConversationTranscript`, which pages older entries with `session.entries()`.
|
|
210
228
|
|
|
211
229
|
### Label input the user did not type
|
|
212
230
|
|
|
@@ -218,7 +236,7 @@ await session.submit("The deploy was approved. Run the migration.", {
|
|
|
218
236
|
});
|
|
219
237
|
```
|
|
220
238
|
|
|
221
|
-
The model sees no difference: it still gets the text as a user message. Only the transcript changes. The input is stored with your `kind` and `data` instead of `pi.user`, and `messages()` and `
|
|
239
|
+
The model sees no difference: it still gets the text as a user message. Only the transcript changes. The input is stored with your `kind` and `data` instead of `pi.user`, and `messages()`, `watch()` and `entries()` return both, so your UI can show it differently, for example as "Approved by ben" rather than as something the user said. Pi reserves kinds that start with `pi.`, so use a prefix of your own, such as `app.`.
|
|
222
240
|
|
|
223
241
|
The kind is a label, not a permission. It records what your code said the input was, and nothing checks it. The model reads the input as if the user wrote it, so do not put anything in it that you would not let the user send.
|
|
224
242
|
|
|
@@ -226,7 +244,7 @@ The example app folds the transcript into chat messages, ignores `kind` and `dat
|
|
|
226
244
|
|
|
227
245
|
### Inputs queued behind a failed run
|
|
228
246
|
|
|
229
|
-
A run fails with `model_error` when the model errors and Pi does not retry or the error outlasts its retries,
|
|
247
|
+
A run fails with `model_error` when the model errors and Pi does not retry or the error outlasts its retries, with `no_model` when the session has no usable model, and with `turn_limit` when it reaches `defaults.maxTurns` (after that round's tools ran). Its own operation settles `unanswered` with that reason; to answer it once the cause is fixed, call `session.continue()`. Pi's `settings.afterFailedRun` decides what happens to the inputs queued behind it. Refer to [Failures and Recovery](https://github.com/earendil-works/pi/tree/main/packages/durable#failures-and-recovery) in the pi-durable README for what each value does. Set it in the factory:
|
|
230
248
|
|
|
231
249
|
```ts
|
|
232
250
|
harness: ({ storage, context, onWake }) =>
|
|
@@ -252,16 +270,18 @@ With `keep`, the kept inputs are not work to Pi: its `wake()` counts tasks, not
|
|
|
252
270
|
|
|
253
271
|
## How recovery works
|
|
254
272
|
|
|
255
|
-
The harness schedules one lifecycle job, driven by Pi's `wake()`. While Pi has work running, the job waits on it and refreshes itself as a heartbeat. While Pi's tasks sleep, such as a retry backoff, the job is due when the first one wakes. Pi says when through the `onWake` the factory passes to `Harness.open`, and sets no in-memory timer of its own, so the object can hibernate until then. A task that sleeps while other work runs, such as a compaction retry during a generation, is resumed from the job's wait when it is due. Without `onWake` the harness still works, but Pi's timer keeps the object in memory, and billed, while a task sleeps, and the harness logs a warning. When Pi has nothing to do, the job completes. If the object is evicted or crashes, the job is still due, so its alarm restarts the object. Pi reopens its stored state and resumes the session's work: a replay-safe tool call runs again, and an unsafe one is reported to the model as interrupted.
|
|
273
|
+
The harness schedules one lifecycle job, driven by Pi's `wake()`. While Pi has work running, the job waits on it and refreshes itself as a heartbeat. While Pi's tasks sleep, such as a retry backoff, the job is due when the first one wakes. Pi says when through the `onWake` the factory passes to `Harness.open`, and sets no in-memory timer of its own, so the object can hibernate until then. A task that sleeps while other work runs, such as a compaction retry during a generation, is resumed from the job's wait when it is due. Without `onWake` the harness still works, but Pi's timer keeps the object in memory, and billed, while a task sleeps, and the harness logs a warning. When Pi has nothing to do, the job completes. If the object is evicted or crashes, the job is still due, so its alarm restarts the object. Pi reopens its stored state and resumes the session's work: a replay-safe tool call runs again, and an unsafe one is reported to the model as interrupted. A model request cut off mid-answer is not sent again at once: it counts as a failed attempt under `settings.retry`, and the next attempt waits out the backoff. With no retry left, the operation ends unanswered with reason `interrupted`.
|
|
274
|
+
|
|
275
|
+
Pi shows a streaming answer and running tool output at once, but stores them in batches: with the next change that depends on them, such as the end of the answer, and at the latest after `settings.progress.persistWithinMs` (default 1,000 ms). A crash mid-stream loses up to that much of the stream, and a generation cut off before its first store leaves no partial answer in the transcript. To store every update instead, at the cost of a storage write each, set `settings: { progress: { persistWithinMs: 0 } }` in the factory's `Harness.open`.
|
|
256
276
|
|
|
257
|
-
A task that keeps crashing the object would restart it forever, so Pi
|
|
277
|
+
A task that keeps crashing the object would restart it forever, so Pi ends a task cut off by a crash or eviction `settings.restartLimit` times in a row (default 5). A tool call ends with an error result the model sees, and the run goes on. A model request ends its run, and the run's operations end unanswered with reason `restart_limit`. Either way the job completes and the object can hibernate. If your factory passes `onReport` to `Harness.open`, Pi reports it there as `task_interrupted`. To run the work again, call `session.continue()`, which answers the transcript as it is, or submit it again.
|
|
258
278
|
|
|
259
|
-
A storage error closes Pi for good: the call that hit it rejects with the error, and calls and `
|
|
279
|
+
A storage error closes Pi for good: the call that hit it rejects with the error, and calls underway reject with Pi's `SessionFailed` and `watch()` handles already open end with `{ kind: "failed" }`, so retry them. If your factory passes `onReport` to `Harness.open`, Pi reports the failure there as `storage_failed`. Once the failed Pi has closed, the harness opens Pi again, which runs the factory again, on the next call or the job's next step. Closing waits for running task code, such as a tool call, to return, so code that ignores its abort signal delays the reopen. Pi recovers from what it committed and resumes its work the same way.
|
|
260
280
|
|
|
261
|
-
If a step of the job fails, such as when the factory throws, the job is not dropped. It tries again after 30 seconds, doubling the delay with each failure in a row up to 10 minutes, and goes back to its usual schedule once a step succeeds. A Durable Object memory-limit reset that fails Pi while the job waits on it counts against the alarm's memory-limit circuit breaker. Lifecycle backs the job off and drops it after repeated resets. The next call opens Pi again and pushes the job again, so Pi's restart limit is what eventually
|
|
281
|
+
If a step of the job fails, such as when the factory throws, the job is not dropped. It tries again after 30 seconds, doubling the delay with each failure in a row up to 10 minutes, and goes back to its usual schedule once a step succeeds. A Durable Object memory-limit reset that fails Pi while the job waits on it counts against the alarm's memory-limit circuit breaker. Lifecycle backs the job off and drops it after repeated resets. The next call opens Pi again and pushes the job again, so Pi's restart limit is what eventually ends a task that keeps causing resets.
|
|
262
282
|
|
|
263
283
|
Every operation waits for the object's startup, which runs the factory. A call over RPC that arrives first waits for it rather than opening Pi on its own.
|
|
264
284
|
|
|
265
285
|
## Run the example
|
|
266
286
|
|
|
267
|
-
The [Pi harness example](https://github.com/cloudflare/agents/tree/main/examples/next/harnesses/pi)
|
|
287
|
+
The [Pi harness example](https://github.com/cloudflare/agents/tree/main/examples/next/harnesses/pi) sends `session.watch()` over WebSockets and projects Pi's view into a browser transcript. Its tools come from a `Workspace` from `@cloudflare/computer`: files, `exec` for JavaScript in a Dynamic Worker, and git. It uses a Workers AI model.
|
package/docs/models-pi-ai.md
CHANGED
|
@@ -369,7 +369,7 @@ Every other model in the catalog takes the full set.
|
|
|
369
369
|
|
|
370
370
|
## Requirements
|
|
371
371
|
|
|
372
|
-
This subpath needs `@earendil-works/pi-ai@~1.
|
|
372
|
+
This subpath needs `@earendil-works/pi-ai@~1.5.0`, an optional peer of `agents`. `agents`
|
|
373
373
|
takes no vendor package as a dependency, optional or otherwise. An unlisted `@cf/` id resolves with default metadata (a
|
|
374
374
|
128k context window, 8192 output tokens, zero cost); pass overrides when you know better.
|
|
375
375
|
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"bin": {
|
|
13
13
|
"agents": "./dist/cli.js"
|
|
14
14
|
},
|
|
15
|
-
"version": "0.
|
|
15
|
+
"version": "0.33.0",
|
|
16
16
|
"sideEffects": [
|
|
17
17
|
"./dist/cli.js"
|
|
18
18
|
],
|
|
@@ -46,10 +46,12 @@
|
|
|
46
46
|
"@ai-sdk/react": "^4.0.0",
|
|
47
47
|
"@ai-sdk/valibot": "3.0.6",
|
|
48
48
|
"@cloudflare/codemode": "^0.5.6",
|
|
49
|
-
"@earendil-works/chord": "~1.
|
|
50
|
-
"@earendil-works/pi-ai": "~1.
|
|
51
|
-
"@earendil-works/pi-
|
|
52
|
-
"@earendil-works/pi-
|
|
49
|
+
"@earendil-works/chord": "~1.5.0",
|
|
50
|
+
"@earendil-works/pi-ai": "~1.5.0",
|
|
51
|
+
"@earendil-works/pi-codemode": "~1.5.0",
|
|
52
|
+
"@earendil-works/pi-durable": "~1.5.0",
|
|
53
|
+
"@earendil-works/pi-schema": "~1.5.0",
|
|
54
|
+
"@earendil-works/pi-tui": "1.5.0",
|
|
53
55
|
"@modelcontextprotocol/client": "2.4.0",
|
|
54
56
|
"@modelcontextprotocol/conformance-v2": "npm:@modelcontextprotocol/conformance@0.2.0-alpha.12",
|
|
55
57
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
@@ -75,9 +77,10 @@
|
|
|
75
77
|
"@ai-sdk/provider": "^4.0.0",
|
|
76
78
|
"@ai-sdk/react": "^3.0.0 || ^4.0.0",
|
|
77
79
|
"@cloudflare/codemode": ">=0.5.0",
|
|
78
|
-
"@earendil-works/chord": "~1.
|
|
79
|
-
"@earendil-works/pi-ai": "~1.
|
|
80
|
-
"@earendil-works/pi-durable": "~1.
|
|
80
|
+
"@earendil-works/chord": "~1.5.0",
|
|
81
|
+
"@earendil-works/pi-ai": "~1.5.0",
|
|
82
|
+
"@earendil-works/pi-durable": "~1.5.0",
|
|
83
|
+
"@earendil-works/pi-schema": "~1.5.0",
|
|
81
84
|
"@modelcontextprotocol/client": "2.4.0",
|
|
82
85
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
83
86
|
"@modelcontextprotocol/server": "2.4.0",
|
|
@@ -112,6 +115,9 @@
|
|
|
112
115
|
"@earendil-works/pi-durable": {
|
|
113
116
|
"optional": true
|
|
114
117
|
},
|
|
118
|
+
"@earendil-works/pi-schema": {
|
|
119
|
+
"optional": true
|
|
120
|
+
},
|
|
115
121
|
"@modelcontextprotocol/sdk": {
|
|
116
122
|
"optional": true
|
|
117
123
|
},
|