agency-lang 0.7.0 → 0.7.2

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 (182) hide show
  1. package/dist/lib/agents/agency-agent/agent.agency +169 -28
  2. package/dist/lib/agents/agency-agent/agent.js +579 -152
  3. package/dist/lib/agents/agency-agent/lib/attachments.js +2 -2
  4. package/dist/lib/agents/agency-agent/lib/config.agency +5 -0
  5. package/dist/lib/agents/agency-agent/lib/config.js +11 -0
  6. package/dist/lib/agents/agency-agent/lib/defaultPolicy.agency +106 -0
  7. package/dist/lib/agents/agency-agent/lib/defaultPolicy.js +764 -3
  8. package/dist/lib/agents/agency-agent/lib/modelFilters.js +1 -1
  9. package/dist/lib/agents/agency-agent/lib/resolution.js +4 -4
  10. package/dist/lib/agents/agency-agent/lib/search.js +3 -3
  11. package/dist/lib/agents/agency-agent/lib/settings.js +1 -1
  12. package/dist/lib/agents/agency-agent/lib/utils.js +1 -1
  13. package/dist/lib/agents/agency-agent/shared.agency +22 -0
  14. package/dist/lib/agents/agency-agent/shared.js +160 -3
  15. package/dist/lib/agents/agency-agent/subagents/code.js +1 -1
  16. package/dist/lib/agents/agency-agent/subagents/explorer.js +1 -1
  17. package/dist/lib/agents/agency-agent/subagents/oracle.js +1 -1
  18. package/dist/lib/agents/agency-agent/subagents/research.js +1 -1
  19. package/dist/lib/agents/agency-agent/subagents/review.js +4 -4
  20. package/dist/lib/agents/agency-agent/tests/agentTurn.js +1 -1
  21. package/dist/lib/agents/agency-agent/tests/attachments.js +1 -1
  22. package/dist/lib/agents/agency-agent/tests/attachmentsTurn.js +2 -2
  23. package/dist/lib/agents/agency-agent/tests/gitPolicy.js +3 -3
  24. package/dist/lib/agents/agency-agent/tests/oneShotRounds.agency +20 -0
  25. package/dist/lib/agents/agency-agent/tests/oneShotRounds.js +555 -0
  26. package/dist/lib/agents/agency-agent/tests/oneShotRounds.test.json +9 -0
  27. package/dist/lib/agents/review/agent.js +3 -3
  28. package/dist/lib/cli/doctor.d.ts +8 -0
  29. package/dist/lib/cli/doctor.js +21 -13
  30. package/dist/lib/cli/doctor.test.js +34 -0
  31. package/dist/lib/cli/help.js +1 -5
  32. package/dist/lib/cli/runBundledAgent.d.ts +17 -1
  33. package/dist/lib/cli/runBundledAgent.js +73 -2
  34. package/dist/lib/cli/runBundledAgent.test.d.ts +1 -0
  35. package/dist/lib/cli/runBundledAgent.test.js +96 -0
  36. package/dist/lib/config.d.ts +42 -33
  37. package/dist/lib/config.js +108 -6
  38. package/dist/lib/config.test.js +121 -2
  39. package/dist/lib/ir/prettyPrint.js +25 -4
  40. package/dist/lib/parseCache.js +8 -13
  41. package/dist/lib/parseCache.test.js +5 -8
  42. package/dist/lib/parser.js +5 -12
  43. package/dist/lib/preprocessors/typescriptPreprocessor.d.ts +0 -28
  44. package/dist/lib/preprocessors/typescriptPreprocessor.js +0 -245
  45. package/dist/lib/runtime/configOverrides.d.ts +17 -16
  46. package/dist/lib/runtime/configOverrides.js +27 -16
  47. package/dist/lib/runtime/configOverrides.test.js +116 -2
  48. package/dist/lib/runtime/prompt.js +7 -3
  49. package/dist/lib/runtime/runner.d.ts +2 -2
  50. package/dist/lib/runtime/runner.js +26 -7
  51. package/dist/lib/runtime/state/context.js +9 -2
  52. package/dist/lib/stdlib/llm.d.ts +1 -0
  53. package/dist/lib/stdlib/version.d.ts +1 -1
  54. package/dist/lib/stdlib/version.js +1 -1
  55. package/dist/scripts/agency.d.ts +2 -0
  56. package/dist/scripts/agency.js +55 -12
  57. package/dist/scripts/agency.test.js +73 -1
  58. package/package.json +1 -1
  59. package/stdlib/agency/eval.js +1 -1
  60. package/stdlib/agency.js +1 -1
  61. package/stdlib/agent.agency +9 -9
  62. package/stdlib/agent.js +5 -5
  63. package/stdlib/data/tech/hackernews.js +1 -1
  64. package/stdlib/index.js +15 -15
  65. package/stdlib/llm.agency +2 -1
  66. package/stdlib/llm.js +3 -3
  67. package/stdlib/markdown.js +1 -1
  68. package/stdlib/memory.js +2 -2
  69. package/stdlib/object.js +5 -5
  70. package/stdlib/policy.agency +21 -7
  71. package/stdlib/policy.js +45 -16
  72. package/stdlib/skills.js +1 -1
  73. package/stdlib/strategy.js +3 -3
  74. package/stdlib/thread.js +3 -3
  75. package/stdlib/ui/chart.js +2 -2
  76. package/stdlib/ui/cli.agency +1 -1
  77. package/stdlib/ui/cli.js +1 -1
  78. package/stdlib/ui/layout.js +3 -3
  79. package/stdlib/ui/table.js +2 -2
  80. package/stdlib/ui.js +3 -3
  81. package/dist/lib/agents/docs/cli/cli/agent.md +0 -16
  82. package/dist/lib/agents/docs/cli/cli/compile.md +0 -21
  83. package/dist/lib/agents/docs/cli/cli/coverage.md +0 -112
  84. package/dist/lib/agents/docs/cli/cli/debug.md +0 -41
  85. package/dist/lib/agents/docs/cli/cli/doc.md +0 -98
  86. package/dist/lib/agents/docs/cli/cli/editor-integration.md +0 -44
  87. package/dist/lib/agents/docs/cli/cli/eval-judge.md +0 -72
  88. package/dist/lib/agents/docs/cli/cli/eval.md +0 -194
  89. package/dist/lib/agents/docs/cli/cli/format.md +0 -23
  90. package/dist/lib/agents/docs/cli/cli/index.md +0 -7
  91. package/dist/lib/agents/docs/cli/cli/local.md +0 -92
  92. package/dist/lib/agents/docs/cli/cli/models.md +0 -63
  93. package/dist/lib/agents/docs/cli/cli/optimize.md +0 -338
  94. package/dist/lib/agents/docs/cli/cli/pack.md +0 -56
  95. package/dist/lib/agents/docs/cli/cli/policy.md +0 -23
  96. package/dist/lib/agents/docs/cli/cli/preprocess-and-ast.md +0 -21
  97. package/dist/lib/agents/docs/cli/cli/review.md +0 -16
  98. package/dist/lib/agents/docs/cli/cli/run.md +0 -79
  99. package/dist/lib/agents/docs/cli/cli/schedule.md +0 -89
  100. package/dist/lib/agents/docs/cli/cli/serve.md +0 -52
  101. package/dist/lib/agents/docs/cli/cli/test.md +0 -44
  102. package/dist/lib/agents/docs/cli/cli/trace-and-bundle.md +0 -75
  103. package/dist/lib/agents/docs/cli/cli/typecheck.md +0 -19
  104. package/dist/lib/agents/docs/guide/guide/advanced-types.md +0 -26
  105. package/dist/lib/agents/docs/guide/guide/agency-config-file.md +0 -212
  106. package/dist/lib/agents/docs/guide/guide/agency-packages.md +0 -54
  107. package/dist/lib/agents/docs/guide/guide/agency-stdlib.md +0 -14
  108. package/dist/lib/agents/docs/guide/guide/agency-vs-typescript.md +0 -33
  109. package/dist/lib/agents/docs/guide/guide/attachments.md +0 -56
  110. package/dist/lib/agents/docs/guide/guide/basic-syntax.md +0 -350
  111. package/dist/lib/agents/docs/guide/guide/blocks.md +0 -134
  112. package/dist/lib/agents/docs/guide/guide/build-integration.md +0 -99
  113. package/dist/lib/agents/docs/guide/guide/builtins.md +0 -84
  114. package/dist/lib/agents/docs/guide/guide/callbacks.md +0 -169
  115. package/dist/lib/agents/docs/guide/guide/checkpointing.md +0 -101
  116. package/dist/lib/agents/docs/guide/guide/cli-args.md +0 -190
  117. package/dist/lib/agents/docs/guide/guide/common-functions.md +0 -36
  118. package/dist/lib/agents/docs/guide/guide/compiling-and-running.md +0 -62
  119. package/dist/lib/agents/docs/guide/guide/concurrency.md +0 -108
  120. package/dist/lib/agents/docs/guide/guide/cross-thread-context.md +0 -226
  121. package/dist/lib/agents/docs/guide/guide/custom-providers.md +0 -195
  122. package/dist/lib/agents/docs/guide/guide/debugging.md +0 -67
  123. package/dist/lib/agents/docs/guide/guide/developer-tools.md +0 -90
  124. package/dist/lib/agents/docs/guide/guide/effects-and-raises.md +0 -137
  125. package/dist/lib/agents/docs/guide/guide/effects.md +0 -100
  126. package/dist/lib/agents/docs/guide/guide/error-handling.md +0 -161
  127. package/dist/lib/agents/docs/guide/guide/exercise-1.md +0 -32
  128. package/dist/lib/agents/docs/guide/guide/functions.md +0 -94
  129. package/dist/lib/agents/docs/guide/guide/getting-started.md +0 -35
  130. package/dist/lib/agents/docs/guide/guide/global-var-initialization.md +0 -70
  131. package/dist/lib/agents/docs/guide/guide/global-vs-static.md +0 -76
  132. package/dist/lib/agents/docs/guide/guide/guards.md +0 -134
  133. package/dist/lib/agents/docs/guide/guide/handlers.md +0 -196
  134. package/dist/lib/agents/docs/guide/guide/image-generation.md +0 -113
  135. package/dist/lib/agents/docs/guide/guide/imports-and-packages.md +0 -100
  136. package/dist/lib/agents/docs/guide/guide/interrupts-from-typescript.md +0 -84
  137. package/dist/lib/agents/docs/guide/guide/interrupts-part-2.md +0 -54
  138. package/dist/lib/agents/docs/guide/guide/interrupts.md +0 -139
  139. package/dist/lib/agents/docs/guide/guide/llm-part-2.md +0 -111
  140. package/dist/lib/agents/docs/guide/guide/llm.md +0 -109
  141. package/dist/lib/agents/docs/guide/guide/mcp.md +0 -295
  142. package/dist/lib/agents/docs/guide/guide/memory.md +0 -401
  143. package/dist/lib/agents/docs/guide/guide/message-threads.md +0 -111
  144. package/dist/lib/agents/docs/guide/guide/nodes.md +0 -50
  145. package/dist/lib/agents/docs/guide/guide/observability.md +0 -99
  146. package/dist/lib/agents/docs/guide/guide/partial-application.md +0 -96
  147. package/dist/lib/agents/docs/guide/guide/pattern-matching.md +0 -366
  148. package/dist/lib/agents/docs/guide/guide/policies.md +0 -67
  149. package/dist/lib/agents/docs/guide/guide/schema-parameter-injection.md +0 -101
  150. package/dist/lib/agents/docs/guide/guide/schemas.md +0 -99
  151. package/dist/lib/agents/docs/guide/guide/serving.md +0 -165
  152. package/dist/lib/agents/docs/guide/guide/state-isolation.md +0 -139
  153. package/dist/lib/agents/docs/guide/guide/streaming.md +0 -28
  154. package/dist/lib/agents/docs/guide/guide/tags.md +0 -72
  155. package/dist/lib/agents/docs/guide/guide/testing.md +0 -187
  156. package/dist/lib/agents/docs/guide/guide/troubleshooting.md +0 -86
  157. package/dist/lib/agents/docs/guide/guide/ts-helpers.md +0 -559
  158. package/dist/lib/agents/docs/guide/guide/ts-interop.md +0 -72
  159. package/dist/lib/agents/docs/guide/guide/type-validation.md +0 -187
  160. package/dist/lib/agents/docs/guide/guide/types.md +0 -181
  161. package/dist/lib/agents/docs/guide/guide/unused.md +0 -178
  162. package/dist/lib/agents/docs/guide/guide/unused2.md +0 -258
  163. package/dist/lib/agents/docs/guide/guide/value-parameterized-types.md +0 -186
  164. package/dist/lib/agents/docs/guide/guide/vscode-extension.md +0 -33
  165. package/dist/lib/agents/docs/guide/guide/why-agency.md +0 -323
  166. package/dist/lib/preprocessors/typescriptPreprocessor.config.test.js +0 -327
  167. package/stdlib/browser.js +0 -421
  168. package/stdlib/chart.js +0 -983
  169. package/stdlib/cli.js +0 -1116
  170. package/stdlib/email.js +0 -1104
  171. package/stdlib/imessage.js +0 -377
  172. package/stdlib/keyring.js +0 -803
  173. package/stdlib/layout.js +0 -3657
  174. package/stdlib/oauth.js +0 -862
  175. package/stdlib/schemas.js +0 -223
  176. package/stdlib/search.js +0 -629
  177. package/stdlib/sms.js +0 -419
  178. package/stdlib/table.js +0 -1419
  179. package/stdlib/threads.js +0 -1041
  180. package/stdlib/types.js +0 -222
  181. package/stdlib/validators.js +0 -1606
  182. /package/dist/lib/{preprocessors/typescriptPreprocessor.config.test.d.ts → cli/doctor.test.d.ts} +0 -0
@@ -220,7 +220,7 @@ async function __filterHostedModels_impl(models, filters) {
220
220
  await runner.step(1, async (runner2) => {
221
221
  __stack.locals.out = [];
222
222
  });
223
- await runner.loop(2, __stack.args.models, async (model, _, runner2) => {
223
+ await runner.loop(2, async () => __stack.args.models, async (model, _, runner2) => {
224
224
  await runner2.ifElse(0, [
225
225
  {
226
226
  condition: async () => !__eq(__stack.args.filters.provider, null) && !__eq(__stack.args.filters.provider, ``) && !__eq(model.provider, __stack.args.filters.provider),
@@ -378,7 +378,7 @@ async function __resolveSlot_impl(slot, layers, ctx) {
378
378
  }
379
379
  });
380
380
  });
381
- await runner.loop(1, __stack.args.layers, async (layer, _, runner2) => {
381
+ await runner.loop(1, async () => __stack.args.layers, async (layer, _, runner2) => {
382
382
  await runner2.step(0, async (runner3) => {
383
383
  __stack.locals.perSlotValue = layer.perSlot[__stack.args.slot];
384
384
  });
@@ -603,7 +603,7 @@ async function __resolveAll_impl(layers, ctx) {
603
603
  await runner.step(1, async (runner2) => {
604
604
  __stack.locals.output = {};
605
605
  });
606
- await runner.loop(2, __readStatic(SLOTS, "SLOTS", "/Users/adityabhargava/agency-lang/packages/agency-lang/dist/lib/agents/agency-agent/lib/slots.agency"), async (slot, _, runner2) => {
606
+ await runner.loop(2, async () => __readStatic(SLOTS, "SLOTS", "/Users/adityabhargava/agency-lang/packages/agency-lang/dist/lib/agents/agency-agent/lib/slots.agency"), async (slot, _, runner2) => {
607
607
  await runner2.step(0, async (runner3) => {
608
608
  __stack.locals.resolved = await __call(resolveSlot, {
609
609
  type: "positional",
@@ -923,7 +923,7 @@ async function __slotMapToValues_impl(slots, providers, providerEstablished) {
923
923
  await runner.step(1, async (runner2) => {
924
924
  __stack.locals.output = {};
925
925
  });
926
- await runner.loop(2, await __callMethod(Object, "keys", {
926
+ await runner.loop(2, async () => await __callMethod(Object, "keys", {
927
927
  type: "positional",
928
928
  args: [__stack.args.slots]
929
929
  }), async (key, _, runner2) => {
@@ -1376,7 +1376,7 @@ async function __diffResolved_impl(before, after) {
1376
1376
  await runner.step(1, async (runner2) => {
1377
1377
  __stack.locals.changes = [];
1378
1378
  });
1379
- await runner.loop(2, await __callMethod(Object, "keys", {
1379
+ await runner.loop(2, async () => await __callMethod(Object, "keys", {
1380
1380
  type: "positional",
1381
1381
  args: [__stack.args.after]
1382
1382
  }), async (slot, _, runner2) => {
@@ -304,7 +304,7 @@ async function __findBackend_impl(name) {
304
304
  }
305
305
  });
306
306
  });
307
- await runner.loop(1, __readStatic(BACKENDS, "BACKENDS", "dist/lib/agents/agency-agent/lib/search.agency"), async (b, _, runner2) => {
307
+ await runner.loop(1, async () => __readStatic(BACKENDS, "BACKENDS", "dist/lib/agents/agency-agent/lib/search.agency"), async (b, _, runner2) => {
308
308
  await runner2.ifElse(0, [
309
309
  {
310
310
  condition: async () => __eq(b.name, __stack.args.name),
@@ -921,7 +921,7 @@ async function __usableLocalBackends_impl(ctx) {
921
921
  await runner.step(1, async (runner2) => {
922
922
  __stack.locals.result = [];
923
923
  });
924
- await runner.loop(2, __readStatic(BACKENDS, "BACKENDS", "dist/lib/agents/agency-agent/lib/search.agency"), async (b, _, runner2) => {
924
+ await runner.loop(2, async () => __readStatic(BACKENDS, "BACKENDS", "dist/lib/agents/agency-agent/lib/search.agency"), async (b, _, runner2) => {
925
925
  await runner2.ifElse(0, [
926
926
  {
927
927
  condition: async () => __eq(b.name, `off`) || __eq(b.name, `hosted`),
@@ -2128,7 +2128,7 @@ async function __availableBackendItems_impl() {
2128
2128
  await runner.step(2, async (runner2) => {
2129
2129
  __stack.locals.result = [];
2130
2130
  });
2131
- await runner.loop(3, __readStatic(BACKENDS, "BACKENDS", "dist/lib/agents/agency-agent/lib/search.agency"), async (b, _, runner2) => {
2131
+ await runner.loop(3, async () => __readStatic(BACKENDS, "BACKENDS", "dist/lib/agents/agency-agent/lib/search.agency"), async (b, _, runner2) => {
2132
2132
  await runner2.ifElse(0, [
2133
2133
  {
2134
2134
  condition: async () => await __call(isBackendAvailable, {
@@ -252,7 +252,7 @@ async function __sanitizeModelSettings_impl(settings) {
252
252
  await runner.step(4, async (runner2) => {
253
253
  __stack.locals.kept = {};
254
254
  });
255
- await runner.loop(5, await __callMethod(Object, "keys", {
255
+ await runner.loop(5, async () => await __callMethod(Object, "keys", {
256
256
  type: "positional",
257
257
  args: [__stack.locals.slots]
258
258
  }), async (key, _, runner2) => {
@@ -602,7 +602,7 @@ async function __formatArgs_impl(args) {
602
602
  await runner.step(1, async (runner2) => {
603
603
  __stack.locals.parts = [];
604
604
  });
605
- await runner.loop(2, __stack.args.args, async (key, _, runner2) => {
605
+ await runner.loop(2, async () => __stack.args.args, async (key, _, runner2) => {
606
606
  await runner2.step(0, async (runner3) => {
607
607
  __stack.locals.value = __stack.args.args[key];
608
608
  });
@@ -21,6 +21,28 @@ import { getModelSettings, loadSettings } from "./lib/settings.agency"
21
21
  import { slotKind } from "./lib/slots.agency"
22
22
 
23
23
 
24
+ // One-shot runs (--print / piped / a positional query) have no REPL for the
25
+ // user to say "keep going", so an autonomous task gets more tool rounds by
26
+ // default than the interactive baked default (10).
27
+ export static const ONE_SHOT_MAX_TOOL_CALL_ROUNDS = 50
28
+
29
+ /** Effective maxToolCallRounds for a run. An explicit --max-tool-call-rounds
30
+ always wins; otherwise a one-shot run gets ONE_SHOT_MAX_TOOL_CALL_ROUNDS and
31
+ an interactive run returns null (keep the compiled default). */
32
+ export def resolveMaxToolCallRounds(
33
+ explicit: number | null,
34
+ oneShot: boolean,
35
+ ): number | null {
36
+ if (explicit != null) {
37
+ return explicit
38
+ }
39
+ if (oneShot) {
40
+ return ONE_SHOT_MAX_TOOL_CALL_ROUNDS
41
+ }
42
+ return null
43
+ }
44
+
45
+
24
46
  // Per-user state directory for the agent (persistent memory + saved
25
47
  // policy). We expand `~` ourselves via `env("HOME")` because
26
48
  // `enableMemory(...)`'s underlying `MemoryFrame` calls
@@ -184,12 +184,14 @@ __registerTool(getModelSettings);
184
184
  __registerTool(loadSettings);
185
185
  __registerTool(slotKind);
186
186
  let __staticInitPromise = null;
187
+ let ONE_SHOT_MAX_TOOL_CALL_ROUNDS = __UNINIT_STATIC;
187
188
  let AGENCY_AGENT_DIR = __UNINIT_STATIC;
188
189
  async function __initializeStatic(__ctx) {
189
190
  if (__staticInitPromise) {
190
191
  return __staticInitPromise;
191
192
  }
192
193
  __staticInitPromise = (async () => {
194
+ ONE_SHOT_MAX_TOOL_CALL_ROUNDS = __deepFreeze(50);
193
195
  AGENCY_AGENT_DIR = __deepFreeze(await __call(computeAgentDir, {
194
196
  type: "positional",
195
197
  args: []
@@ -199,6 +201,7 @@ async function __initializeStatic(__ctx) {
199
201
  }
200
202
  function __getStaticVars() {
201
203
  return {
204
+ ONE_SHOT_MAX_TOOL_CALL_ROUNDS,
202
205
  AGENCY_AGENT_DIR
203
206
  };
204
207
  }
@@ -220,6 +223,158 @@ async function __registerTopLevelCallbacks(__ctx) {
220
223
  __ctx.topLevelCallbacks = [];
221
224
  }
222
225
  __functionRefReviver.registry = __toolRegistry;
226
+ async function __resolveMaxToolCallRounds_impl(explicit, oneShot) {
227
+ const __setupData = setupFunction();
228
+ const __stack = __setupData.stack;
229
+ const __step = __setupData.step;
230
+ const __self = __setupData.self;
231
+ const __ctx = getRuntimeContext().ctx;
232
+ let __forked;
233
+ let __functionCompleted = false;
234
+ if (!__globals().isInitialized("dist/lib/agents/agency-agent/shared.agency")) {
235
+ await __initializeGlobals(__ctx);
236
+ }
237
+ let __funcStartTime = performance.now();
238
+ __stack.args["explicit"] = explicit;
239
+ __stack.args["oneShot"] = oneShot;
240
+ __self.__retryable = __self.__retryable ?? true;
241
+ const runner = new Runner(__ctx, __stack, { state: __stack, moduleId: "dist/lib/agents/agency-agent/shared.agency", scopeName: "resolveMaxToolCallRounds", threads: __setupData.threads });
242
+ let __resultCheckpointId = -1;
243
+ if (__ctx._pendingArgOverrides) {
244
+ const __overrides = __ctx._pendingArgOverrides;
245
+ __ctx._pendingArgOverrides = void 0;
246
+ if ("explicit" in __overrides) {
247
+ explicit = __overrides["explicit"];
248
+ __stack.args["explicit"] = explicit;
249
+ }
250
+ if ("oneShot" in __overrides) {
251
+ oneShot = __overrides["oneShot"];
252
+ __stack.args["oneShot"] = oneShot;
253
+ }
254
+ }
255
+ try {
256
+ await agencyStore.run({
257
+ ...getRuntimeContext(),
258
+ ctx: __ctx,
259
+ stack: __setupData.stateStack,
260
+ threads: __setupData.threads
261
+ }, async () => {
262
+ await runner.hook(0, async () => {
263
+ await callHook({
264
+ name: "onFunctionStart",
265
+ data: {
266
+ functionName: "resolveMaxToolCallRounds",
267
+ args: {
268
+ explicit,
269
+ oneShot
270
+ },
271
+ moduleId: "dist/lib/agents/agency-agent/shared.agency"
272
+ }
273
+ });
274
+ });
275
+ await runner.ifElse(1, [
276
+ {
277
+ condition: async () => !__eq(__stack.args.explicit, null),
278
+ body: async (runner2) => {
279
+ await runner2.step(0, async (runner3) => {
280
+ __functionCompleted = true;
281
+ runner3.halt(__stack.args.explicit);
282
+ return;
283
+ });
284
+ }
285
+ }
286
+ ]);
287
+ await runner.ifElse(2, [
288
+ {
289
+ condition: async () => __stack.args.oneShot,
290
+ body: async (runner2) => {
291
+ await runner2.step(0, async (runner3) => {
292
+ __functionCompleted = true;
293
+ runner3.halt(__readStatic(ONE_SHOT_MAX_TOOL_CALL_ROUNDS, "ONE_SHOT_MAX_TOOL_CALL_ROUNDS", "dist/lib/agents/agency-agent/shared.agency"));
294
+ return;
295
+ });
296
+ }
297
+ }
298
+ ]);
299
+ await runner.step(3, async (runner2) => {
300
+ __functionCompleted = true;
301
+ runner2.halt(null);
302
+ return;
303
+ });
304
+ });
305
+ if (runner.halted) {
306
+ if (isFailure(runner.haltResult)) {
307
+ runner.haltResult.retryable = runner.haltResult.retryable && __self.__retryable;
308
+ }
309
+ return runner.haltResult;
310
+ }
311
+ } catch (__error) {
312
+ if (__error instanceof RestoreSignal) {
313
+ throw __error;
314
+ }
315
+ if (__error instanceof AgencyAbort) {
316
+ throw __error;
317
+ }
318
+ {
319
+ const __errMsg = __error instanceof Error ? __error.message : String(__error);
320
+ const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
321
+ const __log = __createLogger(__ctx.logLevel);
322
+ __log.error("Function resolveMaxToolCallRounds threw an exception (converted to Failure): " + __errMsg);
323
+ if (__errStack) __log.error(__errStack);
324
+ __ctx.statelogClient?.error?.({
325
+ errorType: "runtimeError",
326
+ message: __errMsg,
327
+ functionName: "resolveMaxToolCallRounds",
328
+ retryable: __self.__retryable
329
+ });
330
+ }
331
+ return failure(
332
+ __error instanceof Error ? __error.message : String(__error),
333
+ {
334
+ checkpoint: getRuntimeContext().ctx.getResultCheckpoint(),
335
+ retryable: __self.__retryable,
336
+ functionName: "resolveMaxToolCallRounds",
337
+ args: __stack.args
338
+ }
339
+ );
340
+ } finally {
341
+ __stateStack()?.pop();
342
+ if (__functionCompleted) {
343
+ await callHook({
344
+ name: "onFunctionEnd",
345
+ data: {
346
+ functionName: "resolveMaxToolCallRounds",
347
+ timeTaken: performance.now() - __funcStartTime
348
+ }
349
+ });
350
+ }
351
+ }
352
+ }
353
+ const resolveMaxToolCallRounds = __AgencyFunction.create({
354
+ name: "resolveMaxToolCallRounds",
355
+ module: "dist/lib/agents/agency-agent/shared.agency",
356
+ fn: __resolveMaxToolCallRounds_impl,
357
+ params: [{
358
+ name: "explicit",
359
+ hasDefault: false,
360
+ defaultValue: void 0,
361
+ variadic: false,
362
+ isFunctionTyped: false
363
+ }, {
364
+ name: "oneShot",
365
+ hasDefault: false,
366
+ defaultValue: void 0,
367
+ variadic: false,
368
+ isFunctionTyped: false
369
+ }],
370
+ toolDefinition: {
371
+ name: "resolveMaxToolCallRounds",
372
+ description: "No description provided.",
373
+ schema: z.object({ "explicit": z.union([z.number(), z.null()]), "oneShot": z.boolean() })
374
+ },
375
+ safe: false,
376
+ exported: true
377
+ }, __toolRegistry);
223
378
  async function __computeAgentDir_impl() {
224
379
  const __setupData = setupFunction();
225
380
  const __stack = __setupData.stack;
@@ -972,7 +1127,7 @@ async function __promoteAll_impl(slots) {
972
1127
  await runner.step(1, async (runner2) => {
973
1128
  __stack.locals.promoted = {};
974
1129
  });
975
- await runner.loop(2, await __callMethod(Object, "keys", {
1130
+ await runner.loop(2, async () => await __callMethod(Object, "keys", {
976
1131
  type: "positional",
977
1132
  args: [__stack.args.slots]
978
1133
  }), async (slot, _, runner2) => {
@@ -1120,7 +1275,7 @@ async function __applyResolved_impl(slots) {
1120
1275
  await runner.step(1, async (runner2) => {
1121
1276
  __globals().set("dist/lib/agents/agency-agent/shared.agency", "_resolved", __stack.args.slots);
1122
1277
  });
1123
- await runner.loop(2, await __callMethod(Object, "keys", {
1278
+ await runner.loop(2, async () => await __callMethod(Object, "keys", {
1124
1279
  type: "positional",
1125
1280
  args: [__stack.args.slots]
1126
1281
  }), async (slot, _, runner2) => {
@@ -1993,9 +2148,10 @@ const configureLocalModel = __AgencyFunction.create({
1993
2148
  exported: true
1994
2149
  }, __toolRegistry);
1995
2150
  var stdin_default = graph;
1996
- const __sourceMap = { "dist/lib/agents/agency-agent/shared.agency:computeAgentDir": { "1": { "line": 34, "col": 2 }, "2": { "line": 35, "col": 2 }, "3": { "line": 38, "col": 2 }, "2.0": { "line": 36, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:enableAgentMemory": { "1": { "line": 59, "col": 2 } }, "dist/lib/agents/agency-agent/shared.agency:getSlowModel": { "1": { "line": 72, "col": 2 } }, "dist/lib/agents/agency-agent/shared.agency:getSlowProvider": { "1": { "line": 76, "col": 2 } }, "dist/lib/agents/agency-agent/shared.agency:setSlowModel": { "1": { "line": 84, "col": 2 }, "2": { "line": 85, "col": 2 } }, "dist/lib/agents/agency-agent/shared.agency:promoteProvider": { "1": { "line": 93, "col": 2 }, "2": { "line": 96, "col": 2 }, "1.0": { "line": 94, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:promoteAll": { "1": { "line": 102, "col": 2 }, "2": { "line": 103, "col": 2 }, "3": { "line": 114, "col": 2 }, "2.0": { "line": 104, "col": 4 }, "2.1": { "line": 105, "col": 4 }, "2.2": { "line": 108, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:applyResolved": { "1": { "line": 122, "col": 2 }, "2": { "line": 123, "col": 2 }, "2.0": { "line": 124, "col": 4 }, "2.1": { "line": 125, "col": 4 }, "2.2": { "line": 128, "col": 4 }, "2.3.0": { "line": 130, "col": 6 }, "2.3.1": { "line": 137, "col": 6 }, "2.3": { "line": 129, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:getResolvedSlots": { "1": { "line": 143, "col": 2 } }, "dist/lib/agents/agency-agent/shared.agency:currentProvider": { "1": { "line": 147, "col": 2 }, "2": { "line": 148, "col": 2 }, "3": { "line": 151, "col": 2 }, "2.0": { "line": 149, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:configureModels": { "1": { "line": 170, "col": 2 }, "2": { "line": 175, "col": 2 }, "3": { "line": 176, "col": 2 }, "4": { "line": 180, "col": 2 }, "5": { "line": 181, "col": 2 }, "7": { "line": 190, "col": 2 }, "8": { "line": 194, "col": 2 }, "9": { "line": 195, "col": 2 }, "10": { "line": 198, "col": 2 }, "12": { "line": 204, "col": 2 }, "13": { "line": 205, "col": 2 }, "14": { "line": 214, "col": 2 }, "15": { "line": 215, "col": 2 }, "16": { "line": 220, "col": 2 }, "3.0": { "line": 177, "col": 4 }, "5.0": { "line": 182, "col": 4 }, "5.1": { "line": 183, "col": 4 }, "5.2": { "line": 184, "col": 4 }, "9.0": { "line": 196, "col": 4 }, "10.0": { "line": 199, "col": 4 }, "15.0": { "line": 216, "col": 4 }, "15.1": { "line": 217, "col": 4 }, "15.2": { "line": 218, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:configureLocalModel": { "2": { "line": 236, "col": 2 }, "3": { "line": 237, "col": 2 }, "4": { "line": 242, "col": 2 }, "5": { "line": 246, "col": 2 }, "6": { "line": 251, "col": 2 }, "3.0": { "line": 238, "col": 4 }, "3.1": { "line": 239, "col": 4 }, "3.2": { "line": 240, "col": 4 } } };
2151
+ const __sourceMap = { "dist/lib/agents/agency-agent/shared.agency:resolveMaxToolCallRounds": { "1": { "line": 35, "col": 2 }, "2": { "line": 38, "col": 2 }, "3": { "line": 41, "col": 2 }, "1.0": { "line": 36, "col": 4 }, "2.0": { "line": 39, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:computeAgentDir": { "1": { "line": 56, "col": 2 }, "2": { "line": 57, "col": 2 }, "3": { "line": 60, "col": 2 }, "2.0": { "line": 58, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:enableAgentMemory": { "1": { "line": 81, "col": 2 } }, "dist/lib/agents/agency-agent/shared.agency:getSlowModel": { "1": { "line": 94, "col": 2 } }, "dist/lib/agents/agency-agent/shared.agency:getSlowProvider": { "1": { "line": 98, "col": 2 } }, "dist/lib/agents/agency-agent/shared.agency:setSlowModel": { "1": { "line": 106, "col": 2 }, "2": { "line": 107, "col": 2 } }, "dist/lib/agents/agency-agent/shared.agency:promoteProvider": { "1": { "line": 115, "col": 2 }, "2": { "line": 118, "col": 2 }, "1.0": { "line": 116, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:promoteAll": { "1": { "line": 124, "col": 2 }, "2": { "line": 125, "col": 2 }, "3": { "line": 136, "col": 2 }, "2.0": { "line": 126, "col": 4 }, "2.1": { "line": 127, "col": 4 }, "2.2": { "line": 130, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:applyResolved": { "1": { "line": 144, "col": 2 }, "2": { "line": 145, "col": 2 }, "2.0": { "line": 146, "col": 4 }, "2.1": { "line": 147, "col": 4 }, "2.2": { "line": 150, "col": 4 }, "2.3.0": { "line": 152, "col": 6 }, "2.3.1": { "line": 159, "col": 6 }, "2.3": { "line": 151, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:getResolvedSlots": { "1": { "line": 165, "col": 2 } }, "dist/lib/agents/agency-agent/shared.agency:currentProvider": { "1": { "line": 169, "col": 2 }, "2": { "line": 170, "col": 2 }, "3": { "line": 173, "col": 2 }, "2.0": { "line": 171, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:configureModels": { "1": { "line": 192, "col": 2 }, "2": { "line": 197, "col": 2 }, "3": { "line": 198, "col": 2 }, "4": { "line": 202, "col": 2 }, "5": { "line": 203, "col": 2 }, "7": { "line": 212, "col": 2 }, "8": { "line": 216, "col": 2 }, "9": { "line": 217, "col": 2 }, "10": { "line": 220, "col": 2 }, "12": { "line": 226, "col": 2 }, "13": { "line": 227, "col": 2 }, "14": { "line": 236, "col": 2 }, "15": { "line": 237, "col": 2 }, "16": { "line": 242, "col": 2 }, "3.0": { "line": 199, "col": 4 }, "5.0": { "line": 204, "col": 4 }, "5.1": { "line": 205, "col": 4 }, "5.2": { "line": 206, "col": 4 }, "9.0": { "line": 218, "col": 4 }, "10.0": { "line": 221, "col": 4 }, "15.0": { "line": 238, "col": 4 }, "15.1": { "line": 239, "col": 4 }, "15.2": { "line": 240, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:configureLocalModel": { "2": { "line": 258, "col": 2 }, "3": { "line": 259, "col": 2 }, "4": { "line": 264, "col": 2 }, "5": { "line": 268, "col": 2 }, "6": { "line": 273, "col": 2 }, "3.0": { "line": 260, "col": 4 }, "3.1": { "line": 261, "col": 4 }, "3.2": { "line": 262, "col": 4 } } };
1997
2152
  export {
1998
2153
  AGENCY_AGENT_DIR,
2154
+ ONE_SHOT_MAX_TOOL_CALL_ROUNDS,
1999
2155
  __getCheckpoints,
2000
2156
  __invokeFunction,
2001
2157
  __setDebugger,
@@ -2021,6 +2177,7 @@ export {
2021
2177
  promoteAll,
2022
2178
  promoteProvider,
2023
2179
  reject,
2180
+ resolveMaxToolCallRounds,
2024
2181
  respondToInterrupts,
2025
2182
  rewindFrom,
2026
2183
  setSlowModel
@@ -829,7 +829,7 @@ async function __codeAgent_impl(userMsg, allowHandoff) {
829
829
  await runner.step(8, async (runner2) => {
830
830
  __stack.locals.firstIteration = true;
831
831
  });
832
- await runner.thread(9, "create", { label: `code`, summarize: true, session: `code` }, async (runner2) => {
832
+ await runner.thread(9, "create", async () => ({ label: `code`, summarize: true, session: `code` }), async (runner2) => {
833
833
  await runner2.step(0, async (runner3) => {
834
834
  __self.__retryable = false;
835
835
  const __funcResult = await __call(setMemoryId, {
@@ -378,7 +378,7 @@ async function __explorerAgent_impl(userMsg, allowHandoff) {
378
378
  }
379
379
  });
380
380
  });
381
- await runner.thread(1, "create", { label: `explorer`, summarize: true, session: `explorer` }, async (runner2) => {
381
+ await runner.thread(1, "create", async () => ({ label: `explorer`, summarize: true, session: `explorer` }), async (runner2) => {
382
382
  await runner2.ifElse(0, [
383
383
  {
384
384
  condition: async () => __globals().get("dist/lib/agents/agency-agent/subagents/explorer.agency", "first"),
@@ -358,7 +358,7 @@ async function __oracleAgent_impl(userMsg, allowHandoff) {
358
358
  }
359
359
  });
360
360
  });
361
- await runner.thread(1, "create", { label: `oracle`, summarize: true, session: `oracle` }, async (runner2) => {
361
+ await runner.thread(1, "create", async () => ({ label: `oracle`, summarize: true, session: `oracle` }), async (runner2) => {
362
362
  await runner2.ifElse(0, [
363
363
  {
364
364
  condition: async () => __globals().get("dist/lib/agents/agency-agent/subagents/oracle.agency", "first"),
@@ -385,7 +385,7 @@ async function __researchAgent_impl(userMsg, allowHandoff) {
385
385
  }
386
386
  });
387
387
  });
388
- await runner.thread(1, "create", { label: `research`, summarize: true, session: `research` }, async (runner2) => {
388
+ await runner.thread(1, "create", async () => ({ label: `research`, summarize: true, session: `research` }), async (runner2) => {
389
389
  await runner2.step(0, async (runner3) => {
390
390
  __self.__retryable = false;
391
391
  const __funcResult = await __call(setMemoryId, {
@@ -962,7 +962,7 @@ async function __review_impl(userMsg) {
962
962
  }
963
963
  });
964
964
  });
965
- await runner.thread(1, "create", { label: `review`, summarize: true, session: `review` }, async (runner2) => {
965
+ await runner.thread(1, "create", async () => ({ label: `review`, summarize: true, session: `review` }), async (runner2) => {
966
966
  await runner2.step(0, async (runner3) => {
967
967
  __self.__retryable = false;
968
968
  const __funcResult = await __call(setMemoryId, {
@@ -1002,7 +1002,7 @@ async function __review_impl(userMsg) {
1002
1002
  return;
1003
1003
  }
1004
1004
  });
1005
- await runner2.loop(3, __stack.locals.snippets, async (codeSnippet, _, runner3) => {
1005
+ await runner2.loop(3, async () => __stack.locals.snippets, async (codeSnippet, _, runner3) => {
1006
1006
  await runner3.step(0, async (runner4) => {
1007
1007
  __stack.locals.parseResult = await __call(_parse, {
1008
1008
  type: "positional",
@@ -1217,7 +1217,7 @@ async function ___typecheck_impl(agencyCode) {
1217
1217
  await runner2.step(5, async (runner3) => {
1218
1218
  __stack.locals.feedback = [];
1219
1219
  });
1220
- await runner2.loop(6, __stack.locals.errors, async (error, _, runner3) => {
1220
+ await runner2.loop(6, async () => __stack.locals.errors, async (error, _, runner3) => {
1221
1221
  await runner3.step(0, async (runner4) => {
1222
1222
  await __callMethod(__stack.locals.feedback, "push", {
1223
1223
  type: "positional",
@@ -1229,7 +1229,7 @@ async function ___typecheck_impl(agencyCode) {
1229
1229
  });
1230
1230
  });
1231
1231
  });
1232
- await runner2.loop(7, __stack.locals.warnings, async (warning, _, runner3) => {
1232
+ await runner2.loop(7, async () => __stack.locals.warnings, async (warning, _, runner3) => {
1233
1233
  await runner3.step(0, async (runner4) => {
1234
1234
  await __callMethod(__stack.locals.feedback, "push", {
1235
1235
  type: "positional",
@@ -1727,7 +1727,7 @@ graph.node("modelItemsFilterOnlyAnthropic", async (__state) => {
1727
1727
  }
1728
1728
  }
1729
1729
  ]);
1730
- await runner.loop(3, __stack.locals.items, async (item, _, runner2) => {
1730
+ await runner.loop(3, async () => __stack.locals.items, async (item, _, runner2) => {
1731
1731
  await runner2.step(0, async (runner3) => {
1732
1732
  __self.__retryable = false;
1733
1733
  __stack.locals.info = await __call(hostedModelInfo, {
@@ -1637,7 +1637,7 @@ graph.node("capsAtTenWithVisibleSkip", async (__state) => {
1637
1637
  await runner.step(1, async (runner2) => {
1638
1638
  __stack.locals.msg = `look at`;
1639
1639
  });
1640
- await runner.loop(2, Array.from({ length: 11 - 0 }, (_, __i) => __i + 0), async (i, _, runner2) => {
1640
+ await runner.loop(2, async () => Array.from({ length: 11 - 0 }, (_, __i) => __i + 0), async (i, _, runner2) => {
1641
1641
  await runner2.handle(0, async (__data) => approve(), async (runner3) => {
1642
1642
  await runner3.step(0, async (runner4) => {
1643
1643
  __self.__retryable = false;
@@ -265,7 +265,7 @@ async function __threadHasImagePlaceholder_impl() {
265
265
  }
266
266
  }
267
267
  ]);
268
- await runner.loop(3, __stack.locals.threads.value, async (info, _, runner2) => {
268
+ await runner.loop(3, async () => __stack.locals.threads.value, async (info, _, runner2) => {
269
269
  await runner2.step(0, async (runner3) => {
270
270
  __stack.locals.messages = await __call(getThread, {
271
271
  type: "positional",
@@ -281,7 +281,7 @@ async function __threadHasImagePlaceholder_impl() {
281
281
  {
282
282
  condition: async () => await isSuccess(__stack.locals.messages),
283
283
  body: async (runner3) => {
284
- await runner3.loop(0, __stack.locals.messages.value, async (message, _2, runner4) => {
284
+ await runner3.loop(0, async () => __stack.locals.messages.value, async (message, _2, runner4) => {
285
285
  await runner4.ifElse(0, [
286
286
  {
287
287
  condition: async () => __eq(message.role, `user`) && await __callMethod(message.content, "includes", {
@@ -347,7 +347,7 @@ graph.node("recommendedApprovesEveryRead", async (__state) => {
347
347
  }
348
348
  });
349
349
  });
350
- await runner.loop(1, __readStatic(GIT_READS, "GIT_READS", "dist/lib/agents/agency-agent/tests/gitPolicy.agency"), async (effect, _, runner2) => {
350
+ await runner.loop(1, async () => __readStatic(GIT_READS, "GIT_READS", "dist/lib/agents/agency-agent/tests/gitPolicy.agency"), async (effect, _, runner2) => {
351
351
  await runner2.ifElse(0, [
352
352
  {
353
353
  condition: async () => !__eq((await await __call(checkPolicy, {
@@ -448,7 +448,7 @@ graph.node("recommendedPromptsEveryWrite", async (__state) => {
448
448
  }
449
449
  });
450
450
  });
451
- await runner.loop(1, __readStatic(GIT_WRITES, "GIT_WRITES", "dist/lib/agents/agency-agent/tests/gitPolicy.agency"), async (effect, _, runner2) => {
451
+ await runner.loop(1, async () => __readStatic(GIT_WRITES, "GIT_WRITES", "dist/lib/agents/agency-agent/tests/gitPolicy.agency"), async (effect, _, runner2) => {
452
452
  await runner2.ifElse(0, [
453
453
  {
454
454
  condition: async () => __eq((await await __call(checkPolicy, {
@@ -551,7 +551,7 @@ graph.node("minimalApprovesNoGitRead", async (__state) => {
551
551
  });
552
552
  await runner.step(1, async (runner2) => {
553
553
  });
554
- await runner.loop(2, __readStatic(GIT_READS, "GIT_READS", "dist/lib/agents/agency-agent/tests/gitPolicy.agency"), async (effect, _, runner2) => {
554
+ await runner.loop(2, async () => __readStatic(GIT_READS, "GIT_READS", "dist/lib/agents/agency-agent/tests/gitPolicy.agency"), async (effect, _, runner2) => {
555
555
  await runner2.ifElse(0, [
556
556
  {
557
557
  condition: async () => __eq((await await __call(checkPolicy, {
@@ -0,0 +1,20 @@
1
+ // resolveMaxToolCallRounds: an explicit --max-tool-call-rounds always wins;
2
+ // otherwise one-shot runs get the higher default and interactive runs keep the
3
+ // compiled default (null).
4
+ import { resolveMaxToolCallRounds } from "../shared.agency"
5
+
6
+ node explicitWinsOverOneShot(): boolean {
7
+ return resolveMaxToolCallRounds(7, true) == 7
8
+ }
9
+
10
+ node oneShotDefaults50(): boolean {
11
+ return resolveMaxToolCallRounds(null, true) == 50
12
+ }
13
+
14
+ node explicitWinsOverInteractive(): boolean {
15
+ return resolveMaxToolCallRounds(3, false) == 3
16
+ }
17
+
18
+ node interactiveKeepsBaked(): boolean {
19
+ return resolveMaxToolCallRounds(null, false) == null
20
+ }