@bastani/atomic 0.9.20-alpha.8 → 0.9.20-alpha.9

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 (287) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/builtin/intercom/package.json +3 -5
  3. package/dist/builtin/mcp/package.json +3 -3
  4. package/dist/builtin/subagents/CHANGELOG.md +6 -0
  5. package/dist/builtin/subagents/package.json +3 -3
  6. package/dist/builtin/subagents/src/extension/index.bundle.mjs +11 -2
  7. package/dist/builtin/web-access/package.json +1 -1
  8. package/dist/builtin/workflows/CHANGELOG.md +31 -0
  9. package/dist/builtin/workflows/builtin/adversarial-verification.js +3 -3
  10. package/dist/builtin/workflows/builtin/{chunk-ffdrv23t.js → chunk-18yz7r43.js} +1 -1
  11. package/dist/builtin/workflows/builtin/{chunk-9z3ztr2a.js → chunk-1pd5zcfa.js} +1 -1
  12. package/dist/builtin/workflows/builtin/{chunk-5724b0cf.js → chunk-24c235x7.js} +1 -1
  13. package/dist/builtin/workflows/builtin/{chunk-vn0wb31x.js → chunk-2jv44yz7.js} +1 -1
  14. package/dist/builtin/workflows/builtin/{chunk-hmt5w62g.js → chunk-2npg6daz.js} +1 -1
  15. package/dist/builtin/workflows/builtin/{chunk-njmf5ze7.js → chunk-7ps7bnb4.js} +1 -1
  16. package/dist/builtin/workflows/builtin/{chunk-jngsbbpm.js → chunk-ad864596.js} +3 -3
  17. package/dist/builtin/workflows/builtin/{chunk-7n51c5gh.js → chunk-f8jjd90r.js} +1 -1
  18. package/dist/builtin/workflows/builtin/{chunk-3tx8ry44.js → chunk-gxrhbnaj.js} +2 -1
  19. package/dist/builtin/workflows/builtin/{chunk-2hzrv5y8.js → chunk-twefqrv0.js} +986 -199
  20. package/dist/builtin/workflows/builtin/{chunk-7bzcersz.js → chunk-ynded223.js} +3 -3
  21. package/dist/builtin/workflows/builtin/{chunk-dxjxtgmp.js → chunk-z5xdqrs6.js} +1 -1
  22. package/dist/builtin/workflows/builtin/classify-and-act.js +3 -3
  23. package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +3 -3
  24. package/dist/builtin/workflows/builtin/generate-and-filter.js +3 -3
  25. package/dist/builtin/workflows/builtin/goal.js +4 -4
  26. package/dist/builtin/workflows/builtin/index.js +12 -12
  27. package/dist/builtin/workflows/builtin/loop-until-done.js +3 -3
  28. package/dist/builtin/workflows/builtin/open-claude-design.js +3 -3
  29. package/dist/builtin/workflows/builtin/ralph.js +4 -4
  30. package/dist/builtin/workflows/builtin/steering-context.js +1 -1
  31. package/dist/builtin/workflows/builtin/tournament.js +3 -3
  32. package/dist/builtin/workflows/package.json +4 -4
  33. package/dist/builtin/workflows/src/authoring.d.ts +6 -3
  34. package/dist/builtin/workflows/src/extension/index.bundle.mjs +12092 -11365
  35. package/dist/builtin/workflows/src/index.js +41619 -12907
  36. package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +13 -0
  37. package/dist/core/agent-session-boundaries.d.ts.map +1 -1
  38. package/dist/core/agent-session-boundaries.js +9 -4
  39. package/dist/core/agent-session-boundaries.js.map +1 -1
  40. package/dist/core/agent-session-events.d.ts.map +1 -1
  41. package/dist/core/agent-session-events.js +4 -0
  42. package/dist/core/agent-session-events.js.map +1 -1
  43. package/dist/core/agent-session-methods.d.ts +3 -0
  44. package/dist/core/agent-session-methods.d.ts.map +1 -1
  45. package/dist/core/agent-session-methods.js.map +1 -1
  46. package/dist/core/agent-session-tasks.js +4 -4
  47. package/dist/core/agent-session-tasks.js.map +1 -1
  48. package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
  49. package/dist/core/agent-session-tool-registry.js +4 -3
  50. package/dist/core/agent-session-tool-registry.js.map +1 -1
  51. package/dist/core/agent-session.d.ts +3 -0
  52. package/dist/core/agent-session.d.ts.map +1 -1
  53. package/dist/core/agent-session.js +3 -0
  54. package/dist/core/agent-session.js.map +1 -1
  55. package/dist/core/cache-stats.d.ts +7 -1
  56. package/dist/core/cache-stats.d.ts.map +1 -1
  57. package/dist/core/cache-stats.js +24 -5
  58. package/dist/core/cache-stats.js.map +1 -1
  59. package/dist/core/execution-model-router.d.ts +1 -1
  60. package/dist/core/execution-model-router.d.ts.map +1 -1
  61. package/dist/core/execution-model-router.js +23 -14
  62. package/dist/core/execution-model-router.js.map +1 -1
  63. package/dist/core/extensions/agent-events.d.ts +9 -1
  64. package/dist/core/extensions/agent-events.d.ts.map +1 -1
  65. package/dist/core/extensions/agent-events.js.map +1 -1
  66. package/dist/core/extensions/api-types.d.ts +2 -1
  67. package/dist/core/extensions/api-types.d.ts.map +1 -1
  68. package/dist/core/extensions/api-types.js.map +1 -1
  69. package/dist/core/extensions/event-types.d.ts +2 -2
  70. package/dist/core/extensions/event-types.d.ts.map +1 -1
  71. package/dist/core/extensions/event-types.js.map +1 -1
  72. package/dist/core/extensions/index.d.ts +1 -1
  73. package/dist/core/extensions/index.d.ts.map +1 -1
  74. package/dist/core/extensions/index.js.map +1 -1
  75. package/dist/core/extensions/loader-core.d.ts.map +1 -1
  76. package/dist/core/extensions/loader-core.js +1 -0
  77. package/dist/core/extensions/loader-core.js.map +1 -1
  78. package/dist/core/extensions/provider-types.d.ts +34 -16
  79. package/dist/core/extensions/provider-types.d.ts.map +1 -1
  80. package/dist/core/extensions/provider-types.js.map +1 -1
  81. package/dist/core/extensions/runtime-types.d.ts +4 -0
  82. package/dist/core/extensions/runtime-types.d.ts.map +1 -1
  83. package/dist/core/extensions/runtime-types.js.map +1 -1
  84. package/dist/core/extensions/tool-types.d.ts +9 -0
  85. package/dist/core/extensions/tool-types.d.ts.map +1 -1
  86. package/dist/core/extensions/tool-types.js.map +1 -1
  87. package/dist/core/fast-model-routing.d.ts.map +1 -1
  88. package/dist/core/fast-model-routing.js +1 -0
  89. package/dist/core/fast-model-routing.js.map +1 -1
  90. package/dist/core/model-registry.d.ts +3 -1
  91. package/dist/core/model-registry.d.ts.map +1 -1
  92. package/dist/core/model-registry.js +6 -0
  93. package/dist/core/model-registry.js.map +1 -1
  94. package/dist/core/model-runtime-auth.d.ts +2 -2
  95. package/dist/core/model-runtime-auth.d.ts.map +1 -1
  96. package/dist/core/model-runtime-auth.js.map +1 -1
  97. package/dist/core/model-runtime-streaming.d.ts.map +1 -1
  98. package/dist/core/model-runtime-streaming.js +2 -1
  99. package/dist/core/model-runtime-streaming.js.map +1 -1
  100. package/dist/core/model-runtime.d.ts +11 -3
  101. package/dist/core/model-runtime.d.ts.map +1 -1
  102. package/dist/core/model-runtime.js +41 -6
  103. package/dist/core/model-runtime.js.map +1 -1
  104. package/dist/core/package-manager-npm.d.ts.map +1 -1
  105. package/dist/core/package-manager-npm.js +32 -8
  106. package/dist/core/package-manager-npm.js.map +1 -1
  107. package/dist/core/package-manager-resolver.js +3 -1
  108. package/dist/core/package-manager-resolver.js.map +1 -1
  109. package/dist/core/package-manager-types.d.ts +1 -0
  110. package/dist/core/package-manager-types.d.ts.map +1 -1
  111. package/dist/core/package-manager-types.js.map +1 -1
  112. package/dist/core/provider-composer-internal.d.ts +40 -21
  113. package/dist/core/provider-composer-internal.d.ts.map +1 -1
  114. package/dist/core/provider-composer-internal.js +22 -20
  115. package/dist/core/provider-composer-internal.js.map +1 -1
  116. package/dist/core/provider-composer.d.ts +3 -3
  117. package/dist/core/provider-composer.d.ts.map +1 -1
  118. package/dist/core/provider-composer.js +54 -10
  119. package/dist/core/provider-composer.js.map +1 -1
  120. package/dist/core/remote-catalog-provider.d.ts +8 -1
  121. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  122. package/dist/core/remote-catalog-provider.js +46 -4
  123. package/dist/core/remote-catalog-provider.js.map +1 -1
  124. package/dist/core/resource-loader-core.d.ts.map +1 -1
  125. package/dist/core/resource-loader-core.js +7 -3
  126. package/dist/core/resource-loader-core.js.map +1 -1
  127. package/dist/core/resource-loader-extension-warnings.d.ts +9 -0
  128. package/dist/core/resource-loader-extension-warnings.d.ts.map +1 -0
  129. package/dist/core/resource-loader-extension-warnings.js +54 -0
  130. package/dist/core/resource-loader-extension-warnings.js.map +1 -0
  131. package/dist/core/resource-loader-extensions.d.ts.map +1 -1
  132. package/dist/core/resource-loader-extensions.js +1 -0
  133. package/dist/core/resource-loader-extensions.js.map +1 -1
  134. package/dist/core/resource-loader-reload.d.ts.map +1 -1
  135. package/dist/core/resource-loader-reload.js +6 -0
  136. package/dist/core/resource-loader-reload.js.map +1 -1
  137. package/dist/core/runtime-credentials.d.ts.map +1 -1
  138. package/dist/core/runtime-credentials.js +3 -1
  139. package/dist/core/runtime-credentials.js.map +1 -1
  140. package/dist/core/sdk.js +16 -6
  141. package/dist/core/sdk.js.map +1 -1
  142. package/dist/core/settings-manager-basic-accessors.js +4 -4
  143. package/dist/core/settings-manager-basic-accessors.js.map +1 -1
  144. package/dist/core/structured-output/choice-schema.d.ts +8 -0
  145. package/dist/core/structured-output/choice-schema.d.ts.map +1 -0
  146. package/dist/core/structured-output/choice-schema.js +79 -0
  147. package/dist/core/structured-output/choice-schema.js.map +1 -0
  148. package/dist/core/structured-output/index.d.ts +3 -5
  149. package/dist/core/structured-output/index.d.ts.map +1 -1
  150. package/dist/core/structured-output/index.js +218 -41
  151. package/dist/core/structured-output/index.js.map +1 -1
  152. package/dist/core/structured-output/resolver.d.ts +0 -46
  153. package/dist/core/structured-output/resolver.d.ts.map +1 -1
  154. package/dist/core/structured-output/resolver.js +15 -93
  155. package/dist/core/structured-output/resolver.js.map +1 -1
  156. package/dist/core/structured-output/types.d.ts +27 -21
  157. package/dist/core/structured-output/types.d.ts.map +1 -1
  158. package/dist/core/structured-output/types.js.map +1 -1
  159. package/dist/core/system-prompt.d.ts.map +1 -1
  160. package/dist/core/system-prompt.js +9 -1
  161. package/dist/core/system-prompt.js.map +1 -1
  162. package/dist/core/tasks/owner-store.d.ts +6 -0
  163. package/dist/core/tasks/owner-store.d.ts.map +1 -1
  164. package/dist/core/tasks/owner-store.js +16 -3
  165. package/dist/core/tasks/owner-store.js.map +1 -1
  166. package/dist/core/tasks/pause.js +1 -1
  167. package/dist/core/tasks/pause.js.map +1 -1
  168. package/dist/core/tasks/supervisor.d.ts +4 -2
  169. package/dist/core/tasks/supervisor.d.ts.map +1 -1
  170. package/dist/core/tasks/supervisor.js +9 -3
  171. package/dist/core/tasks/supervisor.js.map +1 -1
  172. package/dist/core/tools/ask-user-question/ask-user-question.d.ts.map +1 -1
  173. package/dist/core/tools/ask-user-question/ask-user-question.js +1 -0
  174. package/dist/core/tools/ask-user-question/ask-user-question.js.map +1 -1
  175. package/dist/core/tools/bash.d.ts.map +1 -1
  176. package/dist/core/tools/bash.js +1 -0
  177. package/dist/core/tools/bash.js.map +1 -1
  178. package/dist/core/tools/edit.d.ts.map +1 -1
  179. package/dist/core/tools/edit.js +1 -0
  180. package/dist/core/tools/edit.js.map +1 -1
  181. package/dist/core/tools/file-mutation-coordinator.d.ts +4 -3
  182. package/dist/core/tools/file-mutation-coordinator.d.ts.map +1 -1
  183. package/dist/core/tools/file-mutation-coordinator.js +45 -38
  184. package/dist/core/tools/file-mutation-coordinator.js.map +1 -1
  185. package/dist/core/tools/powershell.d.ts +16 -0
  186. package/dist/core/tools/powershell.d.ts.map +1 -1
  187. package/dist/core/tools/structured-output.d.ts +9 -6
  188. package/dist/core/tools/structured-output.d.ts.map +1 -1
  189. package/dist/core/tools/structured-output.js +36 -8
  190. package/dist/core/tools/structured-output.js.map +1 -1
  191. package/dist/core/tools/todos.d.ts.map +1 -1
  192. package/dist/core/tools/todos.js +1 -0
  193. package/dist/core/tools/todos.js.map +1 -1
  194. package/dist/core/tools/tool-concurrency.d.ts +23 -0
  195. package/dist/core/tools/tool-concurrency.d.ts.map +1 -0
  196. package/dist/core/tools/tool-concurrency.js +58 -0
  197. package/dist/core/tools/tool-concurrency.js.map +1 -0
  198. package/dist/core/tools/tool-definition-wrapper.d.ts +4 -1
  199. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  200. package/dist/core/tools/tool-definition-wrapper.js +2 -0
  201. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  202. package/dist/core/tools/write.d.ts.map +1 -1
  203. package/dist/core/tools/write.js +1 -0
  204. package/dist/core/tools/write.js.map +1 -1
  205. package/dist/index-extensions.d.ts +1 -1
  206. package/dist/index-extensions.d.ts.map +1 -1
  207. package/dist/index-extensions.js.map +1 -1
  208. package/dist/index.d.ts +1 -1
  209. package/dist/index.d.ts.map +1 -1
  210. package/dist/index.js +1 -1
  211. package/dist/index.js.map +1 -1
  212. package/dist/main.d.ts.map +1 -1
  213. package/dist/main.js +4 -0
  214. package/dist/main.js.map +1 -1
  215. package/dist/modes/interactive/components/settings-selector-items.d.ts.map +1 -1
  216. package/dist/modes/interactive/components/settings-selector-items.js +11 -9
  217. package/dist/modes/interactive/components/settings-selector-items.js.map +1 -1
  218. package/dist/modes/interactive/components/settings-selector-types.d.ts +2 -1
  219. package/dist/modes/interactive/components/settings-selector-types.d.ts.map +1 -1
  220. package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
  221. package/dist/modes/interactive/components/task-inspector.d.ts +1 -0
  222. package/dist/modes/interactive/components/task-inspector.d.ts.map +1 -1
  223. package/dist/modes/interactive/components/task-inspector.js +11 -11
  224. package/dist/modes/interactive/components/task-inspector.js.map +1 -1
  225. package/dist/modes/interactive/components/task-list.d.ts +9 -3
  226. package/dist/modes/interactive/components/task-list.d.ts.map +1 -1
  227. package/dist/modes/interactive/components/task-list.js +26 -2
  228. package/dist/modes/interactive/components/task-list.js.map +1 -1
  229. package/dist/modes/interactive/interactive-agent-events.js +3 -9
  230. package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
  231. package/dist/modes/interactive/interactive-auth-login.js +1 -1
  232. package/dist/modes/interactive/interactive-auth-login.js.map +1 -1
  233. package/dist/modes/interactive/interactive-render-chat.js +3 -9
  234. package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
  235. package/dist/modes/interactive/interactive-resource-rendering.js +6 -9
  236. package/dist/modes/interactive/interactive-resource-rendering.js.map +1 -1
  237. package/dist/modes/interactive/interactive-selectors.js +1 -0
  238. package/dist/modes/interactive/interactive-selectors.js.map +1 -1
  239. package/dist/modes/interactive/interactive-slash-commands.js +2 -4
  240. package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
  241. package/dist/modes/interactive-engine/isolated-runtime.d.ts +1 -0
  242. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  243. package/dist/modes/interactive-engine/isolated-runtime.js +5 -0
  244. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  245. package/dist/utils/clipboard-image.d.ts.map +1 -1
  246. package/dist/utils/clipboard-image.js +14 -17
  247. package/dist/utils/clipboard-image.js.map +1 -1
  248. package/docs/background-tasks.md +1 -0
  249. package/docs/computer-use.md +2 -2
  250. package/docs/custom-provider/registration.md +1 -1
  251. package/docs/custom-provider.md +43 -1
  252. package/docs/extensions/authoring.md +22 -3
  253. package/docs/extensions/events.md +18 -0
  254. package/docs/extensions/examples.md +1 -0
  255. package/docs/models/evals.md +31 -79
  256. package/docs/models/model-selection.md +5 -1
  257. package/docs/packages/authoring.md +3 -1
  258. package/docs/providers.md +7 -11
  259. package/docs/sdk/reference.md +18 -42
  260. package/docs/sdk/structured-decisions.md +44 -89
  261. package/docs/sdk.md +1 -1
  262. package/docs/settings.md +6 -6
  263. package/docs/subagents/reference.md +7 -8
  264. package/docs/usage.md +13 -0
  265. package/docs/workflows/api-reference.md +38 -35
  266. package/docs/workflows/authoring.md +113 -1
  267. package/docs/workflows/builtins.md +1 -1
  268. package/docs/workflows/operations.md +51 -29
  269. package/docs/workflows/verification.md +13 -0
  270. package/examples/extensions/README.md +1 -0
  271. package/examples/extensions/debug-provider.ts +90 -0
  272. package/examples/extensions/structured-output.ts +6 -0
  273. package/npm-shrinkwrap.json +32 -32
  274. package/package.json +3 -3
  275. package/dist/builtin/workflows/src/durable/dependency-doctor-types.d.ts +0 -42
  276. package/dist/core/decision-provider.d.ts +0 -4
  277. package/dist/core/decision-provider.d.ts.map +0 -1
  278. package/dist/core/decision-provider.js +0 -12
  279. package/dist/core/decision-provider.js.map +0 -1
  280. package/dist/core/structured-output/jev-client.d.ts +0 -25
  281. package/dist/core/structured-output/jev-client.d.ts.map +0 -1
  282. package/dist/core/structured-output/jev-client.js +0 -174
  283. package/dist/core/structured-output/jev-client.js.map +0 -1
  284. package/dist/core/structured-output/jev.d.ts +0 -5
  285. package/dist/core/structured-output/jev.d.ts.map +0 -1
  286. package/dist/core/structured-output/jev.js +0 -249
  287. package/dist/core/structured-output/jev.js.map +0 -1
@@ -154,7 +154,7 @@ const builtinsOnly = await ModelRuntime.create({ modelsPath: null });
154
154
 
155
155
  ### Structured decisions
156
156
 
157
- Use `inferStructuredOutput()` with an explicit inference model for a single schema-validated semantic decision without starting an agent session or executing tools. It supports ordinary configured models and the decision-only Jev integrations listed by `getStructuredOutputProviders()` (direct TypeSafe, OpenRouter, Vercel AI Gateway, OpenCode Zen), and never reads `routerModel`. Gateway Jev reuses that gateway's existing authentication. The separate `inferRouterDecision()` entrypoint shares `routerModel` resolution for workflow-stage and subagent `model: "auto"` selection only. Neither API changes the selected chat model or the `structured_output` tool. See [Structured decisions](/sdk/structured-decisions) for state preparation, examples, provider limits and failure handling.
157
+ Use `generateStructuredOutput()` for one schema-validated semantic decision without starting an agent session. Pass optional exact `model` and `fallbackModels` IDs, `currentModel`, `modelRegistry`, `instructions`, `state`, and `schema`. Omit `model` to start with the current chat model; the current chat model is also the terminal fallback. Atomic resolves each ID through the supplied registry: a chat model uses chat inference, and a registered classifier uses the generic classify operation. A catalog entry does not prove that the provider can serve the request. Classifiers run only when the schema is a finite Choice and are otherwise skipped. General calls derive choice questions from that schema and never read `routerModel`. Workflow-stage and subagent `model: "auto"` selection use `routerModel` internally; no separate routing-decision API is exported. See [Structured decisions](/sdk/structured-decisions).
158
158
 
159
159
  ### System Prompt
160
160
 
@@ -306,69 +306,49 @@ Normal sessions also expose `kill({ id: taskId })` for their owned bash and Powe
306
306
 
307
307
  #### Structured output final results
308
308
 
309
- `structured_output` is not registered in normal agent sessions by default. Add it only when a caller needs a machine-readable final-answer contract by registering the exported factory as a custom tool:
309
+ `structured_output` is not registered in normal agent sessions by default. Register the factory when a caller needs a schema-validated decision inferred by a selected model:
310
310
 
311
311
  ```typescript
312
- import { Type, type Static } from "typebox";
313
- import {
314
- createAgentSession,
315
- createStructuredOutputTool,
316
- type StructuredOutputCapture,
317
- } from "@bastani/atomic";
312
+ import { Type } from "typebox";
313
+ import { createAgentSession, createStructuredOutputTool } from "@bastani/atomic";
318
314
 
319
315
  const DecisionSchema = Type.Object({
320
- approved: Type.Boolean(),
321
- findings: Type.Array(Type.String()),
316
+ category: Type.Union([Type.Literal("question"), Type.Literal("statement")]),
322
317
  }, { additionalProperties: false });
323
318
 
324
- type Decision = Static<typeof DecisionSchema>;
325
- const capture: StructuredOutputCapture<Decision> = {
326
- called: false,
327
- value: undefined,
328
- };
329
-
330
- const structuredOutput = createStructuredOutputTool({
331
- schema: DecisionSchema,
332
- capture,
333
- });
319
+ const structuredOutput = createStructuredOutputTool({ schema: DecisionSchema });
334
320
 
335
321
  const { session } = await createAgentSession({
336
322
  customTools: [structuredOutput],
323
+ tools: ["structured_output"],
337
324
  });
338
325
  ```
339
326
 
340
- The tool parameters are exactly the supplied schema. With `DecisionSchema`, the model calls `structured_output({ approved, findings })`. The factory also accepts array and primitive schemas when the target provider/tool runtime supports them; the captured value is whatever JSON value matches the schema.
341
-
342
- A successful call:
327
+ The calling model does not supply the decision fields. It calls `structured_output` with:
343
328
 
344
- - Stores the parameters in `capture.value`.
345
- - Returns pretty-printed JSON tool-result text for text print mode and keeps the flat value in tool `details`.
346
- - Writes the same JSON to `output.outputPath` when an `output` file sink is configured.
347
- - Sets `terminate: true`, preventing an extra follow-up assistant turn.
329
+ - `instructions`: the judgment to make.
330
+ - `state`: a nonempty named object containing the task and relevant context. Do not put secrets here.
331
+ - `model`: optional exact `provider/model` ID of a chat model or a registered classifier. Omit it to use the current stage or session chat model.
332
+ - `fallbackModels`: optional ordered exact IDs tried after the primary.
348
333
 
349
- Atomic relies on the tool schema, not extra structured-output parsing or sidecar validation. Structured-output tool definitions opt out of oversized-result persistence.
334
+ The tool infers the result through the session model registry. A successful call returns the schema-validated value as pretty-printed JSON, stores that value in `details`, and sets `terminate: true`. It does not capture the calling model's arguments as the decision. A classifier is used only when the registered schema is a finite Choice; otherwise that candidate is skipped and the next fallback, then the current chat model, is tried. A classifier failure such as missing credentials, an unavailable provider, an unsupported classify operation, a refusal, or a malformed answer advances the same chain. A chat provider refusal advances immediately when reported as an error; plain text without a result gets up to three repairs before advancing. Cancellation stops the call. Saved `/login` credentials are used through the session model registry; a listed model does not prove live access.
350
335
 
351
- Custom tool names are supported, and the prompt metadata follows the configured name. If you use a custom name such as `final_decision`, include that name in any explicit `tools` allowlist. If the standard `structured_output` name is required, register the factory with its default name:
336
+ A custom tool name still works. Include that name in any explicit `tools` allowlist:
352
337
 
353
338
  ```typescript
354
339
  const finalDecision = createStructuredOutputTool({
355
340
  name: "final_decision",
356
341
  schema: DecisionSchema,
357
- capture,
358
342
  });
359
- // The model is prompted to call final_decision exactly once, not structured_output.
360
343
 
361
344
  await createAgentSession({
362
345
  customTools: [finalDecision],
363
- tools: ["final_decision"], // only this tool is enabled
364
- });
365
-
366
- await createAgentSession({
367
- customTools: [createStructuredOutputTool({ schema: DecisionSchema, capture })],
368
- // Registers the standard structured_output tool for this session only.
346
+ tools: ["final_decision"],
369
347
  });
370
348
  ```
371
349
 
350
+ Custom tool names are supported, and the prompt metadata follows the configured name. The examples above use `final_decision` and the default `structured_output` name. Include the name you register in any explicit `tools` allowlist.
351
+
372
352
  > See [examples/sdk/05-tools.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/sdk/05-tools.ts)
373
353
 
374
354
  ### Extensions
@@ -845,11 +825,7 @@ defineTool
845
825
  STRUCTURED_OUTPUT_TOOL_NAME
846
826
  createStructuredOutputTool
847
827
  createStructuredOutputCapture
848
- inferStructuredOutput
849
- inferRouterDecision
850
- resolveRouterModel
851
- getStructuredOutputProviders
852
- JEV_STRUCTURED_OUTPUT_PROVIDER
828
+ generateStructuredOutput
853
829
  getAgentDir
854
830
  getPackageDir
855
831
  getReadmePath
@@ -5,135 +5,90 @@ description: Make a schema-validated structured decision without starting an age
5
5
 
6
6
  # Structured decisions
7
7
 
8
- Use `inferStructuredOutput()` from `@bastani/atomic` when an SDK integration needs one semantic decision before it performs an action. It returns a schema-validated value, the requested and responding model identities, and input/output token counts. It does not execute tools, start a session, or authorize an action.
8
+ Use `generateStructuredOutput()` from `@bastani/atomic`, or the `structured_output` tool, when an integration needs one schema-validated semantic decision. Both use the same model contract. Neither starts a child agent, executes the caller's other tools, or authorizes an action. Neither reads `routerModel` or changes the selected chat model.
9
9
 
10
- `inferStructuredOutput()` takes an explicit inference model and never reads `routerModel`. The `structured_output` tool continues to use its session's model. Neither API changes the selected chat model. [Workflow-stage](/workflows/operations#automatic-stage-models) and [subagent `model: "auto"`](/subagents/reference#automatic-model-selection) selection use the shared router entrypoint below.
10
+ Automatic workflow-stage and subagent `model: "auto"` selection uses `routerModel` separately; it does not change calls to `generateStructuredOutput()`. See [Select the router](#select-the-router).
11
11
 
12
12
  ## Select the inference model
13
13
 
14
- For a general structured-output call, pass `model: { kind: "chat", fullId, model }` with a concrete model from the current registry, or `model: { kind: "jev", fullId: "typesafe-ai/jev-latest" }`. For Jev through a gateway, use any `fullId` from `getStructuredOutputProviders()`: `openrouter/~typesafe/jev-latest`, `vercel-ai-gateway/typesafe-ai/jev`, `opencode/jev-1.13`, or `opencode/jev-1.13-free`. Setting `routerModel` or exporting a TypeSafe key does not change this explicit selection.
14
+ Pass an optional exact `provider/model` string, not a model object and not `auto`:
15
15
 
16
- `inferRouterDecision()` is the shared entrypoint for automatic subagent/workflow-stage model selection. Only this entrypoint consults `routerModel` in [settings.json](/settings#routermodel). It takes `settings`, `modelRegistry` and the invocation-time `currentModel` instead of an explicit inference `model`. Resolution is:
16
+ - `model` is the primary. It may be a chat language model or a classifier registered in the current model registry. `typesafe/jev-latest` is one example classifier, not a separate request type.
17
+ - `fallbackModels` is an ordered list of the same kind of exact IDs.
18
+ - Omit `model` to use the current stage or chat model as the primary.
19
+ - After the primary and every explicit fallback, Atomic tries the current chat model if it has not already been tried.
17
20
 
18
- 1. A nonempty explicit, exact `routerModel` value.
19
- 2. Otherwise `typesafe-ai/jev-latest` when Jev credentials are configured through `/login typesafe-ai` or `TYPESAFE_API_KEY`.
20
- 3. Otherwise the chat model supplied as `currentModel` at invocation time.
21
+ Image-generation models, model patterns, reasoning suffixes, and surrounding whitespace are rejected. Atomic validates every model ID before sending the first request, so a mistyped fallback fails the call even if the primary model would have succeeded. A classifier is never an execution `auto` candidate. A catalog entry does not prove that the provider can classify, that credentials work, or that quota remains. Setting `routerModel` does not change this selection.
21
22
 
22
- An invalid explicit router selection fails instead of falling back. `auto`, model patterns, reasoning suffixes, and surrounding whitespace are not supported. Ordinary models must exist in the current configured catalog; their usual provider authentication applies. Catalog presence and an environment key do not prove live access, quota, or entitlement. The resolver never changes the chat model, the `structured_output` tool's model or saved defaults.
23
+ A classifier can answer a finite Choice. Literal unions, enums, booleans, and flat objects whose required fields all use those types are Choice-compatible. Free-form text, unconstrained numbers, arrays, optional fields, and nested objects are not. Atomic compiles compatible schemas into generic choice questions and skips an incompatible classifier, recording the skip. A request whose entire chain is incompatible fails without inventing a decoder.
23
24
 
24
- Extension tools can read the owning session's current routing setting with `ctx.getRouterModel()`. Pass `settings: { getRouterModel: () => ctx.getRouterModel() }`, `modelRegistry: ctx.modelRegistry` and `currentModel: ctx.model` to `inferRouterDecision()`. This preserves in-memory settings and project-trust behavior instead of loading a separate settings instance.
25
-
26
- Pass the full `ModelRegistry` to use saved Jev credentials with either decision API. Its provider-auth methods preserve normal credential resolution and logout behavior. Minimal custom adapters that omit `getProviderAuth` and `getProviderAuthStatus` retain environment-only Jev support. Never copy a resolved key into decision state.
27
-
28
- OpenRouter Jev reuses the registry's existing OpenRouter sign-in or saved API key and normal `OPENROUTER_API_KEY` fallback. It never uses TypeSafe credentials. Minimal adapters use `OPENROUTER_API_KEY` for this selection. The Atomic ID includes `openrouter/`; the wire model is only `~typesafe/jev-latest`, sent to `https://openrouter.ai/api/alpha/decisions`. Both Jev selections accept the same Choice questions and return the same structured result. OpenRouter is explicit-only and does not change automatic selection precedence.
29
-
30
- Vercel AI Gateway (`https://ai-gateway.vercel.sh/typesafe/v1/systemone`, wire model `typesafe-ai/jev`) and OpenCode Zen (`https://opencode.ai/zen/v1/systemone`, wire models `jev-1.13` and `jev-1.13-free`) follow the same rule with `AI_GATEWAY_API_KEY` and `OPENCODE_API_KEY` or that provider's `/login`. Their model IDs, `contextWindow`, and `cost` fields are read from the models.dev decision catalog bundled with `@bastani/pi-ai` (`getDecisionModels()`), so a gateway that drops or renames its Jev listing disappears from `getStructuredOutputProviders()` at the next catalog regeneration. Gateway Jev is explicit-only.
31
-
32
- ### Router repair attempts
33
-
34
- By default, `inferRouterDecision()` gives each provider an initial attempt plus **up to three corrective retries** when an answer is malformed or fails the decision schema. When a chat fallback exists, a failed Jev attempt switches to chat immediately instead of repairing on Jev; the chat fallback then gets at most four attempts, without a structured-decision time limit. A valid answer stops retries immediately; a valid `none` is not retried. Repairs may increase latency and provider usage, but never start a workflow or child before final validation.
35
-
36
- Separately from output repairs, transient provider failures — connection errors and HTTP 408, 429 and 5xx — are retried up to three times with exponential backoff for both Jev and chat decision requests. Every request honors cancellation; an aborted request is never retried. Both decision APIs accept a `retry` policy (`{ enabled, maxRetries, baseDelayMs }`) to change this; `inferRouterDecision()` also reads `settings.retry` when available.
37
-
38
- Input/configuration errors, cancellation, and stale-catalog rejection are not repaired. Generic `inferStructuredOutput()` gains the same transient-failure retries but no output repairs or provider fallback.
39
-
40
- Any Jev failure switches to the current chat model when the invocation has a concrete current chat model — exhausted output repairs, HTTP and connection errors after their transient retries, missing or unresolvable credentials, response-size violations, and local context-budget rejection. This applies to explicit Jev `routerModel` selections as well as automatic ones. Context-budget failures switch before sending an oversized request; HTTP errors such as `max_tokens_exceeded` switch without repeating an unchanged request. A warning reports the safe failure reason and fallback model. The fallback gets its own initial attempt plus three corrective retries, using the original state, schema and constraints. The result includes `fallback: { from, to, reason }` and identifies the chat model in `model`. This can send routing context to your chat provider and incur its normal charges. Cancellation never triggers fallback.
41
-
42
- For [workflow-stage](/workflows/operations#automatic-stage-models) and [subagent](/subagents/reference#automatic-model-selection) `model: "auto"`, a complete routing-inference failure — Jev and the chat structured-output fallback both — runs the stage or child on the current chat model with a recorded warning instead of failing, provided that model is available and satisfies every routing constraint. If ranking a fallback model fails after the primary was chosen, the primary is kept. Validation, eligibility, credential-screening failures and cancellation still fail as before.
43
-
44
- ## Prepare a decision
45
-
46
- Supply both the ordinary result schema and Jev Choice questions so either provider path can serve the same request. Instructions describe the judgment. Named `state` fields contain the actual task, relevant conversation, explicit constraints and reference text. Paths and URLs may identify a source, but do not replace its content. Exclude secrets from state and criteria.
47
-
48
- Put candidate-specific descriptions and contracts in Choice criteria rather than repeating a complete catalog in state. Both chat and Jev receive the questions and criteria; Jev tournament batches contain only the options being compared. Keep shared state relevant to every comparison. Do not truncate requirements to fit.
25
+ Pass the session `modelRegistry`. Classifier credentials come from that registry's normal provider login, such as `/login typesafe` or `TYPESAFE_API_KEY` for TypeSafe Jev. Do not copy a resolved key into `state`.
49
26
 
50
27
  ```typescript
51
28
  import { Type } from "typebox";
52
- import {
53
- inferStructuredOutput,
54
- ModelRegistry,
55
- ModelRuntime,
56
- type StructuredOutputModel,
57
- } from "@bastani/atomic";
29
+ import { generateStructuredOutput, ModelRegistry, ModelRuntime } from "@bastani/atomic";
58
30
 
59
31
  const modelRuntime = await ModelRuntime.create();
60
32
  const modelRegistry = new ModelRegistry(modelRuntime);
61
- const model = modelRegistry.getAvailable()[0];
62
- if (!model) throw new Error("Choose a configured chat model before making this request.");
63
- const inferenceModel: StructuredOutputModel = {
64
- kind: "chat", fullId: `${model.provider}/${model.id}`, model,
65
- };
33
+ const currentModel = modelRegistry.getAvailable()[0];
34
+ if (!currentModel) throw new Error("Choose a configured chat model before making this request.");
66
35
 
67
36
  const schema = Type.Object(
68
- { category: Type.Union([Type.Literal("question"), Type.Literal("none")]) },
37
+ { category: Type.Union([Type.Literal("question"), Type.Literal("statement")]) },
69
38
  { additionalProperties: false },
70
39
  );
71
- const result = await inferStructuredOutput({
72
- model: inferenceModel,
40
+ const result = await generateStructuredOutput({
41
+ model: "typesafe/jev-latest",
42
+ fallbackModels: [`${currentModel.provider}/${currentModel.id}`],
43
+ currentModel,
73
44
  modelRegistry,
74
45
  schema,
75
- instructions: "Classify whether the task asks a question. Use none for other tasks.",
76
- state: {
77
- task: "What does the router setting mean?",
78
- constraints: { permittedAction: "classify only" },
79
- reference: { text: "A question requests an explanation or information." },
80
- candidates: ["question", "none"],
81
- },
82
- jev: {
83
- questions: {
84
- category: {
85
- instructions: "Does the task request information or an explanation?",
86
- criteria: {
87
- question: "Requests information or an explanation",
88
- none: "Does not request information or an explanation",
89
- },
90
- },
91
- },
92
- decode: (choices) => ({
93
- category: choices.category === "question" ? "question" : "none",
94
- } as const),
95
- },
96
- maxTokens: 4096,
46
+ instructions: "Classify whether the message asks a question or makes a statement.",
47
+ state: { message: "What time does the train leave?" },
97
48
  });
98
- console.log(result.value.category);
49
+ console.log(result.value.category, result.model);
99
50
  ```
100
51
 
101
- Keep `decode` synchronous and side-effect-free. It maps validated Choice keys to exact canonical values. Do not perform inference, authorization, file writes, or launches there. Validate current policy and candidate availability again before any later action. A valid shape is not proof that the judgment is correct.
52
+ The returned `value` is the schema-validated decision, not the request arguments. `model` names the candidate that produced it. `modelAttempts` records skips and failed candidates when a chain was used. A classifier result does not include token usage, so `usage` on a classifier-produced decision is not a classifier bill. Chat usage is reported only when a chat candidate supplies the accepted result. A valid shape is not proof that the judgment is correct. Validate current policy again before any later action.
102
53
 
103
- For runtime catalogs, build schema, state and Choice candidates from the same snapshot. Use one Choice per coherent judgment. Encode a model and its supported reasoning effort as one valid-pair candidate, never independent choices. Keep fixed numeric limits in code and copy them in `decode`; a singleton question is unnecessary for a value already determined. Preserve zero and omitted fields distinctly. Include a no-match outcome when applicable and handle name collisions explicitly.
54
+ The `structured_output` tool takes the same decision inputs from the calling model: required `instructions` and nonempty named `state`, plus optional `model` and `fallbackModels`. The registered schema is fixed by `createStructuredOutputTool({ schema })`. The tool resolves those IDs through the session registry and returns the inferred value. Omitting `model` uses the current stage or session chat model. See [Structured output final results](/sdk/reference#structured-output-final-results).
104
55
 
105
- ## Provider behavior and limits
56
+ ## Select the router
106
57
 
107
- Ordinary models receive one `structured_output` result tool with the supplied schema. Atomic uses provider-aware serialization, requests strict sampling where supported, and validates the returned arguments without coercing values or removing extra fields. Use `additionalProperties: false` for closed objects. Providers without strict sampling must still return valid arguments. `toolChoice: "auto"` also supports models that reject forced tool use. A prose-only response, extra tool call, truncated response or invalid result fails a generic `inferStructuredOutput()` call without a repair prompt; router calls can use the bounded repairs described above.
58
+ For workflow stages and subagents with `model: "auto"`, `routerModel` selects the decision provider: an explicit exact registered chat or classifier ID uses that model, while an unset or `auto` value uses the current chat model. Saved classifier credentials do not change this selection. An invalid explicit router selection fails instead of falling back. Set it through [/settings](/settings#routermodel); extensions can read the current value with `ctx.getRouterModel()`.
108
59
 
109
- Ordinary requests use HTTP/SSE rather than WebSocket transport fallback, and disable configured Anthropic server-side fallbacks for this request only. Transient-failure retries are owned by the decision layer: each provider request sets `maxRetries: 0`, and custom provider implementations must honor these options and must not introduce their own inference retries or fallback requests.
60
+ Chat routing gets an initial attempt plus up to three corrective retries for malformed or schema-invalid output. A failed explicit classifier routing attempt switches to the current chat model immediately when one exists, including missing credentials, an unsupported classify operation, a provider size or context rejection, and a refusal. Cancellation does not fall back. The result includes `fallback: { from, to, reason }` when that hop is used. Transient provider retries follow the selected provider's operation and the request's retry settings. General `generateStructuredOutput()` advances its own `fallbackModels` chain; it does not read `routerModel`.
110
61
 
111
- [TypeSafe Jev](/providers#typesafe-jev) accepts shared state and typed questions instead of JSON-schema generation. Atomic packs independent questions together. Both decision APIs retry transient provider failures up to three times; router calls can additionally repair malformed or schema-invalid answers within their attempt allowance. Question IDs are correlation keys, not instructions seen by Jev, so put complete semantics in each question's `instructions`. Describe the speculative premise of a conditional question and consume its answer only when that premise applies.
62
+ For [workflow-stage](/workflows/operations#automatic-stage-models) and [subagent](/subagents/reference#automatic-model-selection) `model: "auto"`, a complete routing-inference failure runs the stage or child on the current chat model with a recorded warning instead of failing, provided that model is available and satisfies every routing constraint.
112
63
 
113
- Choices with up to 255 options keep a single comparison when they fit the context budget. Larger or more verbose choices use a bounded tournament: every original option participates in stable batches of at most 255; each batch retains its top three by validated probabilities, with ties resolved by original order. Further shrinking rounds precede a final shared comparison. Probabilities are never compared across batches. Multiple named questions can mix small choices and tournaments; `decode` receives original option keys only after all judgments succeed. Empty choices fail; singletons still go to the provider when they fit.
64
+ ## Prepare a decision
65
+
66
+ Instructions describe the judgment. Named `state` fields contain the actual task, relevant conversation, explicit constraints, and reference text. Paths and URLs may identify a source, but do not replace its content. Exclude secrets from state and instructions.
114
67
 
115
- For an abstention option that must remain available, set the question's optional `retainForFinal` to one original option key. It participates normally and is also retained for the final comparison if eliminated; it does not replace any batch's top three. Workflow routing uses this for `none`.
68
+ A general structured-output request supplies `instructions`, `state`, and `schema`. Atomic derives choice questions from a compatible schema and skips a classifier for other schemas. Keep fixed numeric limits in code. Include a no-match outcome in the schema when abstention is valid.
116
69
 
117
- Overflow requires multiple HTTP requests and can increase latency and billed input tokens because each request repeats the unchanged state. Returned usage sums all successful requests; `responseModel` identifies the last response. Grouping can change the winner: this tournament does not guarantee the result of an unlimited flat Choice or a globally optimal selection.
70
+ Automatic routing builds its own finite Choice questions from eligible execution models. Call `generateStructuredOutput()` directly for other decisions; it derives questions from your result schema instead of reading `routerModel`.
118
71
 
119
- Jev documents limits of 32k tokens for state plus the longest question, and 64k for state plus all questions. Without an exact Jev tokenizer, Atomic uses conservative UTF-8 byte budgets of 24,000 and 48,000 respectively, reserving further framing headroom when packing. These checks include compiled instructions and criteria, apply even below 255 options, and may reject inputs the provider would accept.
72
+ ## Provider behavior and limits
120
73
 
121
- The structured-decision transport never trims supplied state or sends an indivisible comparison that exceeds its local budget. Router calls use that state with the current chat model, including for pinned Jev; general structured-output calls fail. A provider `max_tokens_exceeded` response still uses the same routing fallback policy without repeating the rejected request. Supply concise context or select a chat model with enough capacity when needed.
74
+ Chat candidates receive one internal result tool whose parameters are the registered schema. Atomic uses provider-aware serialization, requests strict sampling where supported, and validates the returned arguments without coercing values or removing extra fields. Use `additionalProperties: false` for closed objects. A prose-only response, extra tool call, truncated response, or invalid result fails that candidate and advances the chain. The public `structured_output` tool is separate: its parameters are `instructions`, `state`, and optional model selectors, and its result is the inferred value.
122
75
 
123
- Automatic subagent and workflow-stage model selection prepares a [bounded task excerpt](/subagents/reference#automatic-model-selection) before calling this API. That excerpt preserves protected spans and does not replace the execution prompt. Direct SDK decision calls do not apply this task-excerpt policy.
76
+ Chat decisions use HTTP/SSE rather than WebSocket transport fallback and disable configured Anthropic server-side fallbacks for this request only. The chat decision layer retries transient failures according to the request's retry settings. Classifier calls use the registered provider's `classify` operation and forward the retry limit and cancellation signal; provider implementations own their transport retries.
124
77
 
125
- Jev response bodies are limited to 1 MiB per request. Atomic validates that every question receives a known Choice option; reported model, usage, probabilities and confidence are advisory and never reject an otherwise valid decision.
78
+ A registered classifier receives shared state and choice questions through the generic classify operation. [TypeSafe Jev](/providers#typesafe-jev) is one such classifier. Router classification is one classify request. A provider that rejects the request size or context fails that candidate; routing then uses the current chat model when one exists.
79
+
80
+ The structured-decision path never trims supplied state. A general structured-output call skips an incompatible classifier candidate and continues with the next fallback. A provider size rejection advances the same way without repeating the rejected request. Supply concise context or select a chat model with enough capacity when needed.
81
+
82
+ Automatic subagent and workflow-stage model selection uses a [bounded task excerpt](/subagents/reference#automatic-model-selection) for its routing decision. That excerpt preserves protected spans and does not replace the execution prompt. Direct SDK calls do not apply this task-excerpt policy.
83
+
84
+ Classifier response bodies are limited by the provider operation. Atomic validates that every question receives a known Choice option. The classify result does not report token usage. Reported model, probabilities, and confidence are advisory and never reject an otherwise valid decision.
126
85
 
127
86
  ## Cancellation and failures
128
87
 
129
- Structured decisions have no built-in wall-clock timeout. Slow authentication, inference, repairs, chat fallback and tournament rounds can finish without the former 30-second cutoff. Pass an `AbortSignal` to cancel; SDK callers that need their own deadline can supply `signal: AbortSignal.timeout(milliseconds)`. Cancellation rejects the whole call immediately, even if a provider ignores its signal. A failed batch yields no partial decision, and late responses cannot invoke the Jev mapper. Ordinary output is still bounded by `maxTokens`, default 4096.
88
+ Structured decisions have no built-in wall-clock timeout. Slow authentication, inference, repairs, and chat fallback can finish without the former 30-second cutoff. Pass an `AbortSignal` to cancel; SDK callers that need their own deadline can supply `signal: AbortSignal.timeout(milliseconds)`. Cancellation rejects the whole call immediately, even if a provider ignores its signal. Ordinary output is still bounded by `maxTokens`, default 4096.
130
89
 
131
90
  The `timeoutMs` request option and `DEFAULT_STRUCTURED_OUTPUT_TIMEOUT_MS` export have been removed. Remove these from existing integrations and use `signal` for caller-owned cancellation. Provider transport, credential-preparation and enclosing tool-request limits remain independent; removing the decision timeout does not disable them.
132
91
 
133
92
  No result is returned for missing state, invalid configuration, unrepaired malformed output or an unrecovered provider failure. Keep action admission after the awaited result and check cancellation again at that boundary. Neither API runs recursive agents or provider probes.
134
93
 
135
- Jev errors report the SDK error class, HTTP status, recognized machine error codes such as `max_tokens_exceeded`, and a validated TypeSafe request ID when available. Raw error bodies, arbitrary messages and credentials are not exposed. Transient HTTP failures are retried up to three times before an error is reported; there is no body logging, including when `TYPESAFE_LOG_LEVEL` is set.
136
-
137
- For direct Jev, HTTP 401 means check `/login typesafe-ai` or `TYPESAFE_API_KEY`; for OpenRouter Jev, check `/login openrouter` or `OPENROUTER_API_KEY`. HTTP 400 or 422 means check the state/question contract or reported context limit; 403 means access denied, 404 means check the endpoint/model, and a reported 429 or 529 means the provider stayed rate limited or overloaded through the automatic retries.
138
-
139
- Malformed Jev response errors include a static diagnostic code, without response values or routing context: `choice_key` means an answer named no known Choice option (or was missing), and a non-JSON body reports malformed JSON. Include the code when reporting a failure. Router calls may repair these errors before returning a final failure; generic calls fail immediately. No decision naming an unknown option is accepted.
94
+ Provider errors report a static reason without raw response bodies or credentials. A failed classifier request, including a refusal or an unrecognized or missing Choice answer, advances to the next configured model or current chat model. Chat provider errors also advance, including explicit refusals. Ordinary text without a valid result gets up to three repairs before advancing; Atomic does not inspect the wording to guess whether it is a refusal. Cancellation stops the chain.
package/docs/sdk.md CHANGED
@@ -111,7 +111,7 @@ When upgrading an existing host:
111
111
 
112
112
  - Remove manual registration of Atomic's shipped builtin extensions. They and their resources are included by default. Use `builtins` to disable packages; use `tools`/`excludedTools` to control tool access. An empty tool allowlist also excludes Intercom.
113
113
  - Supply all five `HostInput` methods (`confirm`, `select`, `input`, `editor`, `questionnaire`) through `extensionBindings.humanInput`. Preserve question text and option values, honor each request's abort signal, and return literal `true` only for explicit approval. No adapter is not consent: ordinary dialogs reject with `HumanInputUnavailable`, while required durable workflow gates remain pending. Do not translate cancellation into approval.
114
- - Treat a headless workflow launch as acceptance, not completion. Inspect its run ID/status. After reconnecting, resume that existing run and bind the new adapter with `session.bindExtensions({ humanInput })`; do not start a second run to answer an outstanding question. Durable resume requires working workflow persistence; use `workflowDependency("doctor")` from `@bastani/atomic/workflows` to troubleshoot it.
114
+ - Treat a headless workflow launch as acceptance, not completion. Inspect its run ID/status. After reconnecting, resume that existing run and bind the new adapter with `session.bindExtensions({ humanInput })`; do not start a second run to answer an outstanding question. Durable resume requires working workflow persistence; inspect the original run's status and correct the reported database problem before retrying.
115
115
  - Always `await session.dispose()` in `finally`, including on failure. Disposal is asynchronous and can reject with `ShutdownFailed` after attempting all cleanup; do not hide that rejection or call `process.exit()` to force a successful shutdown. Each session owns its own work, even when services are shared.
116
116
 
117
117
  MCP servers and web providers still require their normal configuration and credentials. Importing the SDK does not connect them or take over standard input. Route host diagnostics through `extensionBindings.onDiagnostic`; a missing provider or extractor is an error, not an empty successful result.
package/docs/settings.md CHANGED
@@ -55,7 +55,7 @@ See [Herdr](/herdr) for state aggregation, reporter conflicts, privacy, and Herd
55
55
  |---------|------|---------|-------------|
56
56
  | `defaultProvider` | string | - | Startup provider, saved automatically when you switch models interactively |
57
57
  | `defaultModel` | string | - | Startup model ID, saved automatically when you switch models interactively |
58
- | `routerModel` | string | `""` | Inference model for workflow-stage and subagent `model: "auto"` selection only. Exact `provider/model`; empty selects Jev when its credentials are configured through `/login` or `TYPESAFE_API_KEY`, otherwise the current chat model. Does not change chat or `structured_output` tool inference. |
58
+ | `routerModel` | string | `""` | Inference model for workflow-stage and subagent `model: "auto"` selection only. An exact `provider/model` selects a registered chat or classifier model. `auto` and empty use the current chat model. Does not change chat or `structured_output` tool inference. |
59
59
  | `defaultThinkingLevel` | string | - | Startup thinking level, saved automatically on interactive model/thinking changes: `"off"`, `"minimal"`, `"low"`, `"medium"`, `"high"`, `"xhigh"`, `"max"`; clamped to the active model's supported levels |
60
60
  | `modelThinkingLevels` | object | - | Per-model startup thinking levels keyed by `"provider/modelId"`; updated automatically on interactive model/thinking changes, or configured from `/settings` → Default thinking level per model |
61
61
  | `hideThinkingBlock` | boolean | `false` | Hide thinking blocks in output |
@@ -79,17 +79,17 @@ Normal automatic selection of an available authenticated model remains enabled i
79
79
  { "routerModel": "" }
80
80
  ```
81
81
 
82
- Use `/settings` → **Router model** to change the effective selection. If the project already defines `routerModel`, the picker edits that project override; otherwise it saves the global default in `~/.atomic/agent/settings.json`. The picker identifies which scope it will save. Choose **Automatic** to save `""` in that scope, **typesafe-ai/jev-latest** for direct Jev, **openrouter/~typesafe/jev-latest** for Jev using your existing OpenRouter login or `OPENROUTER_API_KEY`, a Vercel AI Gateway or OpenCode Zen Jev ID (`vercel-ai-gateway/typesafe-ai/jev`, `opencode/jev-1.13`, `opencode/jev-1.13-free`) using that provider's credentials, or search available chat models by provider/model ID. The Jev options are offered here without appearing in `/model`. Run `/reload` or restart Atomic to apply the saved choice to an already-running isolated engine.
82
+ Use `/settings` → **Router model** to change the effective selection. If the project already defines `routerModel`, the picker edits that project override; otherwise it saves the global default in `~/.atomic/agent/settings.json`. The picker identifies which scope it will save. Choose **Automatic** to save `""` in that scope. `""` and `auto` both use the current chat model; saved classifier credentials do not change that choice. To pin a decision model, choose an exact ID from the current registry, such as `typesafe/jev-latest`, or a chat model by provider/model ID. A classifier is not a chat model and does not appear in `/model`. Run `/reload` or restart Atomic to apply the saved choice to an already-running isolated engine.
83
83
 
84
- A nonempty explicit model takes precedence over automatic Jev selection. Use an exact catalog ID without a reasoning suffix, or a decision-only ID returned by `getStructuredOutputProviders()`, such as `typesafe-ai/jev-latest`, `openrouter/~typesafe/jev-latest`, `vercel-ai-gateway/typesafe-ai/jev`, or `opencode/jev-1.13`. Replace old `typesafe-ai/jev` settings with `typesafe-ai/jev-latest`. An invalid explicit ID, `auto`, non-string value or surrounding whitespace fails the decision instead of silently changing providers. An explicit empty project value overrides a global selection and restores the configured-direct-Jev/current-chat precedence. OpenRouter, Vercel AI Gateway, and OpenCode Zen credentials alone do not select Jev automatically.
84
+ An explicit ID other than `auto` is resolved through the current model registry: a registered classifier first, otherwise a chat model. Gateway classifier IDs are not registered automatically; configure their classifier models and operations before selecting them. An invalid explicit ID, image-generation model, non-string value, or surrounding whitespace fails the decision instead of silently changing providers. An explicit empty project value overrides a global selection and restores the current chat model.
85
85
 
86
- Any Jev failure — HTTP or connection errors, missing credentials, context-budget rejection, or exhausted structured-output repairs — switches routing to your current chat model, whether Jev was selected automatically or pinned explicitly. Transient failures (connection errors, HTTP 408, 429 and 5xx) are first retried up to three times with backoff, and each provider gets an initial attempt plus three corrective retries for invalid output, using the same context. Routing has no built-in wall-clock deadline; cancel the request to stop waiting. Independent provider, credential-preparation and enclosing tool-request limits still apply. Atomic reports the fallback; it can incur chat-provider charges. Cancellation and local input-validation failures do not trigger fallback.
86
+ A failed explicit classifier routing attempt switches to the current chat model when one exists. That includes missing credentials, an unavailable classify operation, a provider size or context rejection, a refusal, and a malformed answer. Transient retries follow the provider operation and retry settings. Chat routing gets an initial attempt plus three corrective retries for invalid output, using the same context. Routing has no built-in wall-clock deadline; cancel the request to stop waiting. Independent provider, credential-preparation, and enclosing tool-request limits still apply. Atomic reports the fallback; it can incur chat-provider charges. Cancellation does not trigger fallback.
87
87
 
88
88
  Automatic subagent and workflow-stage model selection uses a bounded excerpt for long tasks, keeping the beginning, end, and `<keepContext>...</keepContext>` spans. Only the router's copy is shortened; execution receives the full task and hard model constraints stay enforced. Put essential model-selection requirements in protected spans. Unprotected middle text may be omitted, so excerpts can affect model choice. This does not truncate general structured decisions.
89
89
 
90
- If protected content or the remaining request still exceeds Jev's conservative context budget, routing switches to the current chat model, including for a pinned Jev selection. Large candidate sets are split into bounded comparisons without dropping candidates before evaluation.
90
+ If the selected classifier rejects the request for size or context, routing switches to the current chat model.
91
91
 
92
- This setting selects inference for [workflow-stage `model: "auto"`](/workflows/authoring#automatic-stage-model-selection) and [subagent `model: "auto"`](/subagents/reference#automatic-model-selection). It does not directly select the child execution model or change the selected chat model, `structured_output` tool, or general structured-output inference. The selected router provider receives the routing context, so choose a provider permitted to process that data. Authenticate direct Jev with `/login typesafe-ai` or `TYPESAFE_API_KEY`, and gateway Jev (OpenRouter, Vercel AI Gateway, OpenCode Zen) with that gateway's existing credentials. See [Structured decisions](/sdk/structured-decisions) and [TypeSafe Jev](/providers#typesafe-jev).
92
+ This setting selects inference for [workflow-stage `model: "auto"`](/workflows/authoring#automatic-stage-model-selection) and [subagent `model: "auto"`](/subagents/reference#automatic-model-selection). It does not directly select the child execution model or change the selected chat model, `structured_output` tool, or general structured-output inference. The decision provider may be any registered classifier or chat model, never an image-generation model; execution `auto` selects only chat language models, including multimodal-input chat. The selected router provider receives the routing context, so choose a provider permitted to process that data. Authenticate a pinned classifier with that provider's login, such as `/login typesafe` or `TYPESAFE_API_KEY` for TypeSafe Jev. See [Structured decisions](/sdk/structured-decisions) and [TypeSafe Jev](/providers#typesafe-jev).
93
93
 
94
94
  Remove secrets from routing tasks, inputs, and workflow descriptions/contracts before calling the tool. A routing-context credential error stops before inference or launch. Known configured credentials are screened even when they belong to a provider other than the router. Remove the credential from the supplied context or registered definition, reload a changed definition, then retry explicitly. The guard does not detect every possible secret.
95
95
 
@@ -25,23 +25,22 @@ Put requirements that should influence model selection in the task. Atomic suppl
25
25
 
26
26
  The agent's system prompt is not routing metadata. For a self-contained agent with no task, it remains the task fallback. The router weighs task-relevant evidence, cost, and latency rather than always choosing a benchmark winner or maximum effort. Benchmark measurement effort does not prescribe execution effort.
27
27
 
28
- Long tasks use a model-selection excerpt capped at 9,000 JSON-encoded UTF-8 bytes, retaining the beginning, end, and `<keepContext>...</keepContext>` spans in source order. Omissions are marked. Put essential selection requirements in protected spans, since unprotected middle text may be omitted. This applies to chat and Jev routers, not execution: the child still receives its complete task. If protected content cannot fit, Atomic keeps the original task and applies the usual router context-limit and fallback behavior. Hard `modelConstraints` are never truncated.
28
+ Long tasks use a model-selection excerpt capped at 9,000 JSON-encoded UTF-8 bytes, retaining the beginning, end, and `<keepContext>...</keepContext>` spans in source order. Omissions are marked. Put essential selection requirements in protected spans, since unprotected middle text may be omitted. This applies to the routing request, not execution: the child still receives its complete task. If protected content cannot fit, Atomic keeps the original task. A classifier that rejects that request falls back to the current chat model. Hard `modelConstraints` are never truncated.
29
29
 
30
30
  The shared [`routerModel`](/settings#routermodel) setting chooses the model making the decision, not the child model. Selection follows this order:
31
31
 
32
- 1. An explicit setting.
33
- 2. Jev, when credentials are saved through `/login typesafe-ai` or supplied by `TYPESAFE_API_KEY`.
34
- 3. The current chat model.
32
+ 1. An explicit registered classifier or chat model.
33
+ 2. The current chat model, including when `routerModel` is unset or `auto`.
35
34
 
36
- Neither routing nor child fallback changes the parent chat model or the `structured_output` tool.
35
+ Saved classifier credentials do not change this order. Neither routing nor child fallback changes the parent chat model or the `structured_output` tool.
37
36
 
38
- Routing has no built-in wall-clock deadline. Slow decisions can finish; cancel the request to stop waiting. Independent provider and credential-preparation limits still apply. By default, Jev and any current-chat fallback each get an initial attempt plus three corrective retries for malformed or schema-invalid answers. A valid answer stops repairs.
37
+ Routing has no built-in wall-clock deadline. Slow decisions can finish; cancel the request to stop waiting. Independent provider and credential-preparation limits still apply. Chat routing gets an initial attempt plus three corrective retries for malformed or schema-invalid answers. A classifier routing failure switches to the current chat model instead of repeating the classifier request. A valid answer stops repairs.
39
38
 
40
39
  The result records a primary `{ model, effort }` and up to two ordered `fallbacks`, each with its own model and effort. Atomic ranks three distinct eligible provider/model IDs, or all available IDs when fewer than three qualify. It selects each rank from the remaining models, excluding all efforts of earlier choices. A supported `"off"` is distinct from `null`, which means no configurable reasoning. The catalog reflects configured authentication, not proof of valid credentials, quota, or entitlement.
41
40
 
42
- The child does not start if no candidates are eligible, availability changes, or cancellation occurs. Oversized Jev context, a Jev HTTP or connection failure, missing Jev credentials, or exhausted output repairs triggers a reported switch to the current chat model, whether the router was selected automatically or pinned; transient provider failures are retried up to three times first. The chat model gets its own output-repair allowance. If routing inference fails completely — Jev and the chat structured-output fallback both — the child runs on the current chat model instead of failing, with a reported warning, but only when that model is available and satisfies every routing constraint (such as `allowedModels` and effort, cost, context and input limits). Otherwise the launch fails. Invalid inputs, conflicting constraints, cancellation and stale-catalog failures never trigger fallback. No partial decision can launch a child.
41
+ The child does not start if no candidates are eligible, availability changes, or cancellation occurs. A classifier provider failure, missing credentials, unsupported classify operation, size rejection, or malformed answer triggers a reported switch to the current chat model. Transient provider failures are retried up to three times first. The chat model gets its own output-repair allowance. If routing inference fails completely, the child runs on the current chat model instead of failing, with a reported warning, but only when that model is available and satisfies every routing constraint (such as `allowedModels` and effort, cost, context and input limits). Otherwise the launch fails. Invalid inputs, conflicting constraints, cancellation and stale-catalog failures never trigger fallback. No partial decision can launch a child.
43
42
 
44
- For large eligible sets, Jev uses tournament requests without a shared decision deadline. Every eligible pair enters a batch of at most 255; three per batch reach the finalist comparison. Verbose choices can split below 255 options to respect context budgets. Each batch contains only its candidate descriptions and repeats the same routing task or excerpt. Tournaments and repairs can increase latency and usage, and grouping can affect the winner. If the task or a comparison still cannot fit, routing uses the current chat model, including for a pinned Jev selection. See [structured decision limits](/sdk/structured-decisions#provider-behavior-and-limits).
43
+ Router classification is one classify request for the prepared choices. If the provider rejects the request size, routing uses the current chat model. See [structured decision limits](/sdk/structured-decisions#provider-behavior-and-limits).
45
44
 
46
45
  Execution tries the ranked models in order before remaining configured fallbacks and the current chat model, subject to normal retry rules and hard constraints. Duplicate model IDs are attempted only at their first position. Each ranked candidate retains its selected effort. Ranking can require up to three selection passes. Metadata preserves the ordered decision separately from the model and effort actually used; workflow checkpoints restore that order without rerouting.
47
46
 
package/docs/usage.md CHANGED
@@ -162,6 +162,19 @@ Append to the default prompt without replacing it with `APPEND_SYSTEM.md` in eit
162
162
 
163
163
  The default prompt asks the agent to write self-describing code and not add code comments unless you ask for them or the task calls for them. To get comments, request them in your prompt (for example "add JSDoc to the exported functions"), or make it a standing rule in a context file or `APPEND_SYSTEM.md` (for example "Document every exported function with a JSDoc block"). The default guideline explicitly defers to those instructions, so no other configuration is needed.
164
164
 
165
+ When a shell tool is available, the default prompt also asks the agent to record how each task ran in the commits, PRs, issues, and comments it writes, so later sessions can learn from your history:
166
+
167
+ ```text
168
+ Assistant-workflow: ralph (run 1a2b3c4d)
169
+ Assistant-duration: 42m converged, estimated 30m
170
+ Assistant-verification: vitest unit passed: npm run test:unit
171
+ Assistant-verification: herdr terminal E2E passed: /tasks lists running tasks first at 80x24
172
+ User-preference: keep PRs under 500 changed lines
173
+ Co-authored-by: Ada Lovelace <ada@example.com>
174
+ ```
175
+
176
+ Tasks done without a workflow record `Assistant-workflow: inline`. Each `Assistant-verification` line names one check that ran or was attempted, such as unit or E2E tests, agent-browser, Cua Driver, Herdr terminal automation, or the qlty CLI, with its outcome (`passed`, `failed`, or `unavailable`). Each preference carries a `Co-authored-by` line naming the user who expressed it. Before choosing between a workflow and inline work, deciding how to verify a change, or estimating how long a task will take, the agent looks up comparable records with your version control system and its hosting CLI (for example `git log` and `gh` on GitHub) and uses them as a guide alongside your request. For verification, it starts from the checks that proved similar changes and skips setups previously recorded as unavailable unless something has changed, while still running the project's required checks. It applies your own recorded preferences first and falls back to other contributors' preferences as repository conventions only when yours don't cover the situation, so you can always override a convention by stating your preference. To turn off any of these records, such as only preferences or all of them, say so in your request, a context file, or `APPEND_SYSTEM.md`.
177
+
165
178
  ## Exporting and Sharing Sessions
166
179
 
167
180
  Use `/export [file]` to write a session to HTML.