agents 0.31.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.
Files changed (148) hide show
  1. package/dist/{agent-routing-wS1TimZ_.d.ts → agent-routing-vVMA7m8Y.d.ts} +6 -6
  2. package/dist/agent-routing.d.ts +1 -1
  3. package/dist/agent-tool-types.d.ts +1 -1
  4. package/dist/{agent-tools-Bamxxb6Y.d.ts → agent-tools-gGXXkf1z.d.ts} +2 -2
  5. package/dist/agent-tools.d.ts +1 -1
  6. package/dist/agent-tools.js +0 -1
  7. package/dist/agent-tools.js.map +1 -1
  8. package/dist/{ai-sdk-hW3vntnk.d.ts → ai-sdk-CpuRsjP5.d.ts} +2 -2
  9. package/dist/browser/ai.js +2 -3
  10. package/dist/browser/ai.js.map +1 -1
  11. package/dist/browser/index.d.ts +29 -21
  12. package/dist/browser/index.js +937 -4
  13. package/dist/browser/index.js.map +1 -0
  14. package/dist/browser/tools/ai-sdk.d.ts +5 -5
  15. package/dist/browser/tools/ai-sdk.js +9 -3
  16. package/dist/browser/tools/ai-sdk.js.map +1 -1
  17. package/dist/browser/tools/pi.d.ts +11 -8
  18. package/dist/browser/tools/pi.js +58 -11
  19. package/dist/browser/tools/pi.js.map +1 -1
  20. package/dist/browser/tools/tanstack-ai.d.ts +6 -6
  21. package/dist/browser/tools/tanstack-ai.js +3 -3
  22. package/dist/browser/tools/tanstack-ai.js.map +1 -1
  23. package/dist/{browser-D9RNpJuT.d.ts → browser-CI97khiJ.d.ts} +222 -94
  24. package/dist/{browser-tool-BhjCcNVE.d.ts → browser-tool-Cxtiwfua.d.ts} +2 -2
  25. package/dist/browser-tool-DOqT1oSD.js +360 -0
  26. package/dist/browser-tool-DOqT1oSD.js.map +1 -0
  27. package/dist/catalog-BpOejOsE.js +239 -0
  28. package/dist/catalog-BpOejOsE.js.map +1 -0
  29. package/dist/catalog-BpiVV1OF.d.ts +173 -0
  30. package/dist/chat/index.d.ts +2 -2
  31. package/dist/chat/react.js +1 -0
  32. package/dist/chat/react.js.map +1 -1
  33. package/dist/chat-sdk/index.d.ts +1 -1
  34. package/dist/chat-sdk/index.js +1 -1
  35. package/dist/cli.js +63 -62
  36. package/dist/{client-wn4-yqGz.d.ts → client-eSfgYvd3.d.ts} +2 -2
  37. package/dist/client.d.ts +1 -1
  38. package/dist/{cloudflare-Dzvc7V2N.js → cloudflare-CUUm_9q9.js} +26 -4
  39. package/dist/cloudflare-CUUm_9q9.js.map +1 -0
  40. package/dist/{connector-CM-uuxKM.js → connector-Dl098To-.js} +402 -3
  41. package/dist/connector-Dl098To-.js.map +1 -0
  42. package/dist/{do-oauth-client-provider-DfsUcpc3.d.ts → do-oauth-client-provider-DtNqv7oj.d.ts} +26 -2
  43. package/dist/{index-YSKgfgg9.d.ts → emitter-BJZtCVjQ.d.ts} +6 -140
  44. package/dist/emitter-DPOVcCln.js +15 -0
  45. package/dist/emitter-DPOVcCln.js.map +1 -0
  46. package/dist/experimental/channels/web/index.js +1 -1
  47. package/dist/experimental/webmcp.js +1 -1
  48. package/dist/harness/container/index.js +0 -1
  49. package/dist/harness/container/index.js.map +1 -1
  50. package/dist/harness/container/runtime/index.js +2 -2
  51. package/dist/harness/opencode/index.js +0 -1
  52. package/dist/harness/opencode/index.js.map +1 -1
  53. package/dist/harness/pi/index.d.ts +84 -30
  54. package/dist/harness/pi/index.js +120 -224
  55. package/dist/harness/pi/index.js.map +1 -1
  56. package/dist/index.d.ts +2 -3
  57. package/dist/index.js +2 -2
  58. package/dist/{input-schema-BQykTEp_.js → input-schema-0uUu392-.js} +2 -2
  59. package/dist/input-schema-0uUu392-.js.map +1 -0
  60. package/dist/{input-schema-B0Etuo-o.js → input-schema-waggtYrH.js} +2 -2
  61. package/dist/input-schema-waggtYrH.js.map +1 -0
  62. package/dist/markdown-BZ-VLtA1.js +86 -0
  63. package/dist/markdown-BZ-VLtA1.js.map +1 -0
  64. package/dist/mcp/client/do-oauth-client-provider.d.ts +4 -2
  65. package/dist/mcp/client/do-oauth-client-provider.js +15 -1
  66. package/dist/mcp/client/do-oauth-client-provider.js.map +1 -1
  67. package/dist/mcp/client/index.d.ts +1 -1
  68. package/dist/mcp/client/x402.d.ts +8 -8
  69. package/dist/mcp/index.d.ts +2 -2
  70. package/dist/mcp/index.js +4 -4
  71. package/dist/mcp/index.js.map +1 -1
  72. package/dist/models/pi-ai/index.js +12 -15
  73. package/dist/models/pi-ai/index.js.map +1 -1
  74. package/dist/observability/ai/index.js +1 -2
  75. package/dist/observability/ai/index.js.map +1 -1
  76. package/dist/observability/index.d.ts +170 -9
  77. package/dist/observability/index.js +386 -11
  78. package/dist/observability/index.js.map +1 -1
  79. package/dist/react.d.ts +2 -2
  80. package/dist/resource-B59OV2a2.js +325 -0
  81. package/dist/resource-B59OV2a2.js.map +1 -0
  82. package/dist/routing/index.d.ts +1 -1
  83. package/dist/script-CFDLTk5b.d.ts +91 -0
  84. package/dist/script-workspace-BpdAYq1R.d.ts +41 -0
  85. package/dist/serializable.d.ts +1 -1
  86. package/dist/{session-7CDgVE0z.js → session-CRY0bGiI.js} +423 -411
  87. package/dist/session-CRY0bGiI.js.map +1 -0
  88. package/dist/skill-DRBcIBjC.d.ts +221 -0
  89. package/dist/skills/index.d.ts +275 -36
  90. package/dist/skills/index.js +265 -1534
  91. package/dist/skills/index.js.map +1 -1
  92. package/dist/skills/runner.d.ts +37 -0
  93. package/dist/skills/runner.js +912 -0
  94. package/dist/skills/runner.js.map +1 -0
  95. package/dist/skills/tools/ai-sdk.d.ts +36 -0
  96. package/dist/skills/tools/ai-sdk.js +94 -0
  97. package/dist/skills/tools/ai-sdk.js.map +1 -0
  98. package/dist/source-9RQzlEhM.d.ts +112 -0
  99. package/dist/{src-BGolXG_H.js → src-DoGNJ4Ud.js} +4 -5
  100. package/dist/src-DoGNJ4Ud.js.map +1 -0
  101. package/dist/sub-routing.d.ts +1 -1
  102. package/dist/tool-CxKsvxjm.js.map +1 -1
  103. package/dist/tool-DkT_DJBm.js.map +1 -1
  104. package/dist/{tool-helpers-BodWi4gd.js → tool-helpers-F3_Wy2YX.js} +2 -3
  105. package/dist/{tool-helpers-BodWi4gd.js.map → tool-helpers-F3_Wy2YX.js.map} +1 -1
  106. package/dist/vite.d.ts +2 -2
  107. package/dist/vite.js +10 -258
  108. package/dist/vite.js.map +1 -1
  109. package/dist/voice/index.d.ts +1 -1
  110. package/dist/web/fetch/tools/ai-sdk.js +1 -1
  111. package/dist/web/fetch/tools/pi.d.ts +4 -7
  112. package/dist/web/fetch/tools/pi.js +7 -6
  113. package/dist/web/fetch/tools/pi.js.map +1 -1
  114. package/dist/web/fetch/tools/tanstack-ai.js +1 -1
  115. package/dist/web/search/tools/ai-sdk.js +1 -1
  116. package/dist/web/search/tools/pi.d.ts +5 -4
  117. package/dist/web/search/tools/pi.js +5 -10
  118. package/dist/web/search/tools/pi.js.map +1 -1
  119. package/dist/web/search/tools/tanstack-ai.js +1 -1
  120. package/dist/websockets/index.js +1 -1
  121. package/dist/{websockets-CyoeosdO.js → websockets-C6SJtWCJ.js} +1 -2
  122. package/dist/{websockets-CyoeosdO.js.map → websockets-C6SJtWCJ.js.map} +1 -1
  123. package/dist/workflow-types.d.ts +1 -1
  124. package/dist/workflows.d.ts +1 -1
  125. package/dist/workflows.js +0 -1
  126. package/dist/workflows.js.map +1 -1
  127. package/docs/browse-the-web.md +36 -3
  128. package/docs/harnesses/pi.md +59 -33
  129. package/docs/mcp-client.md +23 -1
  130. package/docs/mcp-servers.md +2 -2
  131. package/docs/models-pi-ai.md +1 -1
  132. package/docs/observability.md +5 -3
  133. package/package.json +37 -22
  134. package/dist/browser-1eUbPvC2.js +0 -931
  135. package/dist/browser-1eUbPvC2.js.map +0 -1
  136. package/dist/browser-tool-lGnvEBLJ.js +0 -497
  137. package/dist/browser-tool-lGnvEBLJ.js.map +0 -1
  138. package/dist/cloudflare-Dzvc7V2N.js.map +0 -1
  139. package/dist/connector-CM-uuxKM.js.map +0 -1
  140. package/dist/index-iv9FTXX9.d.ts +0 -311
  141. package/dist/input-schema-B0Etuo-o.js.map +0 -1
  142. package/dist/input-schema-BQykTEp_.js.map +0 -1
  143. package/dist/session-7CDgVE0z.js.map +0 -1
  144. package/dist/skills/compile.d.ts +0 -40
  145. package/dist/skills/compile.js +0 -65
  146. package/dist/skills/compile.js.map +0 -1
  147. package/dist/src-BGolXG_H.js.map +0 -1
  148. package/skills-module.d.ts +0 -22
@@ -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 three Pi packages are optional peer dependencies of `agents`, at `~1.4.0`. pi-durable is experimental, and its API can change in minor releases, so `agents` supports one Pi minor at a time. 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).
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 `thinkingLevel`. Without a model, a session's prompts end unanswered (`no_model`) until one is set. |
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 = Type.Object({ text: Type.String() });
83
+ const WordCount = obj({ text: str() });
84
84
 
85
85
  const wordCount: ToolRegistration<typeof WordCount> = {
86
86
  name: "word_count",
@@ -118,13 +118,19 @@ Pi's extensions can do more: hooks on model requests and tool calls (`hook(ToolT
118
118
 
119
119
  ### Skills
120
120
 
121
- `skills(sources)` turns `agents/skills` sources (refer to [Agent Skills](../../think/index.md#agent-skills)) into a Pi extension named `agents.skills`. It has two tools, `activate_skill` and `read_skill_resource`, and a `skills` section that lists the skills. Install it in the factory, since it reads the sources:
121
+ `skills(sources)` turns `agents/skills` sources (refer to [Agent Skills](../../think/index.md#agent-skills)) into a Pi extension named `agents.skills`. It has two tools, `activate_skill` and `read_skill_resource`, and a `skills` section that lists the skills. Sources can read skills from a Computer Workspace (`workspace()`), an R2 bucket (`r2()`), or code (`manifest()`). Install it in the factory, since it reads the sources:
122
122
 
123
123
  ```ts
124
124
  import { skills } from "agents/harness/pi";
125
+ import * as agentSkills from "agents/skills";
125
126
 
126
127
  harness: async ({ storage, context, onWake }) => {
127
- this.registry.install(await skills(sources));
128
+ this.registry.install(
129
+ await skills([
130
+ agentSkills.workspace(workspace), // /workspace/.agents/skills
131
+ agentSkills.r2(this.env.SKILLS_BUCKET, { prefix: "skills/" })
132
+ ])
133
+ );
128
134
  return Harness.open(
129
135
  storage,
130
136
  { models, registry: this.registry, onWake },
@@ -133,7 +139,7 @@ harness: async ({ storage, context, onWake }) => {
133
139
  };
134
140
  ```
135
141
 
136
- The existing `@cloudflare/think` skills work out-of-the-box.
142
+ The sources are read once, when the factory builds the extension. The tools and their output match `@cloudflare/think`, so a skill behaves the same in both.
137
143
 
138
144
  ### Browser
139
145
 
@@ -183,24 +189,42 @@ const receipt = await session.submit("Summarize the latest report", {
183
189
  const result = await session.wait(receipt.operationId);
184
190
  ```
185
191
 
186
- | Call | What it does |
187
- | ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
188
- | `prompt(input)` | Submits and waits: the answer, and the transcript after it. |
189
- | `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). |
190
- | `wait(operationId, signal?)` | The operation's result once Pi settles it. Aborting `signal` stops only the wait, not the work. |
191
- | `steer(input)` | `submit` with `whenBusy: "steer"`. |
192
- | `abort(operationId?)` | Withdraws a queued operation, or with no id, stops everything running in the session. |
193
- | `pending()` | Operations Pi has not settled yet: queued, part of the running work, or `parked` (see [How recovery works](#how-recovery-works)). |
194
- | `retry()` | Runs again the tasks Pi's restart limit parked in the session's work. Resolves `false` when nothing was parked. |
195
- | `messages()` | Pi's transcript entries since the newest reset. |
196
- | `events()` | Pi's agent events: a `snapshot`, then one batch per commit. |
197
- | `reset(handoff?)` | Starts a new context, optionally from a handoff note. |
198
- | `setModel(model)` | Changes this session's model. |
199
- | `busy()` | Whether a run is going. |
200
-
201
- `harness.prompt()`, `submit()`, `wait()`, `abort()`, `retry()`, `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.
202
-
203
- `messages()` and `events()` are Pi's own records, not a UI-ready chat transcript. The example below folds them into one.
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()`.
204
228
 
205
229
  ### Label input the user did not type
206
230
 
@@ -212,7 +236,7 @@ await session.submit("The deploy was approved. Run the migration.", {
212
236
  });
213
237
  ```
214
238
 
215
- 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 `events()` 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.`.
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.`.
216
240
 
217
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.
218
242
 
@@ -220,7 +244,7 @@ The example app folds the transcript into chat messages, ignores `kind` and `dat
220
244
 
221
245
  ### Inputs queued behind a failed run
222
246
 
223
- A run fails with `model_error` when the model errors and Pi does not retry or the error outlasts its retries, and with `no_model` when the session has no usable model. Its own operation settles `unanswered` with that reason. 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:
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:
224
248
 
225
249
  ```ts
226
250
  harness: ({ storage, context, onWake }) =>
@@ -246,16 +270,18 @@ With `keep`, the kept inputs are not work to Pi: its `wake()` counts tasks, not
246
270
 
247
271
  ## How recovery works
248
272
 
249
- 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`.
250
276
 
251
- A task that keeps crashing the object would restart it forever, so Pi parks a task cut off by a crash or eviction `settings.restartLimit` times in a row (default 5) without progress. A parked task is not work: the job completes and the object can hibernate. Its operations show as `parked` in `pending()`, and `wait()` keeps waiting. If your factory passes `onReport` to `Harness.open`, Pi reports it there as `task_parked`. Once you have dealt with the cause, `session.retry()` runs it again and wakes the harness; `session.abort()` gives up on it instead.
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.
252
278
 
253
- A storage error closes Pi for good: the call that hit it rejects with the error, and calls and `events()` streams already underway end with Pi's `SessionFailed`, so retry them. If your factory passes `onReport` to `Harness.open`, Pi reports the failure there as `session_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.
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.
254
280
 
255
- 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 parks a task that keeps causing resets.
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.
256
282
 
257
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.
258
284
 
259
285
  ## Run the example
260
286
 
261
- The [Pi harness example](https://github.com/cloudflare/agents/tree/main/examples/next/harnesses/pi) streams `session.events()` over WebSockets and folds Pi's entries 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.
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.
@@ -60,7 +60,7 @@ available.
60
60
  Install the exact MCP client peer used by this Agents release:
61
61
 
62
62
  ```sh
63
- pnpm add agents @modelcontextprotocol/client@2.3.1
63
+ pnpm add agents @modelcontextprotocol/client@2.4.0
64
64
  ```
65
65
 
66
66
  The MCP client does not need `@modelcontextprotocol/sdk` or `@modelcontextprotocol/server`. Those packages are optional peers used only by the MCP server APIs.
@@ -367,6 +367,28 @@ class MyAgent extends Agent {
367
367
  }
368
368
  ```
369
369
 
370
+ #### Client ID Metadata Documents
371
+
372
+ Some authorization servers accept a [Client ID Metadata Document](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization#client-id-metadata-documents) instead of dynamic client registration. Pass `clientMetadataUrl` to use one. When a server advertises `client_id_metadata_document_supported`, the agent sends that URL as its `client_id`. Servers that don't advertise it still get dynamic client registration.
373
+
374
+ ```typescript
375
+ import { Agent, DurableObjectOAuthClientProvider } from "agents";
376
+ import type { AgentMcpOAuthProvider } from "agents";
377
+
378
+ class MyAgent extends Agent {
379
+ createMcpOAuthProvider(callbackUrl: string): AgentMcpOAuthProvider {
380
+ return new DurableObjectOAuthClientProvider(
381
+ this.ctx.storage,
382
+ this.name,
383
+ callbackUrl,
384
+ { clientMetadataUrl: "https://my-app.example.com/oauth/client.json" }
385
+ );
386
+ }
387
+ }
388
+ ```
389
+
390
+ Serve the document at that URL. `provider.clientMetadataDocument` returns its JSON: `client_id` is the URL and `redirect_uris` holds the callback URL. The authorization server checks every redirect URI against the document, so pass a fixed `callbackPath` to `addMcpServer` rather than relying on the per-instance default.
391
+
370
392
  ## Using MCP Capabilities
371
393
 
372
394
  Once connected, access the server's capabilities:
@@ -5,7 +5,7 @@ Build an MCP server on Workers with `createMcpHandler` from `agents/mcp/server`
5
5
  ## Install
6
6
 
7
7
  ```sh
8
- pnpm add agents @modelcontextprotocol/server@2.3.1 zod
8
+ pnpm add agents @modelcontextprotocol/server@2.4.0 zod
9
9
  ```
10
10
 
11
11
  `@modelcontextprotocol/server` is an optional peer dependency of `agents`, so your package manager does not install it for you. Use the exact version required by your installed Agents release.
@@ -279,7 +279,7 @@ If the handler lifecycle does not fit, use the SDK's `WebStandardStreamableHTTPS
279
279
  `McpAgent` is deprecated, but existing servers keep working. It is built on MCP SDK v1, which is an optional peer dependency of `agents`, so your package manager no longer installs it for you. Add the exact version your Agents release expects before you upgrade:
280
280
 
281
281
  ```sh
282
- pnpm add agents @modelcontextprotocol/sdk@1.32.1 zod
282
+ pnpm add agents @modelcontextprotocol/sdk@1.32.2 zod
283
283
  ```
284
284
 
285
285
  Keep importing `McpServer` from `@modelcontextprotocol/sdk/server/mcp.js` in an `McpAgent`. An SDK v2 server from `@modelcontextprotocol/server` cannot run inside `McpAgent`. The same applies to `WorkerTransport` and `createLegacyMcpHandler` from `agents/mcp`.
@@ -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.4.0`, an optional peer of `agents`. `agents`
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
 
@@ -438,9 +438,11 @@ exists:
438
438
  `gen_ai.response.finish_reasons` and `gen_ai.request.stop_sequences` are arrays
439
439
  in OTel. Workers' custom `Span.setAttribute` currently accepts only a string,
440
440
  number, or boolean, so the wrapper omits those attributes rather than placing
441
- JSON text under an array-typed key. Similarly, span status is state rather than
442
- an attribute: failures emit `error.type`, but the wrapper does not invent an
443
- `otel.status_code` attribute when Workers exposes no custom-span status setter.
441
+ JSON text under an array-typed key. Failures emit `error.type` and, on runtimes
442
+ with `Span.setStatus()` (the 2026-10-26 release or later), set span status
443
+ `error` without a description. Status is span state, exported to OpenTelemetry
444
+ destinations, not an attribute; the raw error message is never recorded.
445
+ Cancellations leave the status unset.
444
446
 
445
447
  ### Context and safety
446
448
 
package/package.json CHANGED
@@ -12,7 +12,10 @@
12
12
  "bin": {
13
13
  "agents": "./dist/cli.js"
14
14
  },
15
- "version": "0.31.0",
15
+ "version": "0.33.0",
16
+ "sideEffects": [
17
+ "./dist/cli.js"
18
+ ],
16
19
  "license": "MIT",
17
20
  "repository": {
18
21
  "directory": "packages/agents",
@@ -26,10 +29,10 @@
26
29
  "dependencies": {
27
30
  "@babel/plugin-proposal-decorators": "^8.0.2",
28
31
  "@cfworker/json-schema": "^4.1.1",
32
+ "@opentelemetry/api": "^1.9.0",
29
33
  "@rolldown/plugin-babel": "^0.2.3",
30
34
  "capnweb": "^0.12.0",
31
35
  "cron-schedule": "^6.0.0",
32
- "esbuild": "^0.28.1",
33
36
  "mimetext": "^3.0.28",
34
37
  "nanoid": "^5.1.16",
35
38
  "partysocket": "1.3.0",
@@ -42,15 +45,17 @@
42
45
  "@ai-sdk/provider": "^4.0.0",
43
46
  "@ai-sdk/react": "^4.0.0",
44
47
  "@ai-sdk/valibot": "3.0.6",
45
- "@cloudflare/codemode": "^0.5.5",
46
- "@earendil-works/chord": "~1.4.0",
47
- "@earendil-works/pi-ai": "~1.4.0",
48
- "@earendil-works/pi-durable": "~1.4.0",
49
- "@earendil-works/pi-tui": "1.4.0",
50
- "@modelcontextprotocol/client": "2.3.1",
48
+ "@cloudflare/codemode": "^0.5.6",
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",
55
+ "@modelcontextprotocol/client": "2.4.0",
51
56
  "@modelcontextprotocol/conformance-v2": "npm:@modelcontextprotocol/conformance@0.2.0-alpha.12",
52
- "@modelcontextprotocol/sdk": "1.32.1",
53
- "@modelcontextprotocol/server": "2.3.1",
57
+ "@modelcontextprotocol/sdk": "1.32.2",
58
+ "@modelcontextprotocol/server": "2.4.0",
54
59
  "@opencode/plugin": "2.0.24",
55
60
  "@opencode/sdk": "2.0.24",
56
61
  "@tanstack/ai": "0.38.0",
@@ -60,6 +65,7 @@
60
65
  "@x402/evm": "^2.17.0",
61
66
  "ai": "^7.0.0",
62
67
  "chat": "^4.31.0",
68
+ "esbuild": "^0.28.1",
63
69
  "glob": "^13.0.6",
64
70
  "highlight.js": "11.12.0",
65
71
  "just-bash": "^3.0.2",
@@ -71,15 +77,16 @@
71
77
  "@ai-sdk/provider": "^4.0.0",
72
78
  "@ai-sdk/react": "^3.0.0 || ^4.0.0",
73
79
  "@cloudflare/codemode": ">=0.5.0",
74
- "@earendil-works/chord": "~1.4.0",
75
- "@earendil-works/pi-ai": "~1.4.0",
76
- "@earendil-works/pi-durable": "~1.4.0",
77
- "@modelcontextprotocol/client": "2.3.1",
78
- "@modelcontextprotocol/sdk": "1.32.1",
79
- "@modelcontextprotocol/server": "2.3.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",
84
+ "@modelcontextprotocol/client": "2.4.0",
85
+ "@modelcontextprotocol/sdk": "1.32.2",
86
+ "@modelcontextprotocol/server": "2.4.0",
80
87
  "@opencode/plugin": "^2.0.24",
81
88
  "@opencode/sdk": "^2.0.24",
82
- "@tanstack/ai": ">=0.10.2 <1.0.0",
89
+ "@tanstack/ai": ">=0.10.2 <2.0.0",
83
90
  "@x402/core": "^2.0.0",
84
91
  "@x402/evm": "^2.0.0",
85
92
  "ai": "^6.0.0 || ^7.0.0",
@@ -108,6 +115,9 @@
108
115
  "@earendil-works/pi-durable": {
109
116
  "optional": true
110
117
  },
118
+ "@earendil-works/pi-schema": {
119
+ "optional": true
120
+ },
111
121
  "@modelcontextprotocol/sdk": {
112
122
  "optional": true
113
123
  },
@@ -533,10 +543,15 @@
533
543
  "import": "./dist/skills/index.js",
534
544
  "require": "./dist/skills/index.js"
535
545
  },
536
- "./skills/compile": {
537
- "types": "./dist/skills/compile.d.ts",
538
- "import": "./dist/skills/compile.js",
539
- "require": "./dist/skills/compile.js"
546
+ "./skills/tools/ai-sdk": {
547
+ "types": "./dist/skills/tools/ai-sdk.d.ts",
548
+ "import": "./dist/skills/tools/ai-sdk.js",
549
+ "require": "./dist/skills/tools/ai-sdk.js"
550
+ },
551
+ "./skills/runner": {
552
+ "types": "./dist/skills/runner.d.ts",
553
+ "import": "./dist/skills/runner.js",
554
+ "require": "./dist/skills/runner.js"
540
555
  }
541
556
  },
542
557
  "publishConfig": {
@@ -546,7 +561,6 @@
546
561
  "dist",
547
562
  "docs",
548
563
  "agents.tsconfig.json",
549
- "skills-module.d.ts",
550
564
  "README.md"
551
565
  ],
552
566
  "nx": {
@@ -579,6 +593,7 @@
579
593
  "test:voice:react": "vitest --project voice-react",
580
594
  "test:channels": "vitest --project channels",
581
595
  "test:browser": "vitest run --config src/browser-tests/vitest.config.ts",
596
+ "test:otel-runtime": "vitest run --config src/otel-tests/vitest.config.ts",
582
597
  "test:workers": "vitest --project workers",
583
598
  "test:chat": "vitest --project chat",
584
599
  "test:harness:opencode": "vitest --project harness-opencode",