@arvo-tools/agentic 1.2.17 → 2.0.1
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 +241 -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 +174 -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 +6 -6
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,44 @@ 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
|
+
subject: param.permissionManagerContext.subject,
|
|
157
|
+
messages: messages_1,
|
|
158
|
+
system: param.system,
|
|
159
|
+
tools: param.tools,
|
|
160
|
+
span: span,
|
|
161
|
+
agentCycles: {
|
|
162
|
+
current: currentAgentCycleCount,
|
|
163
|
+
max: param.agentCycles.max,
|
|
164
|
+
exhausted: agentCycleQuotaExhausted,
|
|
165
|
+
},
|
|
166
|
+
tokenUsage: tokenUsage,
|
|
167
|
+
}))];
|
|
168
|
+
case 4:
|
|
169
|
+
messages_1 = _b.apply(_a, [(_p = (_3.sent())) !== null && _p !== void 0 ? _p : messages_1]);
|
|
170
|
+
return [3 /*break*/, 6];
|
|
171
|
+
case 5:
|
|
172
|
+
err_1 = _3.sent();
|
|
173
|
+
(0, arvo_core_1.logToSpan)({
|
|
174
|
+
level: 'INFO',
|
|
175
|
+
message: 'Error thrown by the preInferenceHook',
|
|
176
|
+
}, span);
|
|
177
|
+
(0, arvo_core_1.exceptionToSpan)(err_1, span);
|
|
178
|
+
return [3 /*break*/, 6];
|
|
179
|
+
case 6:
|
|
149
180
|
param.onStream({
|
|
150
181
|
type: lifecycle === 'init'
|
|
151
182
|
? 'agent.init'
|
|
@@ -154,25 +185,26 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
154
185
|
: 'agent.self.correction',
|
|
155
186
|
data: {
|
|
156
187
|
system: param.system,
|
|
157
|
-
messages:
|
|
188
|
+
messages: messages_1,
|
|
158
189
|
tools: param.tools.map(function (item) { return item.name; }),
|
|
159
190
|
llmResponseType: param.llmResponseType,
|
|
160
191
|
toolIteractionCycle: {
|
|
161
|
-
max: param.
|
|
162
|
-
current: param.
|
|
163
|
-
exhausted:
|
|
192
|
+
max: param.agentCycles.max,
|
|
193
|
+
current: param.agentCycles.current,
|
|
194
|
+
exhausted: agentCycleQuotaExhausted,
|
|
164
195
|
},
|
|
165
196
|
},
|
|
166
197
|
});
|
|
198
|
+
_d = (_c = types_js_1.AgentLLMIntegrationOutputSchema).parse;
|
|
167
199
|
return [4 /*yield*/, param.llm({
|
|
168
200
|
lifecycle: lifecycle,
|
|
169
201
|
system: param.system,
|
|
170
|
-
messages:
|
|
202
|
+
messages: messages_1,
|
|
171
203
|
tools: param.tools,
|
|
172
|
-
|
|
173
|
-
current:
|
|
174
|
-
max: param.
|
|
175
|
-
exhausted:
|
|
204
|
+
agentCycles: {
|
|
205
|
+
current: currentAgentCycleCount,
|
|
206
|
+
max: param.agentCycles.max,
|
|
207
|
+
exhausted: agentCycleQuotaExhausted,
|
|
176
208
|
},
|
|
177
209
|
outputFormat: {
|
|
178
210
|
type: param.llmResponseType,
|
|
@@ -180,18 +212,63 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
180
212
|
},
|
|
181
213
|
onStream: param.onStream,
|
|
182
214
|
}, { otelInfo: otelInfo })];
|
|
183
|
-
case
|
|
184
|
-
response =
|
|
185
|
-
|
|
215
|
+
case 7:
|
|
216
|
+
response = _d.apply(_c, [_3.sent()]);
|
|
217
|
+
currentAgentCycleCount++;
|
|
186
218
|
executionUnits += response.executionUnits;
|
|
187
219
|
tokenUsage.completion += response.usage.tokens.completion;
|
|
188
220
|
tokenUsage.prompt += response.usage.tokens.prompt;
|
|
221
|
+
if (!param.postInferenceHook) return [3 /*break*/, 12];
|
|
222
|
+
pihResult = void 0;
|
|
223
|
+
_3.label = 8;
|
|
224
|
+
case 8:
|
|
225
|
+
_3.trys.push([8, 10, , 11]);
|
|
226
|
+
return [4 /*yield*/, param.postInferenceHook({
|
|
227
|
+
subject: param.permissionManagerContext.subject,
|
|
228
|
+
inference: response,
|
|
229
|
+
span: span,
|
|
230
|
+
agentCycles: {
|
|
231
|
+
current: currentAgentCycleCount,
|
|
232
|
+
max: param.agentCycles.max,
|
|
233
|
+
exhausted: agentCycleQuotaExhausted,
|
|
234
|
+
},
|
|
235
|
+
tokenUsage: tokenUsage,
|
|
236
|
+
})];
|
|
237
|
+
case 9:
|
|
238
|
+
pihResult =
|
|
239
|
+
(_q = (_3.sent())) !== null && _q !== void 0 ? _q : undefined;
|
|
240
|
+
return [3 /*break*/, 11];
|
|
241
|
+
case 10:
|
|
242
|
+
err_2 = _3.sent();
|
|
243
|
+
(0, arvo_core_1.logToSpan)({
|
|
244
|
+
level: 'INFO',
|
|
245
|
+
message: 'Error thrown by the postInferenceHook',
|
|
246
|
+
}, span);
|
|
247
|
+
(0, arvo_core_1.exceptionToSpan)(err_2, span);
|
|
248
|
+
return [3 /*break*/, 11];
|
|
249
|
+
case 11:
|
|
250
|
+
if ((pihResult === null || pihResult === void 0 ? void 0 : pihResult.action) === 'RETRY') {
|
|
251
|
+
(0, arvo_core_1.logToSpan)({
|
|
252
|
+
level: 'INFO',
|
|
253
|
+
message: "RETRY actions issued by the postInferenceHook. Dropping all inference and re-doing inference",
|
|
254
|
+
}, span);
|
|
255
|
+
return [3 /*break*/, 2];
|
|
256
|
+
}
|
|
257
|
+
if ((pihResult === null || pihResult === void 0 ? void 0 : pihResult.action) === 'CIRCUIT_BREAK') {
|
|
258
|
+
(0, arvo_core_1.logToSpan)({
|
|
259
|
+
level: 'INFO',
|
|
260
|
+
message: "CIRCUIT_BREAK actions issued by the postInferenceHook. Dropping all inference and throwing the error issues by the hook",
|
|
261
|
+
}, span);
|
|
262
|
+
throw pihResult.error;
|
|
263
|
+
}
|
|
264
|
+
_3.label = 12;
|
|
265
|
+
case 12:
|
|
189
266
|
// Update the message seen count by one for all the
|
|
190
267
|
// messages which the LLM has seen
|
|
191
|
-
for (i = 0; i <
|
|
192
|
-
|
|
268
|
+
for (i = 0; i < messages_1.length; i++) {
|
|
269
|
+
messages_1[i].seenCount += 1;
|
|
193
270
|
}
|
|
194
|
-
if (!(response.type === 'tool_call')) return [3 /*break*/,
|
|
271
|
+
if (!(response.type === 'tool_call')) return [3 /*break*/, 31];
|
|
195
272
|
arvoToolCalls = [];
|
|
196
273
|
mcpToolResultPromises = [];
|
|
197
274
|
internalToolResultPromises = [];
|
|
@@ -214,17 +291,17 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
214
291
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
215
292
|
finally {
|
|
216
293
|
try {
|
|
217
|
-
if (prioritizedToolCalls_1_1 && !prioritizedToolCalls_1_1.done && (
|
|
294
|
+
if (prioritizedToolCalls_1_1 && !prioritizedToolCalls_1_1.done && (_j = prioritizedToolCalls_1.return)) _j.call(prioritizedToolCalls_1);
|
|
218
295
|
}
|
|
219
296
|
finally { if (e_3) throw e_3.error; }
|
|
220
297
|
}
|
|
221
|
-
return [4 /*yield*/, ((
|
|
298
|
+
return [4 /*yield*/, ((_r = param.permissionManager) === null || _r === void 0 ? void 0 : _r.get({
|
|
222
299
|
source: param.permissionManagerContext,
|
|
223
300
|
tools: toolPermissionRequest,
|
|
224
301
|
config: { otelInfo: otelInfo },
|
|
225
302
|
}))];
|
|
226
|
-
case
|
|
227
|
-
toolPermissionMap = (
|
|
303
|
+
case 13:
|
|
304
|
+
toolPermissionMap = (_s = (_3.sent())) !== null && _s !== void 0 ? _s : {};
|
|
228
305
|
toolsPendingPermission = {};
|
|
229
306
|
_loop_1 = function (item) {
|
|
230
307
|
param.onStream({
|
|
@@ -232,8 +309,8 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
232
309
|
data: {
|
|
233
310
|
tool: {
|
|
234
311
|
name: item.name,
|
|
235
|
-
kind: (
|
|
236
|
-
originalName: (
|
|
312
|
+
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',
|
|
313
|
+
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
314
|
},
|
|
238
315
|
usage: tokenUsage,
|
|
239
316
|
executionunits: executionUnits,
|
|
@@ -245,7 +322,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
245
322
|
name: item.name,
|
|
246
323
|
input: item.input,
|
|
247
324
|
};
|
|
248
|
-
|
|
325
|
+
messages_1.push({
|
|
249
326
|
role: 'assistant',
|
|
250
327
|
content: toolCallContent,
|
|
251
328
|
// This has been viewed by the LLM as it was generated by it
|
|
@@ -253,7 +330,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
253
330
|
});
|
|
254
331
|
var resolvedToolDef = nameToToolMap[item.name];
|
|
255
332
|
if (!resolvedToolDef) {
|
|
256
|
-
|
|
333
|
+
messages_1.push({
|
|
257
334
|
role: 'user',
|
|
258
335
|
content: {
|
|
259
336
|
type: 'tool_result',
|
|
@@ -266,7 +343,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
266
343
|
}
|
|
267
344
|
// Block tool call with explicit deny
|
|
268
345
|
if (toolPermissionMap[item.name] === 'DENIED') {
|
|
269
|
-
|
|
346
|
+
messages_1.push({
|
|
270
347
|
role: 'user',
|
|
271
348
|
content: {
|
|
272
349
|
type: 'tool_result',
|
|
@@ -314,7 +391,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
314
391
|
};
|
|
315
392
|
}
|
|
316
393
|
toolsPendingPermission[item.name].requests.push(item);
|
|
317
|
-
|
|
394
|
+
messages_1.push({
|
|
318
395
|
role: 'user',
|
|
319
396
|
content: {
|
|
320
397
|
type: 'tool_result',
|
|
@@ -379,7 +456,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
379
456
|
}
|
|
380
457
|
else if (resolvedToolDef.serverConfig.kind === 'internal') {
|
|
381
458
|
internalToolResultPromises.push((function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
382
|
-
var serverConfig,
|
|
459
|
+
var serverConfig, response_1, err_3;
|
|
383
460
|
var _a;
|
|
384
461
|
return __generator(this, function (_b) {
|
|
385
462
|
switch (_b.label) {
|
|
@@ -389,34 +466,71 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
389
466
|
serverConfig.contract.fn &&
|
|
390
467
|
typeof serverConfig.contract.fn === 'function')) {
|
|
391
468
|
return [2 /*return*/, {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
content:
|
|
469
|
+
role: 'user',
|
|
470
|
+
seenCount: 0,
|
|
471
|
+
content: {
|
|
472
|
+
type: 'tool_result',
|
|
473
|
+
toolUseId: item.toolUseId,
|
|
474
|
+
content: 'Invalid internal tool call',
|
|
475
|
+
},
|
|
395
476
|
}];
|
|
396
477
|
}
|
|
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
|
-
}); }))];
|
|
478
|
+
_b.label = 1;
|
|
403
479
|
case 1:
|
|
404
|
-
|
|
405
|
-
return [
|
|
406
|
-
|
|
480
|
+
_b.trys.push([1, 3, , 4]);
|
|
481
|
+
return [4 /*yield*/, serverConfig.contract.fn(item.input, {
|
|
482
|
+
otelInfo: otelInfo,
|
|
407
483
|
toolUseId: item.toolUseId,
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
484
|
+
})];
|
|
485
|
+
case 2:
|
|
486
|
+
response_1 = (_a = (_b.sent())) !== null && _a !== void 0 ? _a : null;
|
|
487
|
+
if (response_1 && 'messages' in response_1) {
|
|
488
|
+
return [2 /*return*/, response_1.messages];
|
|
489
|
+
}
|
|
490
|
+
if (response_1 && 'data' in response_1) {
|
|
491
|
+
return [2 /*return*/, {
|
|
492
|
+
role: 'user',
|
|
493
|
+
seenCount: 0,
|
|
494
|
+
content: {
|
|
495
|
+
type: 'tool_result',
|
|
496
|
+
toolUseId: item.toolUseId,
|
|
497
|
+
content: JSON.stringify(response_1.data),
|
|
498
|
+
},
|
|
499
|
+
}];
|
|
500
|
+
}
|
|
501
|
+
return [2 /*return*/, {
|
|
502
|
+
role: 'user',
|
|
503
|
+
seenCount: 0,
|
|
504
|
+
content: {
|
|
505
|
+
type: 'tool_result',
|
|
506
|
+
toolUseId: item.toolUseId,
|
|
507
|
+
content: 'Tool executed successfully.',
|
|
508
|
+
},
|
|
411
509
|
}];
|
|
510
|
+
case 3:
|
|
511
|
+
err_3 = _b.sent();
|
|
512
|
+
return [2 /*return*/, {
|
|
513
|
+
role: 'user',
|
|
514
|
+
seenCount: 0,
|
|
515
|
+
content: {
|
|
516
|
+
type: 'tool_result',
|
|
517
|
+
toolUseId: item.toolUseId,
|
|
518
|
+
content: JSON.stringify({
|
|
519
|
+
type: 'error',
|
|
520
|
+
name: err_3.name,
|
|
521
|
+
message: err_3.message,
|
|
522
|
+
}),
|
|
523
|
+
},
|
|
524
|
+
}];
|
|
525
|
+
case 4: return [2 /*return*/];
|
|
412
526
|
}
|
|
413
527
|
});
|
|
414
528
|
}); })());
|
|
415
529
|
}
|
|
416
530
|
else if (resolvedToolDef.serverConfig.kind === 'arvo') {
|
|
417
|
-
var zodParseResult = ((
|
|
531
|
+
var zodParseResult = ((_z = resolvedToolDef.serverConfig.contract) === null || _z === void 0 ? void 0 : _z.accepts.schema).safeParse(__assign(__assign({}, item.input), { parentSubject$$: null }));
|
|
418
532
|
if (zodParseResult === null || zodParseResult === void 0 ? void 0 : zodParseResult.error) {
|
|
419
|
-
|
|
533
|
+
messages_1.push({
|
|
420
534
|
role: 'user',
|
|
421
535
|
content: {
|
|
422
536
|
type: 'tool_result',
|
|
@@ -431,7 +545,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
431
545
|
});
|
|
432
546
|
}
|
|
433
547
|
else {
|
|
434
|
-
arvoToolCalls.push(__assign(__assign({}, toolCallContent), { input: zodParseResult.data, name: (
|
|
548
|
+
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
549
|
}
|
|
436
550
|
}
|
|
437
551
|
};
|
|
@@ -444,72 +558,79 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
444
558
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
445
559
|
finally {
|
|
446
560
|
try {
|
|
447
|
-
if (prioritizedToolCalls_2_1 && !prioritizedToolCalls_2_1.done && (
|
|
561
|
+
if (prioritizedToolCalls_2_1 && !prioritizedToolCalls_2_1.done && (_k = prioritizedToolCalls_2.return)) _k.call(prioritizedToolCalls_2);
|
|
448
562
|
}
|
|
449
563
|
finally { if (e_4) throw e_4.error; }
|
|
450
564
|
}
|
|
451
|
-
|
|
452
|
-
case
|
|
453
|
-
|
|
565
|
+
_3.label = 14;
|
|
566
|
+
case 14:
|
|
567
|
+
_3.trys.push([14, 19, 20, 21]);
|
|
454
568
|
e_1 = void 0;
|
|
455
569
|
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 =
|
|
570
|
+
case 15:
|
|
571
|
+
_e = (__values.apply(void 0, [_3.sent()])), _f = _e.next();
|
|
572
|
+
_3.label = 16;
|
|
573
|
+
case 16:
|
|
574
|
+
if (!!_f.done) return [3 /*break*/, 18];
|
|
575
|
+
item = _f.value;
|
|
576
|
+
messages_1.push({ role: 'user', content: item, seenCount: 0 });
|
|
577
|
+
_3.label = 17;
|
|
578
|
+
case 17:
|
|
579
|
+
_f = _e.next();
|
|
580
|
+
return [3 /*break*/, 16];
|
|
581
|
+
case 18: return [3 /*break*/, 21];
|
|
582
|
+
case 19:
|
|
583
|
+
e_1_1 = _3.sent();
|
|
470
584
|
e_1 = { error: e_1_1 };
|
|
471
|
-
return [3 /*break*/,
|
|
472
|
-
case
|
|
585
|
+
return [3 /*break*/, 21];
|
|
586
|
+
case 20:
|
|
473
587
|
try {
|
|
474
|
-
if (
|
|
588
|
+
if (_f && !_f.done && (_l = _e.return)) _l.call(_e);
|
|
475
589
|
}
|
|
476
590
|
finally { if (e_1) throw e_1.error; }
|
|
477
591
|
return [7 /*endfinally*/];
|
|
478
|
-
case
|
|
479
|
-
|
|
592
|
+
case 21:
|
|
593
|
+
_3.trys.push([21, 26, 27, 28]);
|
|
480
594
|
e_2 = void 0;
|
|
481
595
|
return [4 /*yield*/, Promise.all(internalToolResultPromises)];
|
|
482
|
-
case
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
case
|
|
486
|
-
if (!!
|
|
487
|
-
item =
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
596
|
+
case 22:
|
|
597
|
+
_g = (__values.apply(void 0, [_3.sent()])), _h = _g.next();
|
|
598
|
+
_3.label = 23;
|
|
599
|
+
case 23:
|
|
600
|
+
if (!!_h.done) return [3 /*break*/, 25];
|
|
601
|
+
item = _h.value;
|
|
602
|
+
if (Array.isArray(item)) {
|
|
603
|
+
item.forEach(function (i) {
|
|
604
|
+
messages_1.push(i);
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
messages_1.push(item);
|
|
609
|
+
}
|
|
610
|
+
_3.label = 24;
|
|
611
|
+
case 24:
|
|
612
|
+
_h = _g.next();
|
|
613
|
+
return [3 /*break*/, 23];
|
|
614
|
+
case 25: return [3 /*break*/, 28];
|
|
615
|
+
case 26:
|
|
616
|
+
e_2_1 = _3.sent();
|
|
496
617
|
e_2 = { error: e_2_1 };
|
|
497
|
-
return [3 /*break*/,
|
|
498
|
-
case
|
|
618
|
+
return [3 /*break*/, 28];
|
|
619
|
+
case 27:
|
|
499
620
|
try {
|
|
500
|
-
if (
|
|
621
|
+
if (_h && !_h.done && (_m = _g.return)) _m.call(_g);
|
|
501
622
|
}
|
|
502
623
|
finally { if (e_2) throw e_2.error; }
|
|
503
624
|
return [7 /*endfinally*/];
|
|
504
|
-
case
|
|
505
|
-
if (!(param.permissionManager && Object.keys(toolsPendingPermission).length)) return [3 /*break*/,
|
|
506
|
-
return [4 /*yield*/, ((
|
|
625
|
+
case 28:
|
|
626
|
+
if (!(param.permissionManager && Object.keys(toolsPendingPermission).length)) return [3 /*break*/, 30];
|
|
627
|
+
return [4 /*yield*/, ((_2 = param.permissionManager) === null || _2 === void 0 ? void 0 : _2.requestBuilder({
|
|
507
628
|
source: param.permissionManagerContext,
|
|
508
629
|
tools: toolsPendingPermission,
|
|
509
630
|
config: { otelInfo: otelInfo },
|
|
510
631
|
}))];
|
|
511
|
-
case
|
|
512
|
-
toolPermissionRequest_1 =
|
|
632
|
+
case 29:
|
|
633
|
+
toolPermissionRequest_1 = _3.sent();
|
|
513
634
|
arvoToolCalls.push({
|
|
514
635
|
type: 'tool_use',
|
|
515
636
|
name: param.permissionManager.contract.accepts.type,
|
|
@@ -551,8 +672,8 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
551
672
|
executionunits: executionUnits,
|
|
552
673
|
},
|
|
553
674
|
});
|
|
554
|
-
|
|
555
|
-
case
|
|
675
|
+
_3.label = 30;
|
|
676
|
+
case 30:
|
|
556
677
|
if (arvoToolCalls.length) {
|
|
557
678
|
param.onStream({
|
|
558
679
|
type: 'agent.tool.request.delegation',
|
|
@@ -563,11 +684,11 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
563
684
|
},
|
|
564
685
|
});
|
|
565
686
|
return [2 /*return*/, {
|
|
566
|
-
messages:
|
|
687
|
+
messages: messages_1,
|
|
567
688
|
toolCalls: arvoToolCalls,
|
|
568
|
-
|
|
569
|
-
current:
|
|
570
|
-
max: param.
|
|
689
|
+
agentCycles: {
|
|
690
|
+
current: currentAgentCycleCount,
|
|
691
|
+
max: param.agentCycles.max,
|
|
571
692
|
},
|
|
572
693
|
executionUnits: executionUnits,
|
|
573
694
|
tokenUsage: tokenUsage,
|
|
@@ -575,7 +696,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
575
696
|
}
|
|
576
697
|
lifecycle = 'tool_result';
|
|
577
698
|
return [3 /*break*/, 2];
|
|
578
|
-
case
|
|
699
|
+
case 31:
|
|
579
700
|
param.onStream({
|
|
580
701
|
type: 'agent.output.finalization',
|
|
581
702
|
data: {
|
|
@@ -585,10 +706,10 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
585
706
|
},
|
|
586
707
|
});
|
|
587
708
|
return [4 /*yield*/, param.outputBuilder(__assign(__assign({}, response), { outputFormat: param.outputFormat, span: span }))];
|
|
588
|
-
case
|
|
589
|
-
outputResult =
|
|
709
|
+
case 32:
|
|
710
|
+
outputResult = _3.sent();
|
|
590
711
|
if ('error' in outputResult && outputResult.error) {
|
|
591
|
-
|
|
712
|
+
messages_1.push({
|
|
592
713
|
role: 'assistant',
|
|
593
714
|
content: {
|
|
594
715
|
type: 'text',
|
|
@@ -597,7 +718,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
597
718
|
// This has been viewed by the LLM as it was generated by it
|
|
598
719
|
seenCount: 1,
|
|
599
720
|
});
|
|
600
|
-
|
|
721
|
+
messages_1.push({
|
|
601
722
|
role: 'user',
|
|
602
723
|
content: {
|
|
603
724
|
type: 'text',
|
|
@@ -613,7 +734,7 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
613
734
|
return [3 /*break*/, 2];
|
|
614
735
|
}
|
|
615
736
|
if ('data' in outputResult && outputResult.data) {
|
|
616
|
-
|
|
737
|
+
messages_1.push({
|
|
617
738
|
role: 'assistant',
|
|
618
739
|
content: {
|
|
619
740
|
type: 'text',
|
|
@@ -631,22 +752,22 @@ var agentLoop = function (param, config) { return __awaiter(void 0, void 0, void
|
|
|
631
752
|
},
|
|
632
753
|
});
|
|
633
754
|
return [2 /*return*/, {
|
|
634
|
-
messages:
|
|
755
|
+
messages: messages_1,
|
|
635
756
|
output: outputResult.data,
|
|
636
|
-
|
|
637
|
-
current:
|
|
638
|
-
max: param.
|
|
757
|
+
agentCycles: {
|
|
758
|
+
current: currentAgentCycleCount,
|
|
759
|
+
max: param.agentCycles.max,
|
|
639
760
|
},
|
|
640
761
|
executionUnits: executionUnits,
|
|
641
762
|
tokenUsage: tokenUsage,
|
|
642
763
|
}];
|
|
643
764
|
}
|
|
644
765
|
return [3 /*break*/, 2];
|
|
645
|
-
case
|
|
646
|
-
case
|
|
766
|
+
case 33: throw new Error("Tool calls exhausted the max quota: ".concat(currentAgentCycleCount));
|
|
767
|
+
case 34:
|
|
647
768
|
span.end();
|
|
648
769
|
return [7 /*endfinally*/];
|
|
649
|
-
case
|
|
770
|
+
case 35: return [2 /*return*/];
|
|
650
771
|
}
|
|
651
772
|
});
|
|
652
773
|
}); },
|