Workspace Runtime 執行
session.sendText(...) 請 Agent 推理並行動。workspace.run(...) 讓 App 執行它已知道要執行的程式碼。對確定性的操作,App 不必只為執行而花費一個 Agent 回合。
const result = await workspace.run(` const text = await Deno.readTextFile("data.json"); const data = JSON.parse(text); console.log(JSON.stringify({ count: data.items.length }));`);
if (result.stdoutTruncated || result.stderrTruncated) { throw new Error("Workspace script output was truncated");}
const value = JSON.parse(result.stdout);結果包含 stdout、stderr、exit code 和截斷旗標。精確的回傳型別、非零 exit、失敗與 timeout 行為請見 PedelecWorkspace reference。
直接執行適合在使用者按下 Export 後產生檔案、開啟專案時讀取並正規化 metadata、將資料送給 Agent 前先處理、儲存前驗證、已知的本機遷移,或建立衍生 manifest。
在單次執行重用 Runtime Module
Section titled “在單次執行重用 Runtime Module”import { defineRuntimeModule } from "@kaoruisaac/pedelec";
const projectTools = defineRuntimeModule({ name: "project-tools", entry: "./deno/project-tools.ts",});
const result = await workspace.run( ` import { buildManifest } from "project-tools"; await buildManifest(); `, { runtimeModules: [projectTools] },);僅供 Workspace 使用的宣告不需要 Agent-facing description 或 usage。每次執行都要明確提供 modules,且只會掛載該次要求的 modules。runtime cache 有效時,Pedelec 可私下重用已準備的 package。這不是公開的 Workspace module registry。
Session / Thread → skills.runtimeModules → 僅供 Agent-side pedelec-ts-runtimeWorkspace run → workspace.run({ runtimeModules }) → 僅供 App 執行workspace.run() 不會繼承 Session Runtime Modules。建立 Session 也不會繼承之前 Workspace run 用過的 modules;Workspace-run modules 不會出現在 Agent Host Context。
同一個 Workspace 裡,Workspace Runtime 執行可以與 Agent/provider 工作以及其他 workspace.run() 同時進行。Pedelec 不會替這些 actors 協調 filesystem conflicts。詳見 PedelecWorkspace。