@arvo-tools/agentic 1.2.16 → 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.
- package/dist/Agent/AgentDefaults.d.ts +4 -1
- package/dist/Agent/AgentDefaults.d.ts.map +1 -1
- package/dist/Agent/AgentDefaults.js +110 -73
- package/dist/Agent/AgentDefaults.js.map +1 -1
- package/dist/Agent/agentLoop.d.ts +19 -17
- package/dist/Agent/agentLoop.d.ts.map +1 -1
- package/dist/Agent/agentLoop.js +239 -120
- package/dist/Agent/agentLoop.js.map +1 -1
- package/dist/Agent/index.d.ts +91 -39
- package/dist/Agent/index.d.ts.map +1 -1
- package/dist/Agent/index.js +218 -146
- package/dist/Agent/index.js.map +1 -1
- package/dist/Agent/schema.d.ts +326 -22
- package/dist/Agent/schema.d.ts.map +1 -1
- package/dist/Agent/schema.js +23 -1
- package/dist/Agent/schema.js.map +1 -1
- package/dist/Agent/stream/schema.d.ts +39 -39
- package/dist/Agent/types.d.ts +170 -79
- package/dist/Agent/types.d.ts.map +1 -1
- package/dist/Agent/utils.d.ts +6 -0
- package/dist/Agent/utils.d.ts.map +1 -1
- package/dist/Agent/utils.js +10 -1
- package/dist/Agent/utils.js.map +1 -1
- package/dist/AgentTool/index.d.ts +2 -3
- package/dist/AgentTool/index.d.ts.map +1 -1
- package/dist/AgentTool/index.js +11 -7
- package/dist/AgentTool/index.js.map +1 -1
- package/dist/AgentTool/types.d.ts +27 -9
- package/dist/AgentTool/types.d.ts.map +1 -1
- package/dist/Integrations/MCPClient.d.ts +2 -2
- package/dist/Integrations/MCPClient.js +2 -2
- package/dist/Integrations/anthropic/index.d.ts.map +1 -1
- package/dist/Integrations/anthropic/index.js +3 -3
- package/dist/Integrations/anthropic/index.js.map +1 -1
- package/dist/Integrations/openai/index.d.ts.map +1 -1
- package/dist/Integrations/openai/index.js +3 -3
- package/dist/Integrations/openai/index.js.map +1 -1
- package/dist/Integrations/types.d.ts +89 -15
- package/dist/Integrations/types.d.ts.map +1 -1
- package/dist/Integrations/types.js +47 -0
- package/dist/Integrations/types.js.map +1 -1
- package/dist/SimplePermissionManager/contract.d.ts +4 -4
- package/dist/SimplePermissionManager/index.d.ts +12 -12
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/Agent/agentLoop.js
CHANGED
|
@@ -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,
|
|
127
|
-
var e_3,
|
|
128
|
-
var
|
|
129
|
-
return __generator(this, function (
|
|
130
|
-
switch (
|
|
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
|
-
|
|
142
|
+
_3.label = 1;
|
|
141
143
|
case 1:
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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 (!(
|
|
148
|
-
|
|
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:
|
|
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.
|
|
162
|
-
current: param.
|
|
163
|
-
exhausted:
|
|
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:
|
|
201
|
+
messages: messages_1,
|
|
171
202
|
tools: param.tools,
|
|
172
|
-
|
|
173
|
-
current:
|
|
174
|
-
max: param.
|
|
175
|
-
exhausted:
|
|
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
|
|
184
|
-
response =
|
|
185
|
-
|
|
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 <
|
|
192
|
-
|
|
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*/,
|
|
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 && (
|
|
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*/, ((
|
|
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
|
|
227
|
-
toolPermissionMap = (
|
|
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: (
|
|
236
|
-
originalName: (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
393
|
-
|
|
394
|
-
content:
|
|
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
|
-
|
|
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
|
-
|
|
405
|
-
return [
|
|
406
|
-
|
|
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
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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 = ((
|
|
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
|
-
|
|
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: (
|
|
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 && (
|
|
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
|
-
|
|
452
|
-
case
|
|
453
|
-
|
|
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
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
case
|
|
460
|
-
if (!!
|
|
461
|
-
item =
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
case
|
|
465
|
-
|
|
466
|
-
return [3 /*break*/,
|
|
467
|
-
case
|
|
468
|
-
case
|
|
469
|
-
e_1_1 =
|
|
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*/,
|
|
472
|
-
case
|
|
583
|
+
return [3 /*break*/, 21];
|
|
584
|
+
case 20:
|
|
473
585
|
try {
|
|
474
|
-
if (
|
|
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
|
|
479
|
-
|
|
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
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
case
|
|
486
|
-
if (!!
|
|
487
|
-
item =
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
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*/,
|
|
498
|
-
case
|
|
616
|
+
return [3 /*break*/, 28];
|
|
617
|
+
case 27:
|
|
499
618
|
try {
|
|
500
|
-
if (
|
|
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
|
|
505
|
-
if (!(param.permissionManager && Object.keys(toolsPendingPermission).length)) return [3 /*break*/,
|
|
506
|
-
return [4 /*yield*/, ((
|
|
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
|
|
512
|
-
toolPermissionRequest_1 =
|
|
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
|
-
|
|
555
|
-
case
|
|
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:
|
|
685
|
+
messages: messages_1,
|
|
567
686
|
toolCalls: arvoToolCalls,
|
|
568
|
-
|
|
569
|
-
current:
|
|
570
|
-
max: param.
|
|
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
|
|
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
|
|
589
|
-
outputResult =
|
|
707
|
+
case 32:
|
|
708
|
+
outputResult = _3.sent();
|
|
590
709
|
if ('error' in outputResult && outputResult.error) {
|
|
591
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
753
|
+
messages: messages_1,
|
|
635
754
|
output: outputResult.data,
|
|
636
|
-
|
|
637
|
-
current:
|
|
638
|
-
max: param.
|
|
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
|
|
646
|
-
case
|
|
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
|
|
768
|
+
case 35: return [2 /*return*/];
|
|
650
769
|
}
|
|
651
770
|
});
|
|
652
771
|
}); },
|