@sixb/agent 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -2
  3. package/dist/abort.d.ts +6 -0
  4. package/dist/abort.d.ts.map +1 -0
  5. package/dist/agent-prompt.d.ts +120 -0
  6. package/dist/agent-prompt.d.ts.map +1 -0
  7. package/dist/agent-runtime/errors.d.ts +13 -0
  8. package/dist/agent-runtime/errors.d.ts.map +1 -0
  9. package/dist/agent-runtime/preflight.d.ts +18 -0
  10. package/dist/agent-runtime/preflight.d.ts.map +1 -0
  11. package/dist/agent-runtime/profile.d.ts +14 -0
  12. package/dist/agent-runtime/profile.d.ts.map +1 -0
  13. package/dist/artifacts/layout-check/layout-check.d.ts +87 -0
  14. package/dist/artifacts/layout-check/layout-check.d.ts.map +1 -0
  15. package/dist/artifacts/materialize.d.ts +115 -0
  16. package/dist/artifacts/materialize.d.ts.map +1 -0
  17. package/dist/artifacts/publish-tool.d.ts +86 -0
  18. package/dist/artifacts/publish-tool.d.ts.map +1 -0
  19. package/dist/ask-parent-tool.d.ts +36 -0
  20. package/dist/ask-parent-tool.d.ts.map +1 -0
  21. package/dist/attachments.d.ts +68 -0
  22. package/dist/attachments.d.ts.map +1 -0
  23. package/dist/child-files.d.ts +96 -0
  24. package/dist/child-files.d.ts.map +1 -0
  25. package/dist/child-questions.d.ts +24 -0
  26. package/dist/child-questions.d.ts.map +1 -0
  27. package/dist/computer-runner.d.ts +65 -0
  28. package/dist/computer-runner.d.ts.map +1 -0
  29. package/dist/context-budget.d.ts +28 -0
  30. package/dist/context-budget.d.ts.map +1 -0
  31. package/dist/context-compaction.d.ts +48 -0
  32. package/dist/context-compaction.d.ts.map +1 -0
  33. package/dist/conversation-memory.d.ts +21 -0
  34. package/dist/conversation-memory.d.ts.map +1 -0
  35. package/dist/errors.d.ts +46 -0
  36. package/dist/errors.d.ts.map +1 -0
  37. package/dist/execution-plan.d.ts +34 -0
  38. package/dist/execution-plan.d.ts.map +1 -0
  39. package/dist/failure.d.ts +14 -0
  40. package/dist/failure.d.ts.map +1 -0
  41. package/dist/family-mailbox.d.ts +60 -0
  42. package/dist/family-mailbox.d.ts.map +1 -0
  43. package/dist/file-ref.d.ts +6 -0
  44. package/dist/file-ref.d.ts.map +1 -0
  45. package/dist/image-attachments.d.ts +34 -0
  46. package/dist/image-attachments.d.ts.map +1 -0
  47. package/dist/index.d.ts +35 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +12168 -0
  50. package/dist/index.js.map +65 -0
  51. package/dist/message-authors.d.ts +34 -0
  52. package/dist/message-authors.d.ts.map +1 -0
  53. package/dist/message-times.d.ts +8 -0
  54. package/dist/message-times.d.ts.map +1 -0
  55. package/dist/model-adapters.d.ts +55 -0
  56. package/dist/model-adapters.d.ts.map +1 -0
  57. package/dist/model-lines.d.ts +16 -0
  58. package/dist/model-lines.d.ts.map +1 -0
  59. package/dist/requester.d.ts +15 -0
  60. package/dist/requester.d.ts.map +1 -0
  61. package/dist/run-agent-turn.d.ts +63 -0
  62. package/dist/run-agent-turn.d.ts.map +1 -0
  63. package/dist/run-child.d.ts +77 -0
  64. package/dist/run-child.d.ts.map +1 -0
  65. package/dist/run-conversation-turn.d.ts +42 -0
  66. package/dist/run-conversation-turn.d.ts.map +1 -0
  67. package/dist/run-credential.d.ts +22 -0
  68. package/dist/run-credential.d.ts.map +1 -0
  69. package/dist/run-environment.d.ts +115 -0
  70. package/dist/run-environment.d.ts.map +1 -0
  71. package/dist/run-fate.d.ts +15 -0
  72. package/dist/run-fate.d.ts.map +1 -0
  73. package/dist/run-sandbox.d.ts +60 -0
  74. package/dist/run-sandbox.d.ts.map +1 -0
  75. package/dist/run-subagent.d.ts +51 -0
  76. package/dist/run-subagent.d.ts.map +1 -0
  77. package/dist/run-workflow-agent-node.d.ts +41 -0
  78. package/dist/run-workflow-agent-node.d.ts.map +1 -0
  79. package/dist/sandbox-api-context.d.ts +34 -0
  80. package/dist/sandbox-api-context.d.ts.map +1 -0
  81. package/dist/sandbox-file-registry.d.ts +9 -0
  82. package/dist/sandbox-file-registry.d.ts.map +1 -0
  83. package/dist/sandbox-files.d.ts +71 -0
  84. package/dist/sandbox-files.d.ts.map +1 -0
  85. package/dist/sandbox-handle.d.ts +15 -0
  86. package/dist/sandbox-handle.d.ts.map +1 -0
  87. package/dist/sandbox-readiness.d.ts +8 -0
  88. package/dist/sandbox-readiness.d.ts.map +1 -0
  89. package/dist/skills/built-in.d.ts +15 -0
  90. package/dist/skills/built-in.d.ts.map +1 -0
  91. package/dist/subagent-continuation.d.ts +27 -0
  92. package/dist/subagent-continuation.d.ts.map +1 -0
  93. package/dist/subagent-inbox.d.ts +53 -0
  94. package/dist/subagent-inbox.d.ts.map +1 -0
  95. package/dist/subagent-tools.d.ts +282 -0
  96. package/dist/subagent-tools.d.ts.map +1 -0
  97. package/dist/thread-context.d.ts +12 -0
  98. package/dist/thread-context.d.ts.map +1 -0
  99. package/dist/tools/attachments.d.ts +11 -0
  100. package/dist/tools/attachments.d.ts.map +1 -0
  101. package/dist/tools/bash.d.ts +60 -0
  102. package/dist/tools/bash.d.ts.map +1 -0
  103. package/dist/tools/model-spec.d.ts +4 -0
  104. package/dist/tools/model-spec.d.ts.map +1 -0
  105. package/dist/tools/read.d.ts +43 -0
  106. package/dist/tools/read.d.ts.map +1 -0
  107. package/dist/tools/result-media.d.ts +22 -0
  108. package/dist/tools/result-media.d.ts.map +1 -0
  109. package/dist/tools/result-output.d.ts +18 -0
  110. package/dist/tools/result-output.d.ts.map +1 -0
  111. package/dist/tools/tool-files.d.ts +59 -0
  112. package/dist/tools/tool-files.d.ts.map +1 -0
  113. package/dist/tools/view-file.d.ts +40 -0
  114. package/dist/tools/view-file.d.ts.map +1 -0
  115. package/dist/tsconfig.json +5 -0
  116. package/dist/turn-runtime.d.ts +19 -0
  117. package/dist/turn-runtime.d.ts.map +1 -0
  118. package/dist/types.d.ts +76 -0
  119. package/dist/types.d.ts.map +1 -0
  120. package/dist/workflow-input-attachments.d.ts +18 -0
  121. package/dist/workflow-input-attachments.d.ts.map +1 -0
  122. package/package.json +59 -4
  123. package/src/abort.ts +40 -0
  124. package/src/agent-prompt.ts +758 -0
  125. package/src/agent-runtime/errors.ts +44 -0
  126. package/src/agent-runtime/preflight.ts +314 -0
  127. package/src/agent-runtime/profile.ts +23 -0
  128. package/src/artifacts/layout-check/check.cjs +478 -0
  129. package/src/artifacts/layout-check/layout-check.ts +460 -0
  130. package/src/artifacts/materialize.ts +380 -0
  131. package/src/artifacts/publish-tool.ts +700 -0
  132. package/src/ask-parent-tool.ts +100 -0
  133. package/src/attachments.ts +850 -0
  134. package/src/child-files.ts +540 -0
  135. package/src/child-questions.ts +42 -0
  136. package/src/computer-runner.ts +284 -0
  137. package/src/context-budget.ts +161 -0
  138. package/src/context-compaction.ts +529 -0
  139. package/src/conversation-memory.ts +45 -0
  140. package/src/errors.ts +85 -0
  141. package/src/execution-plan.ts +50 -0
  142. package/src/failure.ts +71 -0
  143. package/src/family-mailbox.ts +189 -0
  144. package/src/file-ref.ts +18 -0
  145. package/src/image-attachments.ts +322 -0
  146. package/src/index.ts +54 -0
  147. package/src/message-authors.ts +77 -0
  148. package/src/message-times.ts +21 -0
  149. package/src/model-adapters.ts +227 -0
  150. package/src/model-lines.ts +28 -0
  151. package/src/requester.ts +21 -0
  152. package/src/run-agent-turn.ts +347 -0
  153. package/src/run-child.ts +319 -0
  154. package/src/run-conversation-turn.ts +257 -0
  155. package/src/run-credential.ts +55 -0
  156. package/src/run-environment.ts +769 -0
  157. package/src/run-fate.ts +51 -0
  158. package/src/run-sandbox.ts +63 -0
  159. package/src/run-subagent.ts +347 -0
  160. package/src/run-workflow-agent-node.ts +270 -0
  161. package/src/sandbox-api-context.ts +234 -0
  162. package/src/sandbox-file-registry.ts +26 -0
  163. package/src/sandbox-files.ts +326 -0
  164. package/src/sandbox-handle.ts +19 -0
  165. package/src/sandbox-readiness.ts +22 -0
  166. package/src/skills/built-in.ts +183 -0
  167. package/src/skills/sixb-artifacts/SKILL.md +95 -0
  168. package/src/skills/sixb-artifacts/canvas.md +104 -0
  169. package/src/skills/sixb-artifacts/document.md +63 -0
  170. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/first-job.html +42 -0
  171. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/region.html +29 -0
  172. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/shared.css +35 -0
  173. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/welcome.html +31 -0
  174. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/canvas.json +107 -0
  175. package/src/skills/sixb-artifacts/examples/canvas/retro/canvas.json +158 -0
  176. package/src/skills/sixb-artifacts/examples/document/incident-report/document.md +35 -0
  177. package/src/skills/sixb-artifacts/examples/document/operations-review/document.md +41 -0
  178. package/src/skills/sixb-artifacts/examples/document/operations-review/figures/restorations.svg +1 -0
  179. package/src/skills/sixb-artifacts/examples/page/collections-desk/index.html +169 -0
  180. package/src/skills/sixb-artifacts/examples/page/collections-desk/queries/overdue.json +13 -0
  181. package/src/skills/sixb-artifacts/examples/page/dispatch-board/data/dispatch.json +234 -0
  182. package/src/skills/sixb-artifacts/examples/page/dispatch-board/index.html +245 -0
  183. package/src/skills/sixb-artifacts/examples/page/fleet-planner/data/plan.json +53 -0
  184. package/src/skills/sixb-artifacts/examples/page/fleet-planner/index.html +462 -0
  185. package/src/skills/sixb-artifacts/examples/page/service-explorer/data/service.json +276 -0
  186. package/src/skills/sixb-artifacts/examples/page/service-explorer/index.html +549 -0
  187. package/src/skills/sixb-artifacts/examples/sheet/overdue-invoices/queries/overdue.json +13 -0
  188. package/src/skills/sixb-artifacts/examples/sheet/overdue-invoices/workbook.json +30 -0
  189. package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/sheets/Inventory.csv +13 -0
  190. package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/sheets/Spend.csv +6 -0
  191. package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/workbook.json +47 -0
  192. package/src/skills/sixb-artifacts/examples/sheet/service-metrics/sheets/Quarters.csv +5 -0
  193. package/src/skills/sixb-artifacts/examples/sheet/service-metrics/sheets/Regions.csv +5 -0
  194. package/src/skills/sixb-artifacts/examples/sheet/service-metrics/workbook.json +78 -0
  195. package/src/skills/sixb-artifacts/examples/slides/launch-plan/index.html +63 -0
  196. package/src/skills/sixb-artifacts/examples/slides/q3-review/index.html +133 -0
  197. package/src/skills/sixb-artifacts/file.md +17 -0
  198. package/src/skills/sixb-artifacts/page.md +215 -0
  199. package/src/skills/sixb-artifacts/queries.md +66 -0
  200. package/src/skills/sixb-artifacts/references.md +68 -0
  201. package/src/skills/sixb-artifacts/sheet.md +223 -0
  202. package/src/skills/sixb-artifacts/slides.md +137 -0
  203. package/src/skills/sixb-memory/SKILL.md +68 -0
  204. package/src/skills/text-assets.d.ts +25 -0
  205. package/src/subagent-continuation.ts +51 -0
  206. package/src/subagent-inbox.ts +101 -0
  207. package/src/subagent-tools.ts +1609 -0
  208. package/src/thread-context.ts +25 -0
  209. package/src/tools/attachments.ts +28 -0
  210. package/src/tools/bash.ts +217 -0
  211. package/src/tools/model-spec.ts +22 -0
  212. package/src/tools/read.ts +262 -0
  213. package/src/tools/result-media.ts +147 -0
  214. package/src/tools/result-output.ts +44 -0
  215. package/src/tools/tool-files.ts +204 -0
  216. package/src/tools/view-file.ts +155 -0
  217. package/src/turn-runtime.ts +33 -0
  218. package/src/types.ts +79 -0
  219. package/src/workflow-input-attachments.ts +140 -0
@@ -0,0 +1,769 @@
1
+ import { posix } from "node:path"
2
+ import type { Principal } from "@sixb/core"
3
+ import {
4
+ type AgentRunArtifacts,
5
+ type AgentRunSession,
6
+ type AgentTurnHistory,
7
+ conversationThreadId,
8
+ subagentSandboxFiles,
9
+ } from "@sixb/core/internal/agents"
10
+ import type { RenderedOntologyDocs } from "@sixb/core/internal/ontology"
11
+ import type { WorkflowIOSnapshot } from "@sixb/core/internal/workflows"
12
+ import type { ModelTool } from "@sixb/core/models"
13
+ import type {
14
+ AgentThreadRecord,
15
+ ConversationAgentRunRecord,
16
+ SubagentRunRecord,
17
+ WorkflowAgentNodeRunRecord,
18
+ } from "@sixb/core/storage"
19
+ import { NEVER_ABORTED_SIGNAL, waitForAbort } from "./abort"
20
+ import { type AgentExecutionMode, agentRuntimeFacts, renderAgentSystemPrompt } from "./agent-prompt"
21
+ import { assertAgentRuntimeProfile } from "./agent-runtime/preflight"
22
+ import {
23
+ type InstalledArtifacts,
24
+ installArtifactsPublishedBy,
25
+ type MaterializedArtifacts,
26
+ materializeThreadArtifacts,
27
+ } from "./artifacts/materialize"
28
+ import { createPublishArtifactTools } from "./artifacts/publish-tool"
29
+ import {
30
+ modelSupportsInlineImages,
31
+ type PreparedAgentAttachmentContext,
32
+ prepareAgentAttachments,
33
+ } from "./attachments"
34
+ import { prepareHandedFiles } from "./child-files"
35
+ import type { AgentContextBudget } from "./context-budget"
36
+ import { type LoadConversationMemory, prepareAgentConversationContext } from "./context-compaction"
37
+ import { type ConversationMemory, loadConversationMemory } from "./conversation-memory"
38
+ import { isLostExecution } from "./errors"
39
+ import type { ResolvedAgentExecutionPlan } from "./execution-plan"
40
+ import type { ConversationReaders } from "./message-authors"
41
+ import { type AgentErrorDetails, type AgentToolCaller, projectModelTools } from "./model-adapters"
42
+ import type { AcquiredRunSandbox, BeforeFinalizeOptions, RunSandbox } from "./run-sandbox"
43
+ import {
44
+ AGENT_ARTIFACTS_DIRECTORY,
45
+ AGENT_ARTIFACTS_MANIFEST,
46
+ type PrepareAgentSandboxApiContextInput,
47
+ prepareAgentSandboxApiContext,
48
+ } from "./sandbox-api-context"
49
+ import { AgentSandboxFileRegistry } from "./sandbox-file-registry"
50
+ import type { AgentSandboxHandle } from "./sandbox-handle"
51
+ import { MEMORY_SKILL } from "./skills/built-in"
52
+ import type { SubagentHistory } from "./subagent-continuation"
53
+ import { agentThreadModelContext, type LoadedAgentThreadModelContext } from "./thread-context"
54
+ import { createBashTool } from "./tools/bash"
55
+ import { createReadTool } from "./tools/read"
56
+ import { AgentToolResultMediaBridge } from "./tools/result-media"
57
+ import { AgentFileBudget, createAgentToolFiles, installAgentToolFiles } from "./tools/tool-files"
58
+ import { createViewFileTool } from "./tools/view-file"
59
+ import type { AgentTurnRuntime } from "./turn-runtime"
60
+ import type { AgentExecutionContext, AgentRunFiles, AgentTurnContext } from "./types"
61
+ import { prepareWorkflowInputAttachments } from "./workflow-input-attachments"
62
+
63
+ export interface AgentExecutionEnvironment {
64
+ readonly turnContext: AgentTurnContext
65
+ /** The run's sandbox and file budget, for the files a parent and its children hand each other. */
66
+ readonly runFiles: AgentRunFiles
67
+ /** Confirm preservation before recording success, cancellation or failure. Idempotent. */
68
+ beforeFinalize(options?: BeforeFinalizeOptions): Promise<void>
69
+ dispose(): Promise<void>
70
+ }
71
+
72
+ export interface ConversationAgentExecutionEnvironment extends AgentExecutionEnvironment {
73
+ /** The history the turn runs on: as it started, or as its compaction left it. */
74
+ readonly threadContext: LoadedAgentThreadModelContext
75
+ }
76
+
77
+ /**
78
+ * How a runner gives a run its environment: a cloud sandbox, or a folder on a computer. The runner
79
+ * closes over whatever it opens it from (a factory, the thread's recipe, the run's credentials).
80
+ */
81
+ export type OpenRunSandbox = (lifecycle: {
82
+ /** Stops provisioning: cancellation, lost ownership, or shutdown. */
83
+ readonly signal: AbortSignal
84
+ /** Ends the run when its environment can no longer serve it, such as lost source credentials. */
85
+ readonly onFailure: (error: Error) => void
86
+ }) => Promise<OpenedRunSandbox>
87
+
88
+ export interface OpenedRunSandbox {
89
+ readonly sandbox: RunSandbox
90
+ /** The workspace the run's paused attempt left: it holds that attempt's files already. */
91
+ readonly resumed?: boolean
92
+ }
93
+
94
+ interface CreateAgentEnvironmentInput {
95
+ readonly context: AgentExecutionContext
96
+ readonly plan: ResolvedAgentExecutionPlan
97
+ /** The run's environment, opened by its runner. */
98
+ readonly openSandbox: OpenRunSandbox
99
+ readonly signal?: AbortSignal
100
+ /**
101
+ * Sink for a sandbox teardown that outlives dispose() (the model answered before the boot
102
+ * finished, so dispose returns without stalling on it). The worker registers these so a graceful
103
+ * stop() can drain them instead of leaving orphaned machines being torn down.
104
+ */
105
+ readonly onDetachedTeardown?: (teardown: Promise<void>) => void
106
+ }
107
+
108
+ export interface CreateConversationAgentEnvironmentInput extends CreateAgentEnvironmentInput {
109
+ /** The turn's session: its workspace, conversation and checkpoint go through it. */
110
+ readonly session: AgentRunSession
111
+ readonly thread?: AgentThreadRecord | null
112
+ /** Who asked for the turn: what it publishes is theirs, in an artifact the thread's owner owns. */
113
+ readonly requestedBy?: Principal
114
+ /** Who can read the thread now: in a shared one, who wrote what counts toward the estimate. */
115
+ readonly conversation?: ConversationReaders
116
+ /** Others were added to the thread, so it reaches the project's memory alone. */
117
+ readonly shared?: boolean
118
+ /** Run preflight only after current sandbox access has been resolved. */
119
+ readonly preflight?: { readonly budget: AgentContextBudget; readonly runtime: AgentTurnRuntime }
120
+ readonly run: ConversationAgentRunRecord
121
+ /** The conversation's history as the turn started (`AgentTurnContext.history`). */
122
+ readonly history: AgentTurnHistory
123
+ /** Framework-owned tools of the conversational Agent: delegation. */
124
+ readonly frameworkTools?: readonly ModelTool[]
125
+ }
126
+
127
+ export interface CreateSubagentEnvironmentInput extends CreateAgentEnvironmentInput {
128
+ /** The child's session: its workspace goes through it. */
129
+ readonly session: AgentRunSession
130
+ readonly run: SubagentRunRecord
131
+ /** The child's own thread: memory is read as of its creation. */
132
+ readonly thread: AgentThreadRecord
133
+ /** The conversation: what the child publishes lands there. Absent, it publishes nothing. */
134
+ readonly conversation?: AgentThreadRecord | null
135
+ /** Who asked for the parent turn: what the child publishes is theirs. */
136
+ readonly requestedBy?: Principal
137
+ /** Its thread's messages, whose files are projected again, and the paused run it continues. */
138
+ readonly history: SubagentHistory
139
+ /** Framework-owned tools of a child: `ask_parent`. */
140
+ readonly frameworkTools?: readonly ModelTool[]
141
+ }
142
+
143
+ export interface CreateWorkflowAgentNodeEnvironmentInput extends CreateAgentEnvironmentInput {
144
+ readonly run: WorkflowAgentNodeRunRecord
145
+ readonly workflowId: string
146
+ readonly stepId: string
147
+ readonly nodeInput: WorkflowIOSnapshot
148
+ readonly errorDetails: AgentErrorDetails
149
+ /** How the step calls a project tool: it runs in the cloud, so in the worker's process. */
150
+ readonly callTool: AgentToolCaller
151
+ }
152
+
153
+ /** Prepare conversation history and attachments, then start the shared agent environment. */
154
+ export async function createConversationAgentEnvironment(
155
+ input: CreateConversationAgentEnvironmentInput
156
+ ): Promise<ConversationAgentExecutionEnvironment> {
157
+ const { context, plan, run, preflight } = input
158
+ const { apiBaseUrl } = context
159
+ const failure = new AbortController()
160
+ const sandboxSignal = input.signal
161
+ ? AbortSignal.any([input.signal, failure.signal])
162
+ : failure.signal
163
+ const { sandbox } = await input.openSandbox({
164
+ signal: sandboxSignal,
165
+ onFailure: (error) => failure.abort(error),
166
+ })
167
+ let environment: AgentExecutionEnvironment | undefined
168
+ // The prompt shows memory as of the thread's start or its latest compaction (see
169
+ // loadConversationMemory).
170
+ const threadCreatedAt = input.thread?.createdAt ?? run.createdAt
171
+ const loadMemory: LoadConversationMemory = (checkpoint) =>
172
+ loadConversationMemory({
173
+ session: input.session,
174
+ asOf: checkpoint?.createdAt ?? threadCreatedAt,
175
+ })
176
+ try {
177
+ const { ontologyDocs } = plan
178
+ // Resolve application access before any compaction model call. Once acquired, this
179
+ // environment owns preservation even if history, attachments or runtime preparation fail.
180
+ const prepared = preflight
181
+ ? await prepareAgentConversationContext({
182
+ context,
183
+ session: input.session,
184
+ plan,
185
+ ontologyIndex: ontologyDocs.index,
186
+ contextDirectory: sandbox.contextDirectory,
187
+ run,
188
+ history: input.history,
189
+ ...(input.conversation === undefined ? {} : { conversation: input.conversation }),
190
+ budget: preflight.budget,
191
+ runtime: {
192
+ ...preflight.runtime,
193
+ signal: sandboxSignal,
194
+ assertCanContinue() {
195
+ preflight.runtime.assertCanContinue()
196
+ failure.signal.throwIfAborted()
197
+ },
198
+ },
199
+ frameworkTools: input.frameworkTools,
200
+ loadMemory,
201
+ })
202
+ : undefined
203
+ const threadContext = prepared?.threadContext ?? agentThreadModelContext(input.history)
204
+ const messages = threadContext.retainedMessages
205
+ const [inlineImages, memory] = await Promise.all([
206
+ modelSupportsInlineImages(plan.model),
207
+ prepared ? prepared.memory : loadMemory(threadContext.checkpoint),
208
+ ])
209
+ const attachmentContext = await prepareAgentAttachments({
210
+ projectId: context.id,
211
+ threadId: run.threadId,
212
+ messages,
213
+ blobStorage: context.blobStorage,
214
+ apiBaseUrl,
215
+ contextDirectory: sandbox.contextDirectory,
216
+ inlineImages,
217
+ signal: sandboxSignal,
218
+ })
219
+ environment = await startAgentEnvironment({
220
+ mode: "conversation",
221
+ sandbox,
222
+ sandboxSignal,
223
+ failureSignal: failure.signal,
224
+ context,
225
+ plan,
226
+ runId: run.id,
227
+ threadId: run.threadId,
228
+ callTool: (call, options) => input.session.callTool(call, options),
229
+ ...(input.thread && run.execution
230
+ ? {
231
+ publishing: {
232
+ artifacts: input.session.artifacts,
233
+ threadId: input.thread.id,
234
+ owner: input.thread.ownerPrincipal,
235
+ },
236
+ }
237
+ : {}),
238
+ apiBaseUrl,
239
+ attachmentContext,
240
+ ontologyDocs,
241
+ frameworkTools: input.frameworkTools,
242
+ ...(memory ? { memory } : {}),
243
+ onDetachedTeardown: input.onDetachedTeardown,
244
+ })
245
+ return { ...environment, threadContext }
246
+ } catch (error) {
247
+ // Preparation can fail before the worker receives this environment. Preserve here, before
248
+ // the worker records the run's terminal outcome; a lost execution must touch nothing.
249
+ try {
250
+ if (!isLostExecution(error, input.signal)) await sandbox.beforeFinalize?.()
251
+ } finally {
252
+ await environment?.dispose()
253
+ }
254
+ throw error
255
+ }
256
+ }
257
+
258
+ /**
259
+ * Build an isolated environment for one headless child Agent. It knows the project as its parent
260
+ * does (ontology docs, memory to read), holds the files its parent handed over at their paths, and
261
+ * publishes into its conversation, as its own run.
262
+ *
263
+ * On a provider that resumes sandboxes, its thread keeps its workspace while it pauses: the run
264
+ * that continues it finds every file where it was. Elsewhere, or once those files were lost, it
265
+ * starts blank, with the handed files and what the paused run left in `out/` given back.
266
+ */
267
+ export async function createSubagentEnvironment(
268
+ input: CreateSubagentEnvironmentInput
269
+ ): Promise<AgentExecutionEnvironment> {
270
+ // A child's workspace is blank, so it has no source credentials to lose.
271
+ const { sandbox, resumed = false } = await input.openSandbox({
272
+ signal: input.signal ?? NEVER_ABORTED_SIGNAL,
273
+ onFailure: () => {},
274
+ })
275
+
276
+ try {
277
+ return await startSubagentEnvironment({ ...input, sandbox, resumed })
278
+ } catch (error) {
279
+ // Preparation failed before the worker got this environment: the child ends here, so its
280
+ // workspace goes, as the worker's failure path would destroy it. A lost execution must touch
281
+ // nothing.
282
+ if (!isLostExecution(error, input.signal)) await sandbox.beforeFinalize?.({ discard: true })
283
+ throw error
284
+ }
285
+ }
286
+
287
+ async function startSubagentEnvironment(
288
+ input: CreateSubagentEnvironmentInput & {
289
+ readonly sandbox: RunSandbox
290
+ /** Whether the sandbox is the workspace the paused run left: it holds its files already. */
291
+ readonly resumed: boolean
292
+ }
293
+ ): Promise<AgentExecutionEnvironment> {
294
+ const { context, plan, run, conversation, sandbox, resumed } = input
295
+ // Still listed, as handed over, but never copied over what the child made of them.
296
+ const files = resumed ? (run.spec.files ?? []) : subagentSandboxFiles(run, input.history.paused)
297
+ const history = input.history.messages
298
+ const [memory, handedContext, historyContext] = await Promise.all([
299
+ // As of the thread's start, as a conversation's: each run of the child reads the same memory.
300
+ loadConversationMemory({ session: input.session, asOf: input.thread.createdAt }),
301
+ files.length
302
+ ? prepareHandedFiles({
303
+ projectId: context.id,
304
+ parentRunId: run.parentRunId,
305
+ files,
306
+ inSandbox: resumed,
307
+ contextDirectory: sandbox.contextDirectory,
308
+ blobStorage: context.blobStorage,
309
+ signal: input.signal,
310
+ })
311
+ : emptyAttachmentContext(context.id),
312
+ history.length && context.apiBaseUrl
313
+ ? prepareAgentAttachments({
314
+ projectId: context.id,
315
+ // Its messages are its thread's, so their files are read there.
316
+ threadId: input.thread.id,
317
+ messages: history,
318
+ blobStorage: context.blobStorage,
319
+ apiBaseUrl: context.apiBaseUrl,
320
+ contextDirectory: sandbox.contextDirectory,
321
+ inlineImages: modelSupportsInlineImages(plan.model),
322
+ signal: input.signal,
323
+ })
324
+ : undefined,
325
+ ])
326
+ const attachmentContext = historyContext
327
+ ? mergeAttachmentContexts(handedContext, historyContext)
328
+ : handedContext
329
+
330
+ return startAgentEnvironment({
331
+ mode: "subagent",
332
+ sandbox,
333
+ sandboxSignal: input.signal,
334
+ context,
335
+ plan,
336
+ runId: run.id,
337
+ parentRunId: run.parentRunId,
338
+ threadId: conversationThreadId(input.thread),
339
+ callTool: (call, options) => input.session.callTool(call, options),
340
+ ...(conversation
341
+ ? {
342
+ publishing: {
343
+ artifacts: input.session.artifacts,
344
+ threadId: conversation.id,
345
+ owner: conversation.ownerPrincipal,
346
+ },
347
+ }
348
+ : {}),
349
+ apiBaseUrl: context.apiBaseUrl,
350
+ attachmentContext,
351
+ ontologyDocs: plan.ontologyDocs,
352
+ ...(memory ? { memory } : {}),
353
+ frameworkTools: input.frameworkTools,
354
+ errorDetails: { parentRunId: run.parentRunId, runId: run.id },
355
+ onDetachedTeardown: input.onDetachedTeardown,
356
+ })
357
+ }
358
+
359
+ /** Build the same tool/sandbox environment for a fresh, headless workflow task. */
360
+ export async function createWorkflowAgentNodeEnvironment(
361
+ input: CreateWorkflowAgentNodeEnvironmentInput
362
+ ): Promise<AgentExecutionEnvironment> {
363
+ const { context, plan, run } = input
364
+ const execution = run.execution
365
+ if (!execution) {
366
+ throw new Error(
367
+ `[SixbAgent] Agent workflow node run '${run.nodeRunId}' must hold an execution token.`
368
+ )
369
+ }
370
+ // Cancellation, lost ownership or worker shutdown stop provisioning. A step's lost source
371
+ // credentials end the node through `failure`.
372
+ const failure = new AbortController()
373
+ const sandboxSignal = input.signal
374
+ ? AbortSignal.any([input.signal, failure.signal])
375
+ : failure.signal
376
+
377
+ const { sandbox } = await input.openSandbox({
378
+ signal: sandboxSignal,
379
+ onFailure: (error) => failure.abort(error),
380
+ })
381
+ const attachmentContext = await prepareWorkflowInputAttachments({
382
+ input: input.nodeInput,
383
+ blobStorage: context.blobStorage,
384
+ contextDirectory: sandbox.contextDirectory,
385
+ signal: input.signal,
386
+ })
387
+
388
+ try {
389
+ return await startAgentEnvironment({
390
+ mode: "workflow-task",
391
+ sandbox,
392
+ sandboxSignal,
393
+ failureSignal: failure.signal,
394
+ context,
395
+ actorId: run.actorId,
396
+ plan,
397
+ runId: run.nodeRunId,
398
+ callTool: input.callTool,
399
+ apiBaseUrl: context.apiBaseUrl,
400
+ attachmentContext,
401
+ ontologyDocs: plan.ontologyDocs,
402
+ errorDetails: input.errorDetails,
403
+ onDetachedTeardown: input.onDetachedTeardown,
404
+ })
405
+ } catch (error) {
406
+ // Provisioning can fail, or be abandoned, before the node receives this environment. Confirm
407
+ // the step's credentials are closed before the node records its fate; a lost execution must
408
+ // touch nothing.
409
+ if (!isLostExecution(error, input.signal)) await sandbox.beforeFinalize?.()
410
+ throw error
411
+ }
412
+ }
413
+
414
+ interface AgentEnvironmentSetup
415
+ extends Omit<CreateAgentEnvironmentInput, "signal" | "openSandbox"> {
416
+ readonly sandbox: RunSandbox
417
+ /**
418
+ * Run end or environment failure: stops waiting for a sandbox the first model call needs, and
419
+ * stops reading the artifacts it installs.
420
+ */
421
+ readonly sandboxSignal?: AbortSignal
422
+ /** Environment-owned failure, such as lost source credentials. */
423
+ readonly failureSignal?: AbortSignal
424
+ /** How the run calls a project tool. */
425
+ readonly callTool: AgentToolCaller
426
+ readonly actorId?: string
427
+ readonly parentRunId?: string
428
+ readonly mode: AgentExecutionMode
429
+ readonly runId: string
430
+ readonly threadId?: string
431
+ readonly apiBaseUrl: string
432
+ readonly attachmentContext: PreparedAgentAttachmentContext
433
+ /** Installed under `$SIXB_ONTOLOGY_DIR`; a workflow step's prompt does not list them. */
434
+ readonly ontologyDocs?: RenderedOntologyDocs
435
+ readonly errorDetails?: AgentErrorDetails
436
+ readonly frameworkTools?: readonly ModelTool[]
437
+ /**
438
+ * A conversation, or a child of one, publishes artifacts into its conversation, through its
439
+ * session, and edits them from their installed copies; other runs return text.
440
+ */
441
+ readonly publishing?: {
442
+ readonly artifacts: AgentRunArtifacts
443
+ /** The conversation's thread, and its owner, who owns what the run creates. */
444
+ readonly threadId: string
445
+ readonly owner: Principal
446
+ }
447
+ /** A conversation's memory, or a child's to read: installed in the sandbox and in the prompt. */
448
+ readonly memory?: ConversationMemory
449
+ }
450
+
451
+ /**
452
+ * Start the shared tools, sandbox, and teardown lifecycle after source-specific preparation.
453
+ * A blank sandbox boots concurrently with the model call and tools await it only when used; a
454
+ * workspace (a thread's or a step's) is ready first, so the system prompt describes the one the
455
+ * run got.
456
+ */
457
+ async function startAgentEnvironment(
458
+ input: AgentEnvironmentSetup
459
+ ): Promise<AgentExecutionEnvironment> {
460
+ const { mode, sandbox, context, actorId, plan, runId, threadId, apiBaseUrl, attachmentContext } =
461
+ input
462
+
463
+ let ready: Promise<ProvisionedRunSandbox>
464
+ const fileRegistry = new AgentSandboxFileRegistry()
465
+ const fileBudget = new AgentFileBudget()
466
+ const mediaBridge = new AgentToolResultMediaBridge({
467
+ blobStorage: context.blobStorage,
468
+ sandboxPathForFileRef: (fileRef) => fileRegistry.pathFor(fileRef),
469
+ })
470
+ const filesForToolCall = (input: {
471
+ readonly toolName: string
472
+ readonly toolCallId: string
473
+ readonly signal: AbortSignal
474
+ }) =>
475
+ createAgentToolFiles({
476
+ ...input,
477
+ blobStorage: context.blobStorage,
478
+ budget: fileBudget,
479
+ resolveSandbox: () => ready,
480
+ onPublished: (file) => fileRegistry.register(file.sandboxPath, file.fileRef),
481
+ })
482
+ const tools = [
483
+ ...projectModelTools({
484
+ specs: plan.tools,
485
+ runId,
486
+ callTool: input.callTool,
487
+ fileBytesLeft: () => fileBudget.maxBytes - fileBudget.reservedBytes,
488
+ installFiles: ({ toolName, files, signal }) =>
489
+ installAgentToolFiles({
490
+ toolName,
491
+ files,
492
+ blobStorage: context.blobStorage,
493
+ resolveSandbox: () => ready,
494
+ budget: fileBudget,
495
+ signal,
496
+ onPublished: (file) => fileRegistry.register(file.sandboxPath, file.fileRef),
497
+ }),
498
+ toolResultToModelOutput: (output) => mediaBridge.toModelOutput(output),
499
+ ...(input.errorDetails === undefined ? {} : { errorDetails: input.errorDetails }),
500
+ }),
501
+ ]
502
+
503
+ appendBuiltInTool(
504
+ tools,
505
+ createViewFileTool({
506
+ resolveSandbox: () => ready,
507
+ attachments: attachmentContext,
508
+ registry: fileRegistry,
509
+ filesForToolCall: ({ toolCallId, signal }) =>
510
+ filesForToolCall({ toolName: "view_file", toolCallId, signal }),
511
+ toolResultToModelOutput: (output) => mediaBridge.toModelOutput(output),
512
+ })
513
+ )
514
+ const resolveSandbox = () => ready
515
+ appendBuiltInTool(tools, createReadTool(resolveSandbox))
516
+ appendBuiltInTool(tools, createBashTool(resolveSandbox))
517
+ let installedArtifacts: Promise<InstalledArtifacts> | undefined
518
+ const { publishing } = input
519
+ if (publishing) {
520
+ // Read concurrently with sandbox creation; both run while the model starts.
521
+ installedArtifacts = materializeThreadArtifacts({
522
+ threadId: publishing.threadId,
523
+ // As the requester: the turn installs nothing they could not read themselves.
524
+ artifacts: publishing.artifacts,
525
+ blobStorage: context.blobStorage,
526
+ directory: posix.join(sandbox.contextDirectory, AGENT_ARTIFACTS_DIRECTORY),
527
+ manifestPath: posix.join(sandbox.contextDirectory, AGENT_ARTIFACTS_MANIFEST),
528
+ signal: input.sandboxSignal,
529
+ })
530
+ // Surfaced where provisioning awaits it.
531
+ installedArtifacts.catch(() => {})
532
+ const publishTools = createPublishArtifactTools({
533
+ artifacts: publishing.artifacts,
534
+ threadId: publishing.threadId,
535
+ owner: publishing.owner,
536
+ blobStorage: context.blobStorage,
537
+ budget: fileBudget,
538
+ resolveSandbox,
539
+ installed: installedArtifacts,
540
+ })
541
+ for (const tool of publishTools) appendBuiltInTool(tools, tool)
542
+ }
543
+ for (const frameworkTool of input.frameworkTools ?? []) appendBuiltInTool(tools, frameworkTool)
544
+
545
+ ready = provisionSandbox({
546
+ sandbox,
547
+ context,
548
+ actorId,
549
+ run: { id: runId, ...(threadId ? { threadId } : {}) },
550
+ apiBaseUrl,
551
+ attachmentContext,
552
+ // A conversation's memory section names the memory skill; other runs never see it.
553
+ skills: input.memory && mode === "conversation" ? [...plan.skills, MEMORY_SKILL] : plan.skills,
554
+ ontologyFiles: input.ontologyDocs?.files ?? [],
555
+ ...(installedArtifacts ? { artifacts: installedArtifacts } : {}),
556
+ ...(input.memory ? { memory: input.memory.repos } : {}),
557
+ })
558
+ // Creation failure is surfaced where it is awaited (turn / sandbox tool / dispose); attach a no-op
559
+ // catch so a rejection observed by none of them is not reported as unhandled.
560
+ ready.catch(() => {})
561
+ // Track settlement so dispose() can avoid blocking teardown on a boot still in flight.
562
+ let settled = false
563
+ const markSettled = () => {
564
+ settled = true
565
+ }
566
+ ready.then(markSettled, markSettled)
567
+
568
+ const dispose = () => disposeEnvironment(ready, () => settled, sandbox, input.onDetachedTeardown)
569
+
570
+ let systemPrompt: string
571
+ try {
572
+ const workspace = sandbox.waitBeforeModel
573
+ ? await waitForAbort(ready, input.sandboxSignal)
574
+ : undefined
575
+
576
+ systemPrompt = renderAgentSystemPrompt({
577
+ mode,
578
+ contextDirectory: sandbox.contextDirectory,
579
+ instructions: plan.instructions,
580
+ skills: plan.skills,
581
+ // Workflow prompts are kept lean: their steps get the files without the index.
582
+ ...(mode !== "workflow-task" && input.ontologyDocs
583
+ ? { ontologyIndex: input.ontologyDocs.index }
584
+ : {}),
585
+ sandboxResetAt: workspace?.resetAt,
586
+ workspace: workspace?.promptContext,
587
+ facts: agentRuntimeFacts({
588
+ settings: plan,
589
+ project: context,
590
+ requester: context.requester,
591
+ }),
592
+ ...(plan.sandboxModels ? { sandboxModels: plan.sandboxModels } : {}),
593
+ ...(input.memory ? { memory: input.memory.prompt } : {}),
594
+ })
595
+ } catch (error) {
596
+ // Provisioning has started: give back what it acquires, or the sandbox outlives the run.
597
+ await dispose()
598
+ throw error
599
+ }
600
+
601
+ const beforeFinalize = (options?: BeforeFinalizeOptions) =>
602
+ sandbox.beforeFinalize?.(options) ?? Promise.resolve()
603
+ const artifacts =
604
+ publishing && installedArtifacts
605
+ ? { reader: publishing.artifacts, installed: installedArtifacts }
606
+ : undefined
607
+ const runFiles: AgentRunFiles = {
608
+ sandbox: resolveSandbox,
609
+ blobStorage: context.blobStorage,
610
+ budget: fileBudget,
611
+ async installArtifactsFrom(runIds, signal) {
612
+ if (!artifacts) return
613
+
614
+ await installArtifactsPublishedBy({
615
+ installed: await artifacts.installed,
616
+ artifacts: artifacts.reader,
617
+ blobStorage: context.blobStorage,
618
+ sandbox: (await ready).sandbox,
619
+ runIds,
620
+ signal,
621
+ })
622
+ },
623
+ }
624
+ return {
625
+ beforeFinalize,
626
+ runFiles,
627
+ turnContext: {
628
+ environmentFailureSignal: input.failureSignal,
629
+ ...(sandbox.beforeFinalize ? { beforeFinalize } : {}),
630
+ id: context.id,
631
+ ...(context.authorPrincipal === undefined
632
+ ? {}
633
+ : { authorPrincipal: context.authorPrincipal }),
634
+ blobStorage: context.blobStorage,
635
+ apiBaseUrl,
636
+ attachmentContext,
637
+ tools,
638
+ prepareStep: mediaBridge.prepareStep,
639
+ systemPrompt,
640
+ projectTimeZone: context.timeZone,
641
+ sandboxReady: ready,
642
+ },
643
+ dispose,
644
+ }
645
+ }
646
+
647
+ /** The handed files' context, with what a continuation's history showed its tools. */
648
+ function mergeAttachmentContexts(
649
+ handed: PreparedAgentAttachmentContext,
650
+ history: PreparedAgentAttachmentContext
651
+ ): PreparedAgentAttachmentContext {
652
+ const manifest = (json: string) => JSON.parse(json) as { readonly attachments?: unknown[] }
653
+ const handedManifest = manifest(handed.manifestJson)
654
+ return {
655
+ entries: [...handed.entries, ...history.entries],
656
+ promptTextByPartKey: new Map([...handed.promptTextByPartKey, ...history.promptTextByPartKey]),
657
+ modelFileDataByPartKey: new Map([
658
+ ...handed.modelFileDataByPartKey,
659
+ ...history.modelFileDataByPartKey,
660
+ ]),
661
+ sandboxFiles: [...handed.sandboxFiles, ...history.sandboxFiles],
662
+ manifestJson: JSON.stringify(
663
+ {
664
+ ...handedManifest,
665
+ attachments: [
666
+ ...(handedManifest.attachments ?? []),
667
+ ...(manifest(history.manifestJson).attachments ?? []),
668
+ ],
669
+ },
670
+ null,
671
+ 2
672
+ ),
673
+ }
674
+ }
675
+
676
+ function emptyAttachmentContext(projectId: string): PreparedAgentAttachmentContext {
677
+ return {
678
+ entries: [],
679
+ promptTextByPartKey: new Map(),
680
+ modelFileDataByPartKey: new Map(),
681
+ sandboxFiles: [],
682
+ manifestJson: JSON.stringify({ projectId, attachments: [] }, null, 2),
683
+ }
684
+ }
685
+
686
+ interface ProvisionSandboxInput {
687
+ readonly sandbox: RunSandbox
688
+ readonly context: AgentExecutionContext
689
+ readonly actorId?: string
690
+ readonly run: { readonly id: string; readonly threadId?: string }
691
+ readonly apiBaseUrl: string
692
+ readonly attachmentContext: PreparedAgentAttachmentContext
693
+ readonly skills: ResolvedAgentExecutionPlan["skills"]
694
+ readonly ontologyFiles: RenderedOntologyDocs["files"]
695
+ /** The conversation's artifacts, read while the sandbox starts. */
696
+ readonly artifacts?: Promise<MaterializedArtifacts>
697
+ readonly memory?: PrepareAgentSandboxApiContextInput["memory"]
698
+ }
699
+
700
+ /** A sandbox acquired for the run, with the run's files installed in its context directory. */
701
+ type ProvisionedRunSandbox = AcquiredRunSandbox & AgentSandboxHandle
702
+
703
+ async function provisionSandbox(input: ProvisionSandboxInput): Promise<ProvisionedRunSandbox> {
704
+ const { context, actorId, run, apiBaseUrl, skills, ontologyFiles } = input
705
+ const acquired = await input.sandbox.acquire()
706
+ const { sandbox } = acquired
707
+ const { contextDirectory } = input.sandbox
708
+ try {
709
+ const apiContext = await prepareAgentSandboxApiContext({
710
+ sandbox,
711
+ contextDirectory,
712
+ apiBaseUrl,
713
+ projectId: context.id,
714
+ ...(actorId === undefined ? {} : { actorId }),
715
+ ...(run.threadId ? { threadId: run.threadId } : {}),
716
+ runId: run.id,
717
+ attachments: input.attachmentContext,
718
+ skills,
719
+ ontologyFiles,
720
+ ...(input.artifacts ? { artifacts: await input.artifacts } : {}),
721
+ ...(input.memory ? { memory: input.memory } : {}),
722
+ })
723
+ await assertAgentRuntimeProfile({
724
+ sandbox,
725
+ env: apiContext.env,
726
+ projectId: context.id,
727
+ })
728
+ return { ...acquired, contextDirectory, env: { ...acquired.env, ...apiContext.env } }
729
+ } catch (error) {
730
+ // Give back a half-provisioned sandbox before propagating to the awaiter.
731
+ await input.sandbox.release?.(acquired).catch(() => {})
732
+ throw error
733
+ }
734
+ }
735
+
736
+ function disposeEnvironment(
737
+ ready: Promise<AcquiredRunSandbox>,
738
+ isSettled: () => boolean,
739
+ sandbox: RunSandbox,
740
+ onDetachedTeardown?: (teardown: Promise<void>) => void
741
+ ): Promise<void> {
742
+ // Nothing to give back: teardown, and a worker's stop(), must not wait on provisioning.
743
+ const release = sandbox.release?.bind(sandbox)
744
+ if (!release) return Promise.resolve()
745
+
746
+ // Release the sandbox once provisioning settles. A rejection means provisionSandbox already
747
+ // released whatever it acquired, so there is nothing left to give back.
748
+ const teardown = ready
749
+ .then(release, () => undefined)
750
+ .catch((error) => {
751
+ console.error("[SixbAgent] Could not release agent run sandbox:", error)
752
+ })
753
+ // Once provisioning has settled, await the release so cleanup completes inline.
754
+ if (isSettled()) {
755
+ return teardown
756
+ }
757
+ // Boot still in flight (the model answered before it finished and never used bash): don't stall
758
+ // run teardown on it. Hand the chained release to the worker so a graceful stop() can drain it
759
+ // rather than orphaning a machine that is still being torn down.
760
+ onDetachedTeardown?.(teardown)
761
+ return Promise.resolve()
762
+ }
763
+
764
+ function appendBuiltInTool(tools: ModelTool[], tool: ModelTool): void {
765
+ if (tools.some((candidate) => candidate.name === tool.name)) {
766
+ throw new Error(`[SixbAgent] Agent tool name '${tool.name}' is reserved by the worker runtime.`)
767
+ }
768
+ tools.push(tool)
769
+ }