Skip to content

Commit 3c1b171

Browse files
committed
docs: README — direct tool methods + S3 workspace backend examples
- Main README: add write_file/ls/edit_file/patch_file to the Direct Tools section of the Python and Node API-glance examples; include workspace_backend / workspaceBackend in the SessionOptions example; import LocalWorkspaceBackend and S3WorkspaceBackend in both stubs. - Node SDK README: add a dedicated S3-compatible storage section alongside the existing LocalWorkspaceBackend example. - Python SDK README: import S3WorkspaceBackend; add an S3-backed session example showing write_file/read_file/ls against an S3-compatible endpoint. No code changes — documents the v2.6.0 surface area for SDK users.
1 parent 48371f1 commit 3c1b171

3 files changed

Lines changed: 68 additions & 3 deletions

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ from a3s_code import (
9898
FileMemoryStore,
9999
FileSessionStore,
100100
HttpTransport,
101+
LocalWorkspaceBackend,
102+
S3WorkspaceBackend,
101103
)
102104

103105
# 1. Configure a session — typed extension options, not raw flags.
@@ -118,6 +120,7 @@ opts.session_store = FileSessionStore("./sessions")
118120
opts.session_id = "my-session"
119121
opts.auto_save = True
120122
opts.ahp_transport = HttpTransport("http://localhost:8080/ahp")
123+
opts.workspace_backend = LocalWorkspaceBackend("/my-project") # or S3WorkspaceBackend(bucket=..., prefix=..., ...)
121124

122125
agent = Agent.create("agent.acl")
123126
session = agent.session("/my-project", opts)
@@ -132,6 +135,10 @@ for event in session.stream({"prompt": "Continue the refactor"}):
132135

133136
# 3. Direct tools (bypass the LLM).
134137
session.read_file("src/main.py")
138+
session.write_file("src/new_module.py", "def hello():\n return 'world'\n")
139+
session.edit_file("src/main.py", old_string="old_value", new_string="new_value")
140+
session.patch_file("src/main.py", diff="@@ -1,2 +1,2 @@\n-old\n+new")
141+
session.ls("src")
135142
session.bash("pytest -q")
136143
session.glob("**/*.py")
137144
session.grep("PermissionPolicy")
@@ -242,6 +249,8 @@ import {
242249
FileMemoryStore,
243250
FileSessionStore,
244251
HttpTransport,
252+
LocalWorkspaceBackend,
253+
S3WorkspaceBackend,
245254
} from '@a3s-lab/code';
246255

247256
// 1. Configure a session — typed extension options, not raw flags.
@@ -264,6 +273,7 @@ const opts: SessionOptions = {
264273
sessionId: 'my-session',
265274
autoSave: true,
266275
ahpTransport: new HttpTransport('http://localhost:8080/ahp'),
276+
workspaceBackend: new LocalWorkspaceBackend('/my-project'), // or new S3WorkspaceBackend({ bucket, prefix, ... })
267277
};
268278

269279
const agent = await Agent.create('agent.acl');
@@ -280,6 +290,10 @@ for await (const event of stream) {
280290

281291
// 3. Direct tools (bypass the LLM).
282292
await session.readFile('src/main.ts');
293+
await session.writeFile('src/newModule.ts', "export const hello = () => 'world';\n");
294+
await session.editFile('src/main.ts', 'old_value', 'new_value');
295+
await session.patchFile('src/main.ts', '@@ -1,2 +1,2 @@\n-old\n+new');
296+
await session.ls('src');
283297
await session.bash('npm test');
284298
await session.glob('**/*.ts');
285299
await session.grep('PermissionPolicy');

sdk/node/README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ Scripts can also be loaded from workspace-relative `.js` or `.mjs` files with
5555
## Workspace Backends And Direct Files
5656

5757
The default workspace backend is the local filesystem rooted at the session
58-
workspace. SDK callers can pass the explicit typed backend now, using the same
59-
option surface that remote, browser, DFS, and container-backed workspaces will
60-
use:
58+
workspace. SDK callers can pass an explicit typed backend through the same
59+
option surface used by remote, browser, DFS, and container-backed workspaces:
6160

6261
```js
6362
const { Agent, LocalWorkspaceBackend } = require('@a3s-lab/code')
@@ -74,6 +73,39 @@ await session.editFile('notes.txt', 'one', 'uno')
7473
await session.patchFile('notes.txt', '@@ -1,2 +1,2 @@\n uno\n-two\n+dos')
7574
```
7675

76+
### S3-compatible object storage
77+
78+
`S3WorkspaceBackend` lets built-in file tools (`read`, `write`, `edit`,
79+
`patch`, `ls`) target any S3-compatible endpoint — AWS S3, MinIO, RustFS,
80+
Cloudflare R2, Backblaze B2, etc. `bash`, `git`, `grep`, and `glob` are
81+
automatically hidden from the model because object storage cannot service
82+
them.
83+
84+
```js
85+
const { Agent, S3WorkspaceBackend } = require('@a3s-lab/code')
86+
87+
const agent = await Agent.create('agent.acl')
88+
const session = agent.session('s3://workspace/users/u1/sessions/s1', {
89+
workspaceBackend: new S3WorkspaceBackend({
90+
endpoint: 'https://minio.local:9000', // omit for AWS S3
91+
region: 'us-east-1',
92+
accessKeyId: 'AKIA...',
93+
secretAccessKey: '...',
94+
bucket: 'workspace',
95+
prefix: 'users/u1/sessions/s1',
96+
forcePathStyle: true, // true for MinIO/RustFS/R2
97+
}),
98+
})
99+
100+
await session.writeFile('notes/hello.txt', 'one\ntwo\n')
101+
await session.readFile('notes/hello.txt')
102+
await session.ls('notes')
103+
```
104+
105+
S3 has no atomic read-modify-write, so concurrent writers to the same key
106+
overwrite each other (last-writer-wins). Partition workspaces per session or
107+
user via the `prefix` field when running multi-tenant.
108+
77109
## Planning Events
78110

79111
Planning is automatic by default. Prefer the explicit tri-state

sdk/python/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ from a3s_code import (
6161
FileSessionStore,
6262
HttpTransport,
6363
LocalWorkspaceBackend,
64+
S3WorkspaceBackend,
6465
)
6566

6667
agent = Agent.create("agent.acl")
@@ -111,6 +112,24 @@ session.grep("TODO")
111112
session.tool_names()
112113
session.tool_definitions()
113114

115+
# S3-compatible workspace — point the same direct tools at object storage.
116+
# `bash`, `git`, `grep`, `glob` are automatically hidden because object
117+
# storage cannot service them. Works with AWS S3, MinIO, RustFS, R2, B2.
118+
s3_opts = SessionOptions()
119+
s3_opts.workspace_backend = S3WorkspaceBackend(
120+
bucket="workspace",
121+
prefix="users/u1/sessions/s1",
122+
access_key_id="AKIA...",
123+
secret_access_key="...",
124+
endpoint="https://minio.local:9000", # omit for AWS S3
125+
region="us-east-1",
126+
force_path_style=True, # True for MinIO/RustFS/R2
127+
)
128+
s3_session = agent.session("s3://workspace/users/u1/sessions/s1", s3_opts)
129+
s3_session.write_file("notes/hello.txt", "one\ntwo\n")
130+
s3_session.read_file("notes/hello.txt")
131+
s3_session.ls("notes")
132+
114133
# Programmatic Tool Calling (embedded QuickJS)
115134
program = session.program({
116135
"source": """

0 commit comments

Comments
 (0)