You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(think): built-in workspace for every Think agent (#1275)
Every Think instance now gets `this.workspace` — a Workspace backed by
the DO's SQLite storage, with no R2 required. Workspace tools (read,
write, edit, list, find, grep, delete) are automatically merged into
every `onChatMessage` call before `getTools()`.
Changes:
- think.ts: add `workspace` field (auto-initialized from DO SQLite),
import Workspace + createWorkspaceTools, merge workspace tools first
in onChatMessage tool spread, re-export Workspace from main entry
- package.json: @cloudflare/shell is now a required peer dependency
(removed from peerDependenciesMeta.optional)
- e2e worker: simplified TestAssistant — removed manual getTools()
override and direct Workspace/createWorkspaceTools imports, kept
R2 override as the canonical pattern for large file spillover
- examples/assistant: removed manual Workspace + createWorkspaceTools
wiring, removed @cloudflare/shell direct dependency
- README.md: added built-in workspace section, updated exports/peer
deps tables, added configureSession/onChatResponse to override points,
added session + skills documentation
- design/think.md: added built-in workspace subsection, updated
exports table descriptions
Made-with: Cursor
Add built-in workspace to Think. Every Think instance now has `this.workspace` backed by the DO's SQLite storage, and workspace tools (read, write, edit, list, find, grep, delete) are automatically merged into every chat turn. Override `workspace` to add R2 spillover for large files. `@cloudflare/shell` is now a required peer dependency.
Copy file name to clipboardExpand all lines: design/think.md
+15-9Lines changed: 15 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -319,11 +319,17 @@ Think inherits `runFiber()` from the `Agent` base class. Fiber state is persiste
319
319
320
320
## Tools
321
321
322
-
Think provides factory functions for common tool patterns, published as separate export paths.
322
+
Think provides a built-in workspace and factory functions for additional tool patterns.
323
+
324
+
### Built-in workspace
325
+
326
+
Every Think instance gets `this.workspace` — a `Workspace` (from `@cloudflare/shell`) backed by the DO's SQLite storage. Workspace tools (`read`, `write`, `edit`, `list`, `find`, `grep`, `delete`) are automatically merged into every `onChatMessage` call, before `getTools()`.
327
+
328
+
Override to add R2 spillover: `override workspace = new Workspace({ sql: this.ctx.storage.sql, r2: this.env.R2, name: () => this.name })`.
Seven file operation tools backed by abstract operation interfaces (`ReadOperations`, `WriteOperations`, etc.). A convenience function creates all tools from a `Workspace` instance, but you can also create tools against custom storage backends.
332
+
The individual tool factories are also exported for custom storage backends. Seven file operation tools backed by abstract operation interfaces (`ReadOperations`, `WriteOperations`, etc.).
Copy file name to clipboardExpand all lines: packages/think/README.md
+76-22Lines changed: 76 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,14 +25,38 @@ export class MyAgent extends Think<Env> {
25
25
}
26
26
```
27
27
28
-
That's it. Think handles the WebSocket chat protocol, message persistence, the agentic loop, message sanitization, stream resumption, and client tool support. Connect from the browser with `useAgentChat` from `@cloudflare/ai-chat`.
28
+
That's it. Think handles the WebSocket chat protocol, message persistence, the agentic loop, message sanitization, stream resumption, client tool support, and workspace file tools. Connect from the browser with `useAgentChat` from `@cloudflare/ai-chat`.
29
+
30
+
## Built-in workspace
31
+
32
+
Every Think agent gets `this.workspace` — a virtual filesystem backed by the DO's SQLite storage. Workspace tools (`read`, `write`, `edit`, `list`, `find`, `grep`, `delete`) are automatically available to the model.
33
+
34
+
```ts
35
+
exportclassMyAgentextendsThink<Env> {
36
+
getModel() { ... }
37
+
// this.workspace is ready to use — no setup needed
38
+
// workspace tools are auto-merged into every chat turn
When the LLM calls a client tool, the tool call chunk is sent to the client. The client executes it and sends back `CF_AGENT_TOOL_RESULT`. Think applies the result, persists the updated message, broadcasts `CF_AGENT_MESSAGE_UPDATED`, and optionally auto-continues the conversation (debounce-based — multiple rapid tool results coalesce into one continuation turn).
67
93
68
94
Tool approval flows are also supported via `CF_AGENT_TOOL_APPROVAL`.
69
95
96
+
### Session and context blocks
97
+
98
+
Think uses Session for conversation storage. Override `configureSession` to add persistent memory, skills, compaction, and search:
// Model gets load_context and unload_context tools automatically
125
+
```
126
+
70
127
### MCP integration
71
128
72
129
Think inherits MCP client support from the Agent base class. Set `waitForMcpConnections` to ensure MCP-discovered tools are available before `onChatMessage` runs:
-**Incremental persistence** — skips SQL writes for unchanged messages
126
-
-**Storage bounds** — set `maxPersistedMessages` to cap stored history
127
-
-**Messages on connect** — newly connected clients receive the current message list immediately
128
183
129
184
## Workspace tools
130
185
131
-
File operation tools backed by the Agents SDK `Workspace`:
186
+
File operation tools are built into Think and available to the model on every turn. For custom storage backends, the individual tool factories are also exported:
Each tool is an AI SDK `tool()` with Zod schemas. The underlying operations are abstracted behind interfaces (`ReadOperations`, `WriteOperations`, etc.) so you can create tools backed by custom storage.
195
+
Each tool is an AI SDK `tool()` with Zod schemas. The underlying operations are abstracted behind interfaces (`ReadOperations`, `WriteOperations`, etc.) so you can create tools backed by any storage.
141
196
142
197
## Code execution tool
143
198
@@ -148,7 +203,6 @@ import { createExecuteTool } from "@cloudflare/think/tools/execute";
0 commit comments