@arvo-tools/agentic 1.2.17 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/Agent/AgentDefaults.d.ts +4 -1
  2. package/dist/Agent/AgentDefaults.d.ts.map +1 -1
  3. package/dist/Agent/AgentDefaults.js +110 -73
  4. package/dist/Agent/AgentDefaults.js.map +1 -1
  5. package/dist/Agent/agentLoop.d.ts +19 -17
  6. package/dist/Agent/agentLoop.d.ts.map +1 -1
  7. package/dist/Agent/agentLoop.js +239 -120
  8. package/dist/Agent/agentLoop.js.map +1 -1
  9. package/dist/Agent/index.d.ts +91 -39
  10. package/dist/Agent/index.d.ts.map +1 -1
  11. package/dist/Agent/index.js +218 -146
  12. package/dist/Agent/index.js.map +1 -1
  13. package/dist/Agent/schema.d.ts +326 -22
  14. package/dist/Agent/schema.d.ts.map +1 -1
  15. package/dist/Agent/schema.js +23 -1
  16. package/dist/Agent/schema.js.map +1 -1
  17. package/dist/Agent/stream/schema.d.ts +39 -39
  18. package/dist/Agent/types.d.ts +170 -79
  19. package/dist/Agent/types.d.ts.map +1 -1
  20. package/dist/Agent/utils.d.ts +6 -0
  21. package/dist/Agent/utils.d.ts.map +1 -1
  22. package/dist/Agent/utils.js +10 -1
  23. package/dist/Agent/utils.js.map +1 -1
  24. package/dist/AgentTool/index.d.ts +2 -3
  25. package/dist/AgentTool/index.d.ts.map +1 -1
  26. package/dist/AgentTool/index.js +11 -7
  27. package/dist/AgentTool/index.js.map +1 -1
  28. package/dist/AgentTool/types.d.ts +27 -9
  29. package/dist/AgentTool/types.d.ts.map +1 -1
  30. package/dist/Integrations/MCPClient.d.ts +2 -2
  31. package/dist/Integrations/MCPClient.js +2 -2
  32. package/dist/Integrations/anthropic/index.d.ts.map +1 -1
  33. package/dist/Integrations/anthropic/index.js +3 -3
  34. package/dist/Integrations/anthropic/index.js.map +1 -1
  35. package/dist/Integrations/openai/index.d.ts.map +1 -1
  36. package/dist/Integrations/openai/index.js +3 -3
  37. package/dist/Integrations/openai/index.js.map +1 -1
  38. package/dist/Integrations/types.d.ts +89 -15
  39. package/dist/Integrations/types.d.ts.map +1 -1
  40. package/dist/Integrations/types.js +47 -0
  41. package/dist/Integrations/types.js.map +1 -1
  42. package/dist/SimplePermissionManager/contract.d.ts +4 -4
  43. package/dist/SimplePermissionManager/index.d.ts +12 -12
  44. package/dist/index.d.ts +3 -3
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +2 -1
  47. package/dist/index.js.map +1 -1
  48. package/package.json +6 -6
@@ -87,6 +87,8 @@ exports.agentLoop = void 0;
87
87
  var openinference_semantic_conventions_1 = require("@arizeai/openinference-semantic-conventions");
88
88
  var arvo_core_1 = require("arvo-core");
89
89
  var uuid_1 = require("uuid");
90
+ var types_js_1 = require("../Integrations/types.js");
91
+ var schema_js_1 = require("./schema.js");
90
92
  var utils_1 = require("./utils");
91
93
  /**
92
94
  * The Core Cognitive Loop of the Arvo Agent.
@@ -123,11 +125,11 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
123
125
  _a),
124
126
  },
125
127
  fn: function (span) { return __awaiter(void 0, void 0, void 0, function () {
126
- var otelInfo, nameToToolMap, lifecycle, executionUnits, tokenUsage, currentToolInteractionCount, messages, toolQuotaExhausted, response, i, arvoToolCalls, mcpToolResultPromises, internalToolResultPromises, prioritizedToolCalls, toolPermissionRequest, prioritizedToolCalls_1, prioritizedToolCalls_1_1, item, toolPermissionMap, toolsPendingPermission, _loop_1, prioritizedToolCalls_2, prioritizedToolCalls_2_1, item, _a, _b, item, e_1_1, _c, _d, item, e_2_1, toolPermissionRequest_1, outputResult;
127
- var e_3, _e, e_4, _f, e_1, _g, e_2, _h;
128
- var _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
129
- return __generator(this, function (_w) {
130
- switch (_w.label) {
128
+ var otelInfo, nameToToolMap, lifecycle, executionUnits, tokenUsage, currentAgentCycleCount, messages_1, agentCycleQuotaExhausted, _a, _b, err_1, response, _c, _d, pihResult, err_2, i, arvoToolCalls, mcpToolResultPromises, internalToolResultPromises, prioritizedToolCalls, toolPermissionRequest, prioritizedToolCalls_1, prioritizedToolCalls_1_1, item, toolPermissionMap, toolsPendingPermission, _loop_1, prioritizedToolCalls_2, prioritizedToolCalls_2_1, item, _e, _f, item, e_1_1, _g, _h, item, e_2_1, toolPermissionRequest_1, outputResult;
129
+ var e_3, _j, e_4, _k, e_1, _l, e_2, _m;
130
+ var _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
131
+ return __generator(this, function (_3) {
132
+ switch (_3.label) {
131
133
  case 0:
132
134
  otelInfo = {
133
135
  span: span,
@@ -137,15 +139,43 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
137
139
  lifecycle = param.initLifecycle;
138
140
  executionUnits = param.currentTotalExecutionUnits;
139
141
  tokenUsage = param.currentTotalUsageTokens;
140
- _w.label = 1;
142
+ _3.label = 1;
141
143
  case 1:
142
- _w.trys.push([1, , 25, 26]);
143
- currentToolInteractionCount = param.toolInteraction.current;
144
- messages = __spreadArray([], __read(param.messages), false);
145
- _w.label = 2;
144
+ _3.trys.push([1, , 34, 35]);
145
+ currentAgentCycleCount = param.agentCycles.current;
146
+ messages_1 = __spreadArray([], __read(param.messages), false);
147
+ _3.label = 2;
146
148
  case 2:
147
- if (!(currentToolInteractionCount <= param.toolInteraction.max)) return [3 /*break*/, 24];
148
- toolQuotaExhausted = !(currentToolInteractionCount < param.toolInteraction.max);
149
+ if (!(currentAgentCycleCount <= param.agentCycles.max)) return [3 /*break*/, 33];
150
+ agentCycleQuotaExhausted = !(currentAgentCycleCount < param.agentCycles.max);
151
+ _3.label = 3;
152
+ case 3:
153
+ _3.trys.push([3, 5, , 6]);
154
+ _b = (_a = schema_js_1.AgentMessageSchema.array()).parse;
155
+ return [4 /*yield*/, ((_o = param.preInferenceHook) === null || _o === void 0 ? void 0 : _o.call(param, {
156
+ messages: messages_1,
157
+ system: param.system,
158
+ tools: param.tools,
159
+ span: span,
160
+ agentCycles: {
161
+ current: currentAgentCycleCount,
162
+ max: param.agentCycles.max,
163
+ exhausted: agentCycleQuotaExhausted,
164
+ },
165
+ tokenUsage: tokenUsage,
166
+ }))];
167
+ case 4:
168
+ messages_1 = _b.apply(_a, [(_p = (_3.sent())) !== null && _p !== void 0 ? _p : messages_1]);
169
+ return [3 /*break*/, 6];
170
+ case 5:
171
+ err_1 = _3.sent();
172
+ (0, arvo_core_1.logToSpan)({
173
+ level: 'INFO',
174
+ message: 'Error thrown by the preInferenceHook',
175
+ }, span);
176
+ (0, arvo_core_1.exceptionToSpan)(err_1, span);
177
+ return [3 /*break*/, 6];
178
+ case 6:
149
179
  param.onStream({
150
180
  type: lifecycle === 'init'
151
181
  ? 'agent.init'
@@ -154,25 +184,26 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
154
184
  : 'agent.self.correction',
155
185
  data: {
156
186
  system: param.system,
157
- messages: messages,
187
+ messages: messages_1,
158
188
  tools: param.tools.map(function (item) { return item.name; }),
159
189
  llmResponseType: param.llmResponseType,
160
190
  toolIteractionCycle: {
161
- max: param.toolInteraction.max,
162
- current: param.toolInteraction.current,
163
- exhausted: toolQuotaExhausted,
191
+ max: param.agentCycles.max,
192
+ current: param.agentCycles.current,
193
+ exhausted: agentCycleQuotaExhausted,
164
194
  },
165
195
  },
166
196
  });
197
+ _d = (_c = types_js_1.AgentLLMIntegrationOutputSchema).parse;
167
198
  return [4 /*yield*/, param.llm({
168
199
  lifecycle: lifecycle,
169
200
  system: param.system,
170
- messages: messages,
201
+ messages: messages_1,
171
202
  tools: param.tools,
172
- toolInteractions: {
173
- current: currentToolInteractionCount,
174
- max: param.toolInteraction.max,
175
- exhausted: toolQuotaExhausted,
203
+ agentCycles: {
204
+ current: currentAgentCycleCount,
205
+ max: param.agentCycles.max,
206
+ exhausted: agentCycleQuotaExhausted,
176
207
  },
177
208
  outputFormat: {
178
209
  type: param.llmResponseType,
@@ -180,18 +211,62 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
180
211
  },
181
212
  onStream: param.onStream,
182
213
  }, { otelInfo: otelInfo })];
183
- case 3:
184
- response = _w.sent();
185
- currentToolInteractionCount++;
214
+ case 7:
215
+ response = _d.apply(_c, [_3.sent()]);
216
+ currentAgentCycleCount++;
186
217
  executionUnits += response.executionUnits;
187
218
  tokenUsage.completion += response.usage.tokens.completion;
188
219
  tokenUsage.prompt += response.usage.tokens.prompt;
220
+ if (!param.postInferenceHook) return [3 /*break*/, 12];
221
+ pihResult = void 0;
222
+ _3.label = 8;
223
+ case 8:
224
+ _3.trys.push([8, 10, , 11]);
225
+ return [4 /*yield*/, param.postInferenceHook({
226
+ inference: response,
227
+ span: span,
228
+ agentCycles: {
229
+ current: currentAgentCycleCount,
230
+ max: param.agentCycles.max,
231
+ exhausted: agentCycleQuotaExhausted,
232
+ },
233
+ tokenUsage: tokenUsage,
234
+ })];
235
+ case 9:
236
+ pihResult =
237
+ (_q = (_3.sent())) !== null && _q !== void 0 ? _q : undefined;
238
+ return [3 /*break*/, 11];
239
+ case 10:
240
+ err_2 = _3.sent();
241
+ (0, arvo_core_1.logToSpan)({
242
+ level: 'INFO',
243
+ message: 'Error thrown by the postInferenceHook',
244
+ }, span);
245
+ (0, arvo_core_1.exceptionToSpan)(err_2, span);
246
+ return [3 /*break*/, 11];
247
+ case 11:
248
+ if ((pihResult === null || pihResult === void 0 ? void 0 : pihResult.action) === 'RETRY') {
249
+ (0, arvo_core_1.logToSpan)({
250
+ level: 'INFO',
251
+ message: "RETRY actions issued by the postInferenceHook. Dropping all inference and re-doing inference",
252
+ }, span);
253
+ return [3 /*break*/, 2];
254
+ }
255
+ if ((pihResult === null || pihResult === void 0 ? void 0 : pihResult.action) === 'CIRCUIT_BREAK') {
256
+ (0, arvo_core_1.logToSpan)({
257
+ level: 'INFO',
258
+ message: "CIRCUIT_BREAK actions issued by the postInferenceHook. Dropping all inference and throwing the error issues by the hook",
259
+ }, span);
260
+ throw pihResult.error;
261
+ }
262
+ _3.label = 12;
263
+ case 12:
189
264
  // Update the message seen count by one for all the
190
265
  // messages which the LLM has seen
191
- for (i = 0; i < messages.length; i++) {
192
- messages[i].seenCount += 1;
266
+ for (i = 0; i < messages_1.length; i++) {
267
+ messages_1[i].seenCount += 1;
193
268
  }
194
- if (!(response.type === 'tool_call')) return [3 /*break*/, 22];
269
+ if (!(response.type === 'tool_call')) return [3 /*break*/, 31];
195
270
  arvoToolCalls = [];
196
271
  mcpToolResultPromises = [];
197
272
  internalToolResultPromises = [];
@@ -214,17 +289,17 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
214
289
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
215
290
  finally {
216
291
  try {
217
- if (prioritizedToolCalls_1_1 && !prioritizedToolCalls_1_1.done && (_e = prioritizedToolCalls_1.return)) _e.call(prioritizedToolCalls_1);
292
+ if (prioritizedToolCalls_1_1 && !prioritizedToolCalls_1_1.done && (_j = prioritizedToolCalls_1.return)) _j.call(prioritizedToolCalls_1);
218
293
  }
219
294
  finally { if (e_3) throw e_3.error; }
220
295
  }
221
- return [4 /*yield*/, ((_j = param.permissionManager) === null || _j === void 0 ? void 0 : _j.get({
296
+ return [4 /*yield*/, ((_r = param.permissionManager) === null || _r === void 0 ? void 0 : _r.get({
222
297
  source: param.permissionManagerContext,
223
298
  tools: toolPermissionRequest,
224
299
  config: { otelInfo: otelInfo },
225
300
  }))];
226
- case 4:
227
- toolPermissionMap = (_k = (_w.sent())) !== null && _k !== void 0 ? _k : {};
301
+ case 13:
302
+ toolPermissionMap = (_s = (_3.sent())) !== null && _s !== void 0 ? _s : {};
228
303
  toolsPendingPermission = {};
229
304
  _loop_1 = function (item) {
230
305
  param.onStream({
@@ -232,8 +307,8 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
232
307
  data: {
233
308
  tool: {
234
309
  name: item.name,
235
- kind: (_o = (_m = (_l = nameToToolMap[item.name]) === null || _l === void 0 ? void 0 : _l.serverConfig) === null || _m === void 0 ? void 0 : _m.kind) !== null && _o !== void 0 ? _o : 'unknown',
236
- originalName: (_r = (_q = (_p = nameToToolMap[item.name]) === null || _p === void 0 ? void 0 : _p.serverConfig) === null || _q === void 0 ? void 0 : _q.name) !== null && _r !== void 0 ? _r : 'unknown',
310
+ kind: (_v = (_u = (_t = nameToToolMap[item.name]) === null || _t === void 0 ? void 0 : _t.serverConfig) === null || _u === void 0 ? void 0 : _u.kind) !== null && _v !== void 0 ? _v : 'unknown',
311
+ originalName: (_y = (_x = (_w = nameToToolMap[item.name]) === null || _w === void 0 ? void 0 : _w.serverConfig) === null || _x === void 0 ? void 0 : _x.name) !== null && _y !== void 0 ? _y : 'unknown',
237
312
  },
238
313
  usage: tokenUsage,
239
314
  executionunits: executionUnits,
@@ -245,7 +320,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
245
320
  name: item.name,
246
321
  input: item.input,
247
322
  };
248
- messages.push({
323
+ messages_1.push({
249
324
  role: 'assistant',
250
325
  content: toolCallContent,
251
326
  // This has been viewed by the LLM as it was generated by it
@@ -253,7 +328,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
253
328
  });
254
329
  var resolvedToolDef = nameToToolMap[item.name];
255
330
  if (!resolvedToolDef) {
256
- messages.push({
331
+ messages_1.push({
257
332
  role: 'user',
258
333
  content: {
259
334
  type: 'tool_result',
@@ -266,7 +341,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
266
341
  }
267
342
  // Block tool call with explicit deny
268
343
  if (toolPermissionMap[item.name] === 'DENIED') {
269
- messages.push({
344
+ messages_1.push({
270
345
  role: 'user',
271
346
  content: {
272
347
  type: 'tool_result',
@@ -314,7 +389,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
314
389
  };
315
390
  }
316
391
  toolsPendingPermission[item.name].requests.push(item);
317
- messages.push({
392
+ messages_1.push({
318
393
  role: 'user',
319
394
  content: {
320
395
  type: 'tool_result',
@@ -379,7 +454,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
379
454
  }
380
455
  else if (resolvedToolDef.serverConfig.kind === 'internal') {
381
456
  internalToolResultPromises.push((function () { return __awaiter(void 0, void 0, void 0, function () {
382
- var serverConfig, response;
457
+ var serverConfig, response_1, err_3;
383
458
  var _a;
384
459
  return __generator(this, function (_b) {
385
460
  switch (_b.label) {
@@ -389,34 +464,71 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
389
464
  serverConfig.contract.fn &&
390
465
  typeof serverConfig.contract.fn === 'function')) {
391
466
  return [2 /*return*/, {
392
- type: 'tool_result',
393
- toolUseId: item.toolUseId,
394
- content: 'Invalid internal tool call',
467
+ role: 'user',
468
+ seenCount: 0,
469
+ content: {
470
+ type: 'tool_result',
471
+ toolUseId: item.toolUseId,
472
+ content: 'Invalid internal tool call',
473
+ },
395
474
  }];
396
475
  }
397
- return [4 /*yield*/, ((_a = serverConfig.contract
398
- .fn(item.input, { otelInfo: otelInfo })) === null || _a === void 0 ? void 0 : _a.catch(function (err) { return ({
399
- type: 'error',
400
- name: err.name,
401
- message: err.message,
402
- }); }))];
476
+ _b.label = 1;
403
477
  case 1:
404
- response = _b.sent();
405
- return [2 /*return*/, {
406
- type: 'tool_result',
478
+ _b.trys.push([1, 3, , 4]);
479
+ return [4 /*yield*/, serverConfig.contract.fn(item.input, {
480
+ otelInfo: otelInfo,
407
481
  toolUseId: item.toolUseId,
408
- content: response
409
- ? JSON.stringify(response)
410
- : 'No response available from the internal tool',
482
+ })];
483
+ case 2:
484
+ response_1 = (_a = (_b.sent())) !== null && _a !== void 0 ? _a : null;
485
+ if (response_1 && 'messages' in response_1) {
486
+ return [2 /*return*/, response_1.messages];
487
+ }
488
+ if (response_1 && 'data' in response_1) {
489
+ return [2 /*return*/, {
490
+ role: 'user',
491
+ seenCount: 0,
492
+ content: {
493
+ type: 'tool_result',
494
+ toolUseId: item.toolUseId,
495
+ content: JSON.stringify(response_1.data),
496
+ },
497
+ }];
498
+ }
499
+ return [2 /*return*/, {
500
+ role: 'user',
501
+ seenCount: 0,
502
+ content: {
503
+ type: 'tool_result',
504
+ toolUseId: item.toolUseId,
505
+ content: 'Tool executed successfully.',
506
+ },
411
507
  }];
508
+ case 3:
509
+ err_3 = _b.sent();
510
+ return [2 /*return*/, {
511
+ role: 'user',
512
+ seenCount: 0,
513
+ content: {
514
+ type: 'tool_result',
515
+ toolUseId: item.toolUseId,
516
+ content: JSON.stringify({
517
+ type: 'error',
518
+ name: err_3.name,
519
+ message: err_3.message,
520
+ }),
521
+ },
522
+ }];
523
+ case 4: return [2 /*return*/];
412
524
  }
413
525
  });
414
526
  }); })());
415
527
  }
416
528
  else if (resolvedToolDef.serverConfig.kind === 'arvo') {
417
- var zodParseResult = ((_s = resolvedToolDef.serverConfig.contract) === null || _s === void 0 ? void 0 : _s.accepts.schema).safeParse(__assign(__assign({}, item.input), { parentSubject$$: null }));
529
+ var zodParseResult = ((_z = resolvedToolDef.serverConfig.contract) === null || _z === void 0 ? void 0 : _z.accepts.schema).safeParse(__assign(__assign({}, item.input), { parentSubject$$: null }));
418
530
  if (zodParseResult === null || zodParseResult === void 0 ? void 0 : zodParseResult.error) {
419
- messages.push({
531
+ messages_1.push({
420
532
  role: 'user',
421
533
  content: {
422
534
  type: 'tool_result',
@@ -431,7 +543,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
431
543
  });
432
544
  }
433
545
  else {
434
- arvoToolCalls.push(__assign(__assign({}, toolCallContent), { input: zodParseResult.data, name: (_u = (_t = resolvedToolDef.serverConfig.contract) === null || _t === void 0 ? void 0 : _t.accepts.type) !== null && _u !== void 0 ? _u : resolvedToolDef.serverConfig.name }));
546
+ arvoToolCalls.push(__assign(__assign({}, toolCallContent), { input: zodParseResult.data, name: (_1 = (_0 = resolvedToolDef.serverConfig.contract) === null || _0 === void 0 ? void 0 : _0.accepts.type) !== null && _1 !== void 0 ? _1 : resolvedToolDef.serverConfig.name }));
435
547
  }
436
548
  }
437
549
  };
@@ -444,72 +556,79 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
444
556
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
445
557
  finally {
446
558
  try {
447
- if (prioritizedToolCalls_2_1 && !prioritizedToolCalls_2_1.done && (_f = prioritizedToolCalls_2.return)) _f.call(prioritizedToolCalls_2);
559
+ if (prioritizedToolCalls_2_1 && !prioritizedToolCalls_2_1.done && (_k = prioritizedToolCalls_2.return)) _k.call(prioritizedToolCalls_2);
448
560
  }
449
561
  finally { if (e_4) throw e_4.error; }
450
562
  }
451
- _w.label = 5;
452
- case 5:
453
- _w.trys.push([5, 10, 11, 12]);
563
+ _3.label = 14;
564
+ case 14:
565
+ _3.trys.push([14, 19, 20, 21]);
454
566
  e_1 = void 0;
455
567
  return [4 /*yield*/, Promise.all(mcpToolResultPromises)];
456
- case 6:
457
- _a = (__values.apply(void 0, [_w.sent()])), _b = _a.next();
458
- _w.label = 7;
459
- case 7:
460
- if (!!_b.done) return [3 /*break*/, 9];
461
- item = _b.value;
462
- messages.push({ role: 'user', content: item, seenCount: 0 });
463
- _w.label = 8;
464
- case 8:
465
- _b = _a.next();
466
- return [3 /*break*/, 7];
467
- case 9: return [3 /*break*/, 12];
468
- case 10:
469
- e_1_1 = _w.sent();
568
+ case 15:
569
+ _e = (__values.apply(void 0, [_3.sent()])), _f = _e.next();
570
+ _3.label = 16;
571
+ case 16:
572
+ if (!!_f.done) return [3 /*break*/, 18];
573
+ item = _f.value;
574
+ messages_1.push({ role: 'user', content: item, seenCount: 0 });
575
+ _3.label = 17;
576
+ case 17:
577
+ _f = _e.next();
578
+ return [3 /*break*/, 16];
579
+ case 18: return [3 /*break*/, 21];
580
+ case 19:
581
+ e_1_1 = _3.sent();
470
582
  e_1 = { error: e_1_1 };
471
- return [3 /*break*/, 12];
472
- case 11:
583
+ return [3 /*break*/, 21];
584
+ case 20:
473
585
  try {
474
- if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
586
+ if (_f && !_f.done && (_l = _e.return)) _l.call(_e);
475
587
  }
476
588
  finally { if (e_1) throw e_1.error; }
477
589
  return [7 /*endfinally*/];
478
- case 12:
479
- _w.trys.push([12, 17, 18, 19]);
590
+ case 21:
591
+ _3.trys.push([21, 26, 27, 28]);
480
592
  e_2 = void 0;
481
593
  return [4 /*yield*/, Promise.all(internalToolResultPromises)];
482
- case 13:
483
- _c = (__values.apply(void 0, [_w.sent()])), _d = _c.next();
484
- _w.label = 14;
485
- case 14:
486
- if (!!_d.done) return [3 /*break*/, 16];
487
- item = _d.value;
488
- messages.push({ role: 'user', content: item, seenCount: 0 });
489
- _w.label = 15;
490
- case 15:
491
- _d = _c.next();
492
- return [3 /*break*/, 14];
493
- case 16: return [3 /*break*/, 19];
494
- case 17:
495
- e_2_1 = _w.sent();
594
+ case 22:
595
+ _g = (__values.apply(void 0, [_3.sent()])), _h = _g.next();
596
+ _3.label = 23;
597
+ case 23:
598
+ if (!!_h.done) return [3 /*break*/, 25];
599
+ item = _h.value;
600
+ if (Array.isArray(item)) {
601
+ item.forEach(function (i) {
602
+ messages_1.push(i);
603
+ });
604
+ }
605
+ else {
606
+ messages_1.push(item);
607
+ }
608
+ _3.label = 24;
609
+ case 24:
610
+ _h = _g.next();
611
+ return [3 /*break*/, 23];
612
+ case 25: return [3 /*break*/, 28];
613
+ case 26:
614
+ e_2_1 = _3.sent();
496
615
  e_2 = { error: e_2_1 };
497
- return [3 /*break*/, 19];
498
- case 18:
616
+ return [3 /*break*/, 28];
617
+ case 27:
499
618
  try {
500
- if (_d && !_d.done && (_h = _c.return)) _h.call(_c);
619
+ if (_h && !_h.done && (_m = _g.return)) _m.call(_g);
501
620
  }
502
621
  finally { if (e_2) throw e_2.error; }
503
622
  return [7 /*endfinally*/];
504
- case 19:
505
- if (!(param.permissionManager && Object.keys(toolsPendingPermission).length)) return [3 /*break*/, 21];
506
- return [4 /*yield*/, ((_v = param.permissionManager) === null || _v === void 0 ? void 0 : _v.requestBuilder({
623
+ case 28:
624
+ if (!(param.permissionManager && Object.keys(toolsPendingPermission).length)) return [3 /*break*/, 30];
625
+ return [4 /*yield*/, ((_2 = param.permissionManager) === null || _2 === void 0 ? void 0 : _2.requestBuilder({
507
626
  source: param.permissionManagerContext,
508
627
  tools: toolsPendingPermission,
509
628
  config: { otelInfo: otelInfo },
510
629
  }))];
511
- case 20:
512
- toolPermissionRequest_1 = _w.sent();
630
+ case 29:
631
+ toolPermissionRequest_1 = _3.sent();
513
632
  arvoToolCalls.push({
514
633
  type: 'tool_use',
515
634
  name: param.permissionManager.contract.accepts.type,
@@ -551,8 +670,8 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
551
670
  executionunits: executionUnits,
552
671
  },
553
672
  });
554
- _w.label = 21;
555
- case 21:
673
+ _3.label = 30;
674
+ case 30:
556
675
  if (arvoToolCalls.length) {
557
676
  param.onStream({
558
677
  type: 'agent.tool.request.delegation',
@@ -563,11 +682,11 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
563
682
  },
564
683
  });
565
684
  return [2 /*return*/, {
566
- messages: messages,
685
+ messages: messages_1,
567
686
  toolCalls: arvoToolCalls,
568
- toolInteractions: {
569
- current: currentToolInteractionCount,
570
- max: param.toolInteraction.max,
687
+ agentCycles: {
688
+ current: currentAgentCycleCount,
689
+ max: param.agentCycles.max,
571
690
  },
572
691
  executionUnits: executionUnits,
573
692
  tokenUsage: tokenUsage,
@@ -575,7 +694,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
575
694
  }
576
695
  lifecycle = 'tool_result';
577
696
  return [3 /*break*/, 2];
578
- case 22:
697
+ case 31:
579
698
  param.onStream({
580
699
  type: 'agent.output.finalization',
581
700
  data: {
@@ -585,10 +704,10 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
585
704
  },
586
705
  });
587
706
  return [4 /*yield*/, param.outputBuilder(__assign(__assign({}, response), { outputFormat: param.outputFormat, span: span }))];
588
- case 23:
589
- outputResult = _w.sent();
707
+ case 32:
708
+ outputResult = _3.sent();
590
709
  if ('error' in outputResult && outputResult.error) {
591
- messages.push({
710
+ messages_1.push({
592
711
  role: 'assistant',
593
712
  content: {
594
713
  type: 'text',
@@ -597,7 +716,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
597
716
  // This has been viewed by the LLM as it was generated by it
598
717
  seenCount: 1,
599
718
  });
600
- messages.push({
719
+ messages_1.push({
601
720
  role: 'user',
602
721
  content: {
603
722
  type: 'text',
@@ -613,7 +732,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
613
732
  return [3 /*break*/, 2];
614
733
  }
615
734
  if ('data' in outputResult && outputResult.data) {
616
- messages.push({
735
+ messages_1.push({
617
736
  role: 'assistant',
618
737
  content: {
619
738
  type: 'text',
@@ -631,22 +750,22 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
631
750
  },
632
751
  });
633
752
  return [2 /*return*/, {
634
- messages: messages,
753
+ messages: messages_1,
635
754
  output: outputResult.data,
636
- toolInteractions: {
637
- current: currentToolInteractionCount,
638
- max: param.toolInteraction.max,
755
+ agentCycles: {
756
+ current: currentAgentCycleCount,
757
+ max: param.agentCycles.max,
639
758
  },
640
759
  executionUnits: executionUnits,
641
760
  tokenUsage: tokenUsage,
642
761
  }];
643
762
  }
644
763
  return [3 /*break*/, 2];
645
- case 24: throw new Error("Tool calls exhausted the max quota: ".concat(currentToolInteractionCount));
646
- case 25:
764
+ case 33: throw new Error("Tool calls exhausted the max quota: ".concat(currentAgentCycleCount));
765
+ case 34:
647
766
  span.end();
648
767
  return [7 /*endfinally*/];
649
- case 26: return [2 /*return*/];
768
+ case 35: return [2 /*return*/];
650
769
  }
651
770
  });
652
771
  }); },