不将密钥发到浏览器
客户代码中的任何信息都会发布。 SDK 从您自己的服务器上发送结果, 并发送结果; 下面的页面描述一个设备, 其代理器到达的文件, 而不是页面中住着的密钥 。
会议 届会
被绑绑在 localStorage其来源是每个来源。它生存于重新装载,并且对所有其他来源——包括其他在开发中的其他港口的表面——都看不见。
没有磁盘
storage.files 在此丢弃。 浏览器设备将文件保存在自己的浏览器中, 代理器通过您提供的六个操作到达它们 。
const agent = api.agents.create({
runtime: "local",
machine: device,
model: "gemini-3.5-flash",
files: {
list: async (dir) => [{ name, path, type, size, mimeType, modifiedAt }],
read: async (path) => ({ content }),
write: async (path, content) => ({ path }),
mkdir: async (dir) => ({ path: dir }),
move: async (from, to) => ({ path: to }),
remove: async (path) => ({ ok: true }),
},
});class DeviceFiles:
"""Any object with these six methods can be the agent's workspace."""
def list(self, dir="", *, recursive=False): return [{"name": ..., "path": ..., "type": ..., "size": ...}]
def read(self, path): return {"content": ...}
def write(self, path, content): return {"path": path}
def mkdir(self, dir): return {"path": dir}
def move(self, source, destination): return {"path": destination}
def remove(self, path): return {"ok": True}
agent = api.agents.create(
runtime="local",
machine=device,
model="gemini-3.5-flash",
files=DeviceFiles(),
)小姐一,它拒绝建筑
错误是 files_required 并且它列出了失踪的操作。 代理从未被创建过半装备。
这些文件实际住在哪里
这是您的选择, 并且它是桥的全点。 设备自己的文件索引化 DB; 用户必须在设备之间跟随文件的对象存储; 测试的模拟地图 。
// A bridge over any async key-value store
const files = (store) => ({
list: async (dir = "") => store.listPrefix(dir),
read: async (path) => ({ content: await store.get(path) }),
write: async (path, content) => { await store.set(path, content); return { path }; },
mkdir: async (dir) => ({ path: dir }),
move: async (from, to) => { await store.set(to, await store.get(from)); await store.del(from); return { path: to }; },
remove: async (path) => { await store.del(path); return { ok: true }; },
});# A bridge over any key-value store
class StoreFiles:
def __init__(self, store): self.store = store
def list(self, dir="", *, recursive=False): return self.store.list_prefix(dir)
def read(self, path): return {"content": self.store.get(path)}
def write(self, path, content):
self.store.set(path, content)
return {"path": path}
def mkdir(self, dir): return {"path": dir}
def move(self, source, destination):
self.store.set(destination, self.store.get(source))
self.store.delete(source)
return {"path": destination}
def remove(self, path):
self.store.delete(path)
return {"ok": True}正在注册设备
浏览器从不注册—— SDK 不存在此选项, 关键不能存在。 您的服务器注册了它, 并保存了 ID 。
// in the page
let deviceId = localStorage.getItem("device");
if (!deviceId) {
deviceId = crypto.randomUUID();
localStorage.setItem("device", deviceId);
}
// on your server, with the key
const device = await api.storage.device({
deviceId,
name: "Zayd's phone",
userAgent,
});
// a storage of type "phone", provider "browser"# In the page, the browser keeps its own device id (JavaScript):
# localStorage.getItem("device") || crypto.randomUUID()
# On your Python server, with the key
device = api.storage.device(
device_id=device_id,
name="Zayd's phone",
user_agent=user_agent,
)
# a storage of type "phone", provider "browser"命令
bash 被从此工具集中删除, 因为没有任何东西运行它。 提供一个 shell , 然后它又返回, 从代理商的角度来说是相同的 。
api.agents.create({
runtime: "local",
machine: device,
model: "gemini-3.5-flash",
files,
shell: {
run: async (command, { timeoutMs, signal }) => {
const { stdout, stderr, exitCode } = await runSomewhere(command, { timeoutMs, signal });
return { stdout, stderr, exitCode };
},
},
});# Python's bash tool runs on a LocalFiles workspace, on the machine that runs the SDK.
# A device without a shell gets the file tools only: leave "bash" out of its tools.
api.agents.create(
runtime="local",
machine=device,
model="gemini-3.5-flash",
files=StoreFiles(store),
tools=["read", "list", "glob", "write", "edit", "move", "delete"],
)返回三块田,其他任何东西都拒绝 invalid_shell 在代理商建立之前
哪里不在这里
storage.files- 使用files桥。terminals——一个比答案活得久的壳需要有一个活下来的过程。bash,除非您提供shell.- 电脑库仍然有效, 属于这个帐户。