[Agents] Draft workspaces documentation#31254
Conversation
|
This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:
|
c66bfae to
7f59be8
Compare
There was a problem hiding this comment.
1 critical issue and 13 suggestions.
- CRITICAL
src/content/docs/agents/tools/workspace.mdx:45—awaitin constructor is invalid TypeScript. - HIGH
src/content/docs/agents/tools/workspace.mdx:9,86,452— UsePackageManagerscomponent for install commands instead of bareshfences. - HIGH
src/content/docs/agents/tools/workspace.mdx:92,212,432—WranglerConfigrequires TOML input (JSON is auto-generated). Also use$todayforcompatibility_date. - HIGH
src/content/docs/agents/tools/workspace.mdx:367— Baretscode block for a type interface; useTypeScriptExample. - MEDIUM
src/content/docs/agents/tools/workspace.mdx:15,76,129— Run-on sentences and typo. - MEDIUM
src/content/docs/agents/tools/workspace.mdx:17,351— "Coming soon" phrases trigger Semgrep warnings in CI. - LOW
src/content/docs/agents/tools/workspace.mdx:300— Grammar.
Note: The PR description lists many unrelated changes. Update it to describe only the workspace docs addition.
| description: Give your agents a computer. Workspaces are shared between a Durable Object and a container, with built-in shell, mounts, and common filesystem tools. | ||
| --- | ||
|
|
||
| import { Aside, LinkCard, Tabs, TabItem, TypeScriptExample, WranglerConfig } from "~/components"; |
There was a problem hiding this comment.
Add PackageManagers to imports for install commands:
| import { Aside, LinkCard, Tabs, TabItem, TypeScriptExample, WranglerConfig } from "~/components"; | |
| import { Aside, LinkCard, PackageManagers, Tabs, TabItem, TypeScriptExample, WranglerConfig } from "~/components"; |
|
|
||
| Most work performed by an agent that requires a filesystem doesn't require a heavy Linux environment. Workspaces live inside a [Durable Object](/durable-objects/) right next to your agent harness. | ||
|
|
||
| Take advantage of the speed of working on files within the Worker environment and should a Linux environment be needed, you can drop into a [Cloudflare Container](/containers/) to execute bash commands, changes in either environment are reflected everywhere. |
There was a problem hiding this comment.
Split run-on sentence:
| Take advantage of the speed of working on files within the Worker environment and should a Linux environment be needed, you can drop into a [Cloudflare Container](/containers/) to execute bash commands, changes in either environment are reflected everywhere. | |
| Take advantage of the speed of working on files within the Worker environment. Should a Linux environment be needed, you can drop into a [Cloudflare Container](/containers/) to execute bash commands. Changes in either environment are reflected everywhere. |
|
|
||
| Take advantage of the speed of working on files within the Worker environment and should a Linux environment be needed, you can drop into a [Cloudflare Container](/containers/) to execute bash commands, changes in either environment are reflected everywhere. | ||
|
|
||
| File operations, R2 mounts and git clones within the Durable Object are all covered today, lightweight bash execution and code execution are coming soon! |
There was a problem hiding this comment.
Fix comma splice and avoid "coming soon" (flagged by Semgrep):
| File operations, R2 mounts and git clones within the Durable Object are all covered today, lightweight bash execution and code execution are coming soon! | |
| File operations, R2 mounts, and git clones within the Durable Object are all covered today. Lightweight bash execution and code execution are not yet available. |
|
|
||
| const report = await this.#workspace.fs.readFile("/workspace/data/report.csv", "utf8"); | ||
| } |
There was a problem hiding this comment.
Remove await from constructor — constructors cannot be async:
| const report = await this.#workspace.fs.readFile("/workspace/data/report.csv", "utf8"); | |
| } | |
| } |
| ``` | ||
|
|
||
| 1. A Durable Object constructs a `Workspace` backed by the Durable Object SQLite storage and configures a backend (currently a Cloudflare Container). | ||
| 2. The backend starts the container, whose entrypoint is the a small `wsd` client. `wsd` mounts the workspace at a path inside the container using FUSE. |
There was a problem hiding this comment.
Fix typo:
| 2. The backend starts the container, whose entrypoint is the a small `wsd` client. `wsd` mounts the workspace at a path inside the container using FUSE. | |
| 2. The backend starts the container, whose entrypoint is a small `wsd` client. `wsd` mounts the workspace at a path inside the container using FUSE. |
|
|
||
| <Aside type="note" title="Prefer ReadableStream where possible"> | ||
| Durable Objects are limited to 128MiB memory so it is preferable to avoid buffering data, particularly files into memory. All operations will default to `ReadableStream` and provide non-streaming alternatives when needed. |
There was a problem hiding this comment.
Tighten grammar:
| <Aside type="note" title="Prefer ReadableStream where possible"> | |
| Durable Objects are limited to 128MiB memory so it is preferable to avoid buffering data, particularly files into memory. All operations will default to `ReadableStream` and provide non-streaming alternatives when needed. | |
| <Aside type="note" title="Prefer ReadableStream where possible"> | |
| Durable Objects are limited to 128 MiB of memory, so it is preferable to avoid buffering data — particularly files — into memory. All operations default to `ReadableStream` and provide non-streaming alternatives when needed. | |
| </Aside> |
|
|
||
| ## Shell API | ||
|
|
||
| `ws.shell.exec(command, options?)` spawns a command inside the container and returns an `ExecHandle` stub. Today's API is run-and-wait — call `handle.result()` to await the exit code and collected output. Streaming exec is coming soon. |
There was a problem hiding this comment.
Avoid "coming soon" (flagged by Semgrep):
| `ws.shell.exec(command, options?)` spawns a command inside the container and returns an `ExecHandle` stub. Today's API is run-and-wait — call `handle.result()` to await the exit code and collected output. Streaming exec is coming soon. | |
| `ws.shell.exec(command, options?)` spawns a command inside the container and returns an `ExecHandle` stub. Today's API is run-and-wait — call `handle.result()` to await the exit code and collected output. Streaming exec is not yet available. |
| ### `ExecResult` | ||
|
|
||
| ```ts | ||
| interface WorkspaceExecResult<E extends "utf8" | undefined> { | ||
| exitCode: number; | ||
| stdout: E extends "utf8" ? string : Uint8Array; | ||
| stderr: E extends "utf8" ? string : Uint8Array; | ||
| } | ||
| ``` |
There was a problem hiding this comment.
Wrap interface in TypeScriptExample:
| ### `ExecResult` | |
| ```ts | |
| interface WorkspaceExecResult<E extends "utf8" | undefined> { | |
| exitCode: number; | |
| stdout: E extends "utf8" ? string : Uint8Array; | |
| stderr: E extends "utf8" ? string : Uint8Array; | |
| } | |
| ``` | |
| <TypeScriptExample> | |
| ```ts | |
| interface WorkspaceExecResult<E extends "utf8" | undefined> { | |
| exitCode: number; | |
| stdout: E extends "utf8" ? string : Uint8Array; | |
| stderr: E extends "utf8" ? string : Uint8Array; | |
| } | |
| </TypeScriptExample> |
| <WranglerConfig> | ||
|
|
||
| ```jsonc | ||
| { | ||
| "r2_buckets": [ | ||
| { "binding": "Bucket", "bucket_name": "my-agent-data" }, | ||
| { "binding": "Skills", "bucket_name": "my-agent-skills" }, | ||
| ], | ||
| } | ||
| ``` | ||
|
|
||
| </WranglerConfig> |
There was a problem hiding this comment.
Use TOML input for WranglerConfig:
| <WranglerConfig> | |
| ```jsonc | |
| { | |
| "r2_buckets": [ | |
| { "binding": "Bucket", "bucket_name": "my-agent-data" }, | |
| { "binding": "Skills", "bucket_name": "my-agent-skills" }, | |
| ], | |
| } | |
| ``` | |
| </WranglerConfig> | |
| <WranglerConfig> | |
| ```toml | |
| [[r2_buckets]] | |
| binding = "Bucket" | |
| bucket_name = "my-agent-data" | |
| [[r2_buckets]] | |
| binding = "Skills" | |
| bucket_name = "my-agent-skills" |
|
|
||
| ```sh | ||
| npm install isomorphic-git diff |
There was a problem hiding this comment.
Use PackageManagers for install commands:
| ```sh | |
| npm install isomorphic-git diff | |
| <PackageManagers pkg="isomorphic-git diff" /> |
|
Applied labels Posted a review with 14 inline comments on PR #31254:
Also flagged that the PR description lists many unrelated changes instead of describing the workspace docs addition. |
|
Preview URL: https://9d679040.preview.developers.cloudflare.com Files with changes (up to 15)
|
No description provided.