@cloudflare/think 0.23.0 → 0.25.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/README.md +30 -40
- package/dist/{chat-sdk-BEjKXjCm.js → chat-sdk-4Nu96eDX.js} +375 -256
- package/dist/chat-sdk-4Nu96eDX.js.map +1 -0
- package/dist/extensions/index.d.ts +30 -72
- package/dist/extensions/index.js +45 -47
- package/dist/extensions/index.js.map +1 -1
- package/dist/{fetch-DO3uQ9py.js → fetch-BbYxtlff.js} +10 -2
- package/dist/fetch-BbYxtlff.js.map +1 -0
- package/dist/manager-B3rcb_6p.js +493 -0
- package/dist/manager-B3rcb_6p.js.map +1 -0
- package/dist/manager-CWGumyKi.d.ts +3391 -0
- package/dist/messengers/index.d.ts +54 -66
- package/dist/messengers/index.js +2 -2
- package/dist/messengers/telegram.d.ts +4 -4
- package/dist/messengers/telegram.js +1 -1
- package/dist/think.d.ts +2 -2
- package/dist/think.js +8493 -10725
- package/dist/think.js.map +1 -1
- package/dist/tools/browser.d.ts +1 -1
- package/dist/tools/browser.js +1 -1
- package/dist/tools/browser.js.map +1 -1
- package/dist/tools/execute.d.ts +2 -2
- package/dist/tools/execute.js +2 -2
- package/dist/tools/execute.js.map +1 -1
- package/dist/tools/extensions.d.ts +1 -1
- package/dist/tools/extensions.js +1 -1
- package/dist/tools/fetch.js +1 -1
- package/dist/workflows.d.ts +5 -2
- package/docs/actions.md +12 -0
- package/docs/channels.md +10 -4
- package/docs/client-tools.md +57 -27
- package/docs/context.md +92 -0
- package/docs/getting-started.md +4 -4
- package/docs/index.md +112 -52
- package/docs/lifecycle-hooks.md +10 -21
- package/docs/multi-chat.md +6 -6
- package/docs/programmatic-submissions.md +28 -10
- package/docs/sub-agents.md +45 -51
- package/docs/tools.md +41 -15
- package/docs/workflows.md +5 -4
- package/package.json +15 -10
- package/dist/chat-sdk-BEjKXjCm.js.map +0 -1
- package/dist/fetch-DO3uQ9py.js.map +0 -1
- package/dist/hook-proxy-DY2sBNa0.js +0 -117
- package/dist/hook-proxy-DY2sBNa0.js.map +0 -1
- package/dist/index-DDnny6kt.d.ts +0 -5847
- package/dist/manager-BubfmA3q.js +0 -313
- package/dist/manager-BubfmA3q.js.map +0 -1
- package/dist/manager-rze95KCk.d.ts +0 -235
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ import { routeAgentRequest } from "agents";
|
|
|
16
16
|
|
|
17
17
|
export class MyAgent extends Think<Env> {
|
|
18
18
|
getModel() {
|
|
19
|
-
return "@cf/
|
|
19
|
+
return "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
getSystemPrompt() {
|
|
@@ -187,17 +187,16 @@ Configure the backends, and the modules they offer, on the `Workspace`:
|
|
|
187
187
|
|
|
188
188
|
```ts
|
|
189
189
|
import { Workspace } from "@cloudflare/computer";
|
|
190
|
-
import {
|
|
190
|
+
import { CodemodeBackend } from "@cloudflare/computer/backends/codemode";
|
|
191
191
|
import { createGitModule } from "@cloudflare/computer/modules/git";
|
|
192
192
|
|
|
193
193
|
export class MyAgent extends Think<Env> {
|
|
194
194
|
override workspace = new Workspace({
|
|
195
195
|
storage: this.ctx.storage,
|
|
196
196
|
backends: [
|
|
197
|
-
new
|
|
198
|
-
id: "js",
|
|
197
|
+
new CodemodeBackend({
|
|
199
198
|
loader: this.env.LOADER,
|
|
200
|
-
modules: { "
|
|
199
|
+
modules: { "codemode:git": createGitModule() }
|
|
201
200
|
})
|
|
202
201
|
]
|
|
203
202
|
});
|
|
@@ -207,24 +206,23 @@ export class MyAgent extends Think<Env> {
|
|
|
207
206
|
To change a built-in tool, return a tool with the same name from `getTools()`.
|
|
208
207
|
To hide tools for a turn, return `activeTools` from `beforeTurn`.
|
|
209
208
|
|
|
210
|
-
Give a backend a `
|
|
211
|
-
import the agent's tools; files come from `node:fs`:
|
|
209
|
+
Give a backend a `codemode:tools` module, and code the model runs with `exec`
|
|
210
|
+
can import the agent's tools; files come from `node:fs`:
|
|
212
211
|
|
|
213
212
|
```ts
|
|
214
213
|
import { createToolBindings } from "@cloudflare/computer/modules/tools";
|
|
215
214
|
import { forAISDKTools } from "@cloudflare/computer/tools/ai-sdk";
|
|
216
215
|
|
|
217
|
-
new
|
|
218
|
-
id: "js",
|
|
216
|
+
new CodemodeBackend({
|
|
219
217
|
loader: this.env.LOADER,
|
|
220
218
|
modules: {
|
|
221
|
-
"
|
|
219
|
+
"codemode:tools": createToolBindings(forAISDKTools(() => this.getTools()))
|
|
222
220
|
}
|
|
223
221
|
});
|
|
224
222
|
```
|
|
225
223
|
|
|
226
224
|
```ts
|
|
227
|
-
import { getWeather } from "
|
|
225
|
+
import { getWeather } from "codemode:tools";
|
|
228
226
|
export default async () => (await getWeather({ city: "Lisbon" })).text;
|
|
229
227
|
```
|
|
230
228
|
|
|
@@ -341,7 +339,7 @@ Script execution requires a Worker Loader binding:
|
|
|
341
339
|
| --------------------------------------- | ------------------------------------------------------------- |
|
|
342
340
|
| `@cloudflare/think` | `Think`, `Session` — main class + re-exports |
|
|
343
341
|
| `agents/sessions` | `Sessions`, `Session`, `createCompactFunction`, attachments |
|
|
344
|
-
| `agents/context` | `
|
|
342
|
+
| `agents/context` | `Context`, providers, `ContextConfig` — prompt context |
|
|
345
343
|
| `@cloudflare/think/messengers` | Messenger contracts, Chat SDK bridge, state agent, delivery |
|
|
346
344
|
| `@cloudflare/think/messengers/telegram` | Telegram messenger provider and delivery helpers |
|
|
347
345
|
| `@cloudflare/think/tools/fetch` | `createFetchTools()` — opt-in allowlisted HTTP reads |
|
|
@@ -360,7 +358,6 @@ Script execution requires a Worker Loader binding:
|
|
|
360
358
|
| `getTools()` | `{}` | AI SDK `ToolSet` for the agentic loop |
|
|
361
359
|
| `getMessengers()` | `{}` | Messenger ingress and delivery declarations |
|
|
362
360
|
| `getScheduledTasks()` | `{}` | Code-declared recurring prompts |
|
|
363
|
-
| `getScheduledTasksScope()` | `"root"` | Which instances arm declared tasks — `"root"` or `"all"` (sub-agents too) |
|
|
364
361
|
| `getDefaultTimezone()` | `undefined` | Default timezone for wall-clock schedules |
|
|
365
362
|
| `maxSteps` | `10` | Max tool-call rounds per turn (property) |
|
|
366
363
|
| `sendReasoning` | `true` | Send reasoning chunks to chat clients |
|
|
@@ -478,9 +475,8 @@ turn. See the
|
|
|
478
475
|
### Scheduled tasks
|
|
479
476
|
|
|
480
477
|
Use `getScheduledTasks()` for code-declared recurring prompts or deterministic
|
|
481
|
-
scheduled handlers. Think reconciles these declarations on startup,
|
|
482
|
-
|
|
483
|
-
occurrence after each run.
|
|
478
|
+
scheduled handlers. Think reconciles these declarations on startup, keeps one
|
|
479
|
+
pending occurrence per task, and arms the next occurrence after each run.
|
|
484
480
|
|
|
485
481
|
```ts
|
|
486
482
|
import { Think } from "@cloudflare/think";
|
|
@@ -541,23 +537,16 @@ work such as creating a Workflow run or writing a run ledger. Delivery is
|
|
|
541
537
|
at-least-once; use `idempotencyKey` or `occurrenceKey` for your own durable
|
|
542
538
|
idempotency.
|
|
543
539
|
|
|
544
|
-
Declared tasks are armed on the
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
`
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
`internal_reconcileScheduledTasks()` after updating that data. During
|
|
555
|
-
reconciliation Think records the task row before creating the underlying Agent
|
|
556
|
-
schedule, so a `schedule_id` may be temporarily empty if the object is
|
|
557
|
-
interrupted mid-reconcile; the next reconcile repairs that pending row. The
|
|
558
|
-
task `retry` option retries the prompt or handler action before the failure is
|
|
559
|
-
logged. The next occurrence is still scheduled after the action succeeds or
|
|
560
|
-
exhausts its retries, so failed occurrences do not block future runs.
|
|
540
|
+
Declared tasks are armed on the agent that declares them, a sub-agent
|
|
541
|
+
included: each sub-agent arms its own, and its root wakes it when one is due.
|
|
542
|
+
|
|
543
|
+
Each task is one durable job holding its next occurrence. Static declarations
|
|
544
|
+
reconcile on startup. If `getScheduledTasks()` reads product-owned data that can change
|
|
545
|
+
while the Durable Object is live, call `internal_reconcileScheduledTasks()`
|
|
546
|
+
after updating that data. The task `retry` option retries the prompt or
|
|
547
|
+
handler action before the failure goes to `onError()`. The next occurrence is
|
|
548
|
+
still scheduled after the action succeeds or exhausts its retries, so failed
|
|
549
|
+
occurrences do not block future runs.
|
|
561
550
|
|
|
562
551
|
### Lifecycle hooks
|
|
563
552
|
|
|
@@ -803,11 +792,12 @@ export class MyAgent extends Think<Env> {
|
|
|
803
792
|
|
|
804
793
|
A block declared without a `provider` is auto-wired to durable per-agent SQLite,
|
|
805
794
|
so `memory` above is writable through the `set_context` tool with no extra
|
|
806
|
-
wiring. The
|
|
807
|
-
into: a cold wake reuses the exact prompt
|
|
795
|
+
wiring. The transcript records the system prompt each turn was sent with, so
|
|
796
|
+
there is nothing to opt into: a cold wake reuses the exact prompt the model
|
|
797
|
+
already cached.
|
|
808
798
|
|
|
809
799
|
The assembled blocks are available as `this.context` once the Lifecycle has
|
|
810
|
-
started. See [Context](https://github.com/cloudflare/agents/blob/main/docs/
|
|
800
|
+
started. See [Context](https://github.com/cloudflare/agents/blob/main/docs/think/context.md)
|
|
811
801
|
for providers, tools, and frozen-prompt behavior.
|
|
812
802
|
|
|
813
803
|
### Upgrading from 0.17
|
|
@@ -977,8 +967,8 @@ import { Think } from "@cloudflare/think";
|
|
|
977
967
|
type MyConfig = { modelTier: "fast" | "capable"; systemPrompt: string };
|
|
978
968
|
|
|
979
969
|
const MODEL_IDS = {
|
|
980
|
-
fast: "@cf/
|
|
981
|
-
capable: "@cf/
|
|
970
|
+
fast: "@cf/qwen/qwen3.8-27b",
|
|
971
|
+
capable: "@cf/deepseek-ai/deepseek-v4.1-flash-1017"
|
|
982
972
|
} as const;
|
|
983
973
|
|
|
984
974
|
export class MyAgent extends Think<Env> {
|
|
@@ -996,7 +986,7 @@ For values you want broadcast to connected clients, use `state` / `setState` fro
|
|
|
996
986
|
- **WebSocket protocol** — wire-compatible with `useAgentChat` from `@cloudflare/think/react`
|
|
997
987
|
- **Built-in workspace** — every agent gets `this.workspace` with file tools auto-wired
|
|
998
988
|
- **Lifecycle hooks** — `beforeTurn`, `beforeStep`, `onStepFinish`, `onChunk`, `onChatResponse` fire on every turn
|
|
999
|
-
- **Stream resumption** — page refresh replays
|
|
989
|
+
- **Stream resumption** — page refresh replays the stored chunks of the reply in flight
|
|
1000
990
|
- **Client tools** — accept tool schemas from clients, handle results and approvals
|
|
1001
991
|
- **Durable submissions** — accept webhook/RPC-triggered turns with idempotent retry and status inspection
|
|
1002
992
|
- **Messengers** — receive Chat SDK webhooks and deliver streamed replies with provider-safe recovery
|
|
@@ -1010,7 +1000,7 @@ For values you want broadcast to connected clients, use `state` / `setState` fro
|
|
|
1010
1000
|
|
|
1011
1001
|
## Code execution tool
|
|
1012
1002
|
|
|
1013
|
-
> **Deprecated.** Use `exec` with `
|
|
1003
|
+
> **Deprecated.** Use `exec` with `codemode:tools` (see [Built-in workspace](#built-in-workspace)).
|
|
1014
1004
|
|
|
1015
1005
|
Let the LLM write and run JavaScript in a sandboxed Worker:
|
|
1016
1006
|
|