agent-swarm-kit 1.0.151 → 1.0.152

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/build/index.cjs CHANGED
@@ -1501,7 +1501,7 @@ var CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT = functoolsKit.str.newline("Please
1501
1501
  /**
1502
1502
  * @description custom function to fix the model
1503
1503
  */
1504
- var CC_TOOL_CALL_EXCEPTION_CUSTOM_FUNCTION = function () { return Promise.resolve(); };
1504
+ var CC_TOOL_CALL_EXCEPTION_CUSTOM_FUNCTION = function () { return Promise.resolve(null); };
1505
1505
  /**
1506
1506
  * @description When the model output is empty just say hello to the customer
1507
1507
  */
@@ -2305,7 +2305,7 @@ var ClientAgent = /** @class */ (function () {
2305
2305
  */
2306
2306
  ClientAgent.prototype._resurrectModel = function (mode_1) {
2307
2307
  return __awaiter(this, arguments, void 0, function (mode, reason) {
2308
- var rawMessage, content, message, result, validation, content;
2308
+ var placeholder, rawMessage, message, result, validation;
2309
2309
  var _a;
2310
2310
  if (reason === void 0) { reason = "unknown"; }
2311
2311
  return __generator(this, function (_b) {
@@ -2314,27 +2314,22 @@ var ClientAgent = /** @class */ (function () {
2314
2314
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2315
2315
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel"));
2316
2316
  console.warn("agent-swarm model ressurect for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY, " reason=").concat(reason));
2317
+ placeholder = createPlaceholder();
2317
2318
  this.params.onResurrect &&
2318
2319
  this.params.onResurrect(this.params.clientId, this.params.agentName, mode, reason);
2319
- if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "recomplete")) return [3 /*break*/, 2];
2320
- return [4 /*yield*/, this.params.history.push({
2321
- role: "user",
2322
- mode: "tool",
2323
- agentName: this.params.agentName,
2324
- content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
2325
- })];
2326
- case 1:
2327
- _b.sent();
2328
- return [3 /*break*/, 8];
2329
- case 2:
2330
- if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "flush")) return [3 /*break*/, 5];
2320
+ if (GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "recomplete") {
2321
+ console.warn("agent-swarm model ressurect did not solved the problem (still being called after recomplete patch) for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY));
2322
+ }
2323
+ else if (GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "custom") {
2324
+ console.warn("agent-swarm model ressurect did not solved the problem (still being called after patchedMessage emit) for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY));
2325
+ }
2331
2326
  return [4 /*yield*/, this.params.history.push({
2332
2327
  role: "resque",
2333
2328
  mode: "tool",
2334
2329
  agentName: this.params.agentName,
2335
- content: reason || "Unknown error",
2330
+ content: reason || "_resurrectModel call",
2336
2331
  })];
2337
- case 3:
2332
+ case 1:
2338
2333
  _b.sent();
2339
2334
  return [4 /*yield*/, this.params.history.push({
2340
2335
  role: "user",
@@ -2342,85 +2337,57 @@ var ClientAgent = /** @class */ (function () {
2342
2337
  agentName: this.params.agentName,
2343
2338
  content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_FLUSH_PROMPT,
2344
2339
  })];
2345
- case 4:
2346
- _b.sent();
2347
- return [3 /*break*/, 8];
2348
- case 5:
2349
- if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "custom")) return [3 /*break*/, 7];
2350
- return [4 /*yield*/, GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_CUSTOM_FUNCTION(this.params.clientId, this.params.agentName)];
2351
- case 6:
2340
+ case 2:
2352
2341
  _b.sent();
2353
- return [3 /*break*/, 8];
2354
- case 7: throw new Error("agent-swarm _resurrectModel invalid strategy value=".concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY, " agentName=").concat(this.params.agentName, " clientId=").concat(this.params.clientId));
2355
- case 8: return [4 /*yield*/, this.getCompletion(mode)];
2356
- case 9:
2342
+ return [4 /*yield*/, this.getCompletion(mode)];
2343
+ case 3:
2357
2344
  rawMessage = _b.sent();
2358
- if (!((_a = rawMessage.tool_calls) === null || _a === void 0 ? void 0 : _a.length)) return [3 /*break*/, 13];
2345
+ if (!((_a = rawMessage.tool_calls) === null || _a === void 0 ? void 0 : _a.length)) return [3 /*break*/, 6];
2359
2346
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2360
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel failed due to tool_calls"));
2361
- console.warn("agent-swarm model ressurect did not solved the problem (tool_calls) for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY));
2362
- content = createPlaceholder();
2347
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel should not emit tool_calls"));
2348
+ console.warn("agent-swarm _resurrectModel should not emit tool_calls for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY));
2363
2349
  return [4 /*yield*/, this.params.history.push({
2364
2350
  role: "resque",
2365
2351
  mode: "tool",
2366
2352
  agentName: this.params.agentName,
2367
- content: reason || "Unknown error",
2368
- })];
2369
- case 10:
2370
- _b.sent();
2371
- return [4 /*yield*/, this.params.history.push({
2372
- agentName: this.params.agentName,
2373
- role: "assistant",
2374
- mode: "tool",
2375
- content: content,
2353
+ content: "_resurrectModel should not emit tool calls",
2376
2354
  })];
2377
- case 11:
2355
+ case 4:
2378
2356
  _b.sent();
2379
2357
  return [4 /*yield*/, this._resqueSubject.next(MODEL_RESQUE_SYMBOL)];
2380
- case 12:
2358
+ case 5:
2381
2359
  _b.sent();
2382
- return [2 /*return*/, content];
2383
- case 13: return [4 /*yield*/, this.params.map(rawMessage, this.params.clientId, this.params.agentName)];
2384
- case 14:
2360
+ return [2 /*return*/, placeholder];
2361
+ case 6: return [4 /*yield*/, this.params.map(rawMessage, this.params.clientId, this.params.agentName)];
2362
+ case 7:
2385
2363
  message = _b.sent();
2386
2364
  return [4 /*yield*/, this.params.transform(message.content, this.params.clientId, this.params.agentName)];
2387
- case 15:
2365
+ case 8:
2388
2366
  result = _b.sent();
2389
2367
  validation = null;
2390
2368
  return [4 /*yield*/, this.params.validate(result)];
2391
- case 16:
2392
- if (!(validation = _b.sent())) return [3 /*break*/, 20];
2369
+ case 9:
2370
+ if (!(validation = _b.sent())) return [3 /*break*/, 11];
2393
2371
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2394
2372
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel validation error: ").concat(validation));
2395
- console.warn("agent-swarm model ressurect did not solved the problem for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY));
2396
- content = createPlaceholder();
2373
+ console.warn("agent-swarm model ressurect did not solved the problem for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY, " validation=").concat(validation));
2397
2374
  return [4 /*yield*/, this.params.history.push({
2398
2375
  role: "resque",
2399
2376
  mode: "tool",
2400
2377
  agentName: this.params.agentName,
2401
- content: reason || "Unknown error",
2402
- })];
2403
- case 17:
2404
- _b.sent();
2405
- return [4 /*yield*/, this.params.history.push({
2406
- agentName: this.params.agentName,
2407
- role: "assistant",
2408
- mode: "tool",
2409
- content: content,
2378
+ content: "_resurrectModel failed validation: ".concat(validation),
2410
2379
  })];
2411
- case 18:
2412
- _b.sent();
2413
- return [4 /*yield*/, this._resqueSubject.next(MODEL_RESQUE_SYMBOL)];
2414
- case 19:
2380
+ case 10:
2415
2381
  _b.sent();
2416
- return [2 /*return*/, content];
2417
- case 20: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2418
- case 21:
2382
+ return [3 /*break*/, 13];
2383
+ case 11: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2384
+ case 12:
2419
2385
  _b.sent();
2420
- return [4 /*yield*/, this._resqueSubject.next(MODEL_RESQUE_SYMBOL)];
2421
- case 22:
2386
+ _b.label = 13;
2387
+ case 13: return [4 /*yield*/, this._resqueSubject.next(MODEL_RESQUE_SYMBOL)];
2388
+ case 14:
2422
2389
  _b.sent();
2423
- return [2 /*return*/, result];
2390
+ return [2 /*return*/, placeholder];
2424
2391
  }
2425
2392
  });
2426
2393
  });
@@ -2448,16 +2415,16 @@ var ClientAgent = /** @class */ (function () {
2448
2415
  */
2449
2416
  ClientAgent.prototype.getCompletion = function (mode) {
2450
2417
  return __awaiter(this, void 0, void 0, function () {
2451
- var messages, args, output;
2452
- var _a, _b, _c;
2453
- return __generator(this, function (_d) {
2454
- switch (_d.label) {
2418
+ var messages, args, output, message, result, validation, messages_1, args_1, output_1, output_2;
2419
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
2420
+ return __generator(this, function (_k) {
2421
+ switch (_k.label) {
2455
2422
  case 0:
2456
2423
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2457
2424
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " getCompletion"));
2458
2425
  return [4 /*yield*/, this.params.history.toArrayForAgent(this.params.prompt, this.params.system)];
2459
2426
  case 1:
2460
- messages = _d.sent();
2427
+ messages = _k.sent();
2461
2428
  args = {
2462
2429
  clientId: this.params.clientId,
2463
2430
  agentName: this.params.agentName,
@@ -2469,9 +2436,63 @@ var ClientAgent = /** @class */ (function () {
2469
2436
  };
2470
2437
  return [4 /*yield*/, this.params.completion.getCompletion(args)];
2471
2438
  case 2:
2472
- output = _d.sent();
2473
- ((_b = this.params.completion.callbacks) === null || _b === void 0 ? void 0 : _b.onComplete) &&
2474
- ((_c = this.params.completion.callbacks) === null || _c === void 0 ? void 0 : _c.onComplete(args, output));
2439
+ output = _k.sent();
2440
+ return [4 /*yield*/, this.params.map(output, this.params.clientId, this.params.agentName)];
2441
+ case 3:
2442
+ message = _k.sent();
2443
+ return [4 /*yield*/, this.params.transform(message.content, this.params.clientId, this.params.agentName)];
2444
+ case 4:
2445
+ result = _k.sent();
2446
+ if ((_b = message.tool_calls) === null || _b === void 0 ? void 0 : _b.length) {
2447
+ return [2 /*return*/, __assign(__assign({}, output), { content: output.content || "" })];
2448
+ }
2449
+ return [4 /*yield*/, this.params.validate(result)];
2450
+ case 5:
2451
+ validation = _k.sent();
2452
+ if (!!validation) return [3 /*break*/, 6];
2453
+ ((_c = this.params.completion.callbacks) === null || _c === void 0 ? void 0 : _c.onComplete) &&
2454
+ ((_d = this.params.completion.callbacks) === null || _d === void 0 ? void 0 : _d.onComplete(args, output));
2455
+ return [2 /*return*/, __assign(__assign({}, output), { content: output.content || "" })];
2456
+ case 6:
2457
+ if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "recomplete")) return [3 /*break*/, 10];
2458
+ console.warn("agent-swarm model using recomplete resurrect for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " validation=").concat(validation));
2459
+ return [4 /*yield*/, this.params.history.push({
2460
+ role: "user",
2461
+ mode: "tool",
2462
+ agentName: this.params.agentName,
2463
+ content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
2464
+ })];
2465
+ case 7:
2466
+ _k.sent();
2467
+ return [4 /*yield*/, this.params.history.toArrayForAgent(this.params.prompt, this.params.system)];
2468
+ case 8:
2469
+ messages_1 = _k.sent();
2470
+ args_1 = {
2471
+ clientId: this.params.clientId,
2472
+ agentName: this.params.agentName,
2473
+ messages: messages_1,
2474
+ mode: mode,
2475
+ tools: (_e = this.params.tools) === null || _e === void 0 ? void 0 : _e.map(function (t) {
2476
+ return lodashEs.omit(t, "toolName", "docNote", "call", "validate", "callbacks");
2477
+ }),
2478
+ };
2479
+ return [4 /*yield*/, this.params.completion.getCompletion(args_1)];
2480
+ case 9:
2481
+ output_1 = _k.sent();
2482
+ return [2 /*return*/, __assign(__assign({}, output_1), { content: output_1.content || "" })];
2483
+ case 10:
2484
+ if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "custom")) return [3 /*break*/, 12];
2485
+ console.warn("agent-swarm model using custom resurrect for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " validation=").concat(validation));
2486
+ return [4 /*yield*/, GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_CUSTOM_FUNCTION(this.params.clientId, this.params.agentName)];
2487
+ case 11:
2488
+ output_2 = _k.sent();
2489
+ ((_f = this.params.completion.callbacks) === null || _f === void 0 ? void 0 : _f.onComplete) &&
2490
+ ((_g = this.params.completion.callbacks) === null || _g === void 0 ? void 0 : _g.onComplete(args, output_2));
2491
+ return [2 /*return*/, output_2];
2492
+ case 12:
2493
+ console.warn("agent-swarm model completion pending resurrect for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY, " validation=").concat(validation));
2494
+ ((_h = this.params.completion.callbacks) === null || _h === void 0 ? void 0 : _h.onComplete) &&
2495
+ ((_j = this.params.completion.callbacks) === null || _j === void 0 ? void 0 : _j.onComplete(args, output));
2475
2496
  return [2 /*return*/, __assign(__assign({}, output), { content: output.content || "" })];
2476
2497
  }
2477
2498
  });
@@ -3057,7 +3078,7 @@ var ClientHistory = /** @class */ (function () {
3057
3078
  });
3058
3079
  };
3059
3080
  /**
3060
- * Pushes a message to the history.
3081
+ * Pop a message from the history.
3061
3082
  * @returns {Promise<IModelMessage | null>}
3062
3083
  */
3063
3084
  ClientHistory.prototype.pop = function () {
package/build/index.mjs CHANGED
@@ -1499,7 +1499,7 @@ var CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT = str.newline("Please analyze the l
1499
1499
  /**
1500
1500
  * @description custom function to fix the model
1501
1501
  */
1502
- var CC_TOOL_CALL_EXCEPTION_CUSTOM_FUNCTION = function () { return Promise.resolve(); };
1502
+ var CC_TOOL_CALL_EXCEPTION_CUSTOM_FUNCTION = function () { return Promise.resolve(null); };
1503
1503
  /**
1504
1504
  * @description When the model output is empty just say hello to the customer
1505
1505
  */
@@ -2303,7 +2303,7 @@ var ClientAgent = /** @class */ (function () {
2303
2303
  */
2304
2304
  ClientAgent.prototype._resurrectModel = function (mode_1) {
2305
2305
  return __awaiter(this, arguments, void 0, function (mode, reason) {
2306
- var rawMessage, content, message, result, validation, content;
2306
+ var placeholder, rawMessage, message, result, validation;
2307
2307
  var _a;
2308
2308
  if (reason === void 0) { reason = "unknown"; }
2309
2309
  return __generator(this, function (_b) {
@@ -2312,27 +2312,22 @@ var ClientAgent = /** @class */ (function () {
2312
2312
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2313
2313
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel"));
2314
2314
  console.warn("agent-swarm model ressurect for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY, " reason=").concat(reason));
2315
+ placeholder = createPlaceholder();
2315
2316
  this.params.onResurrect &&
2316
2317
  this.params.onResurrect(this.params.clientId, this.params.agentName, mode, reason);
2317
- if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "recomplete")) return [3 /*break*/, 2];
2318
- return [4 /*yield*/, this.params.history.push({
2319
- role: "user",
2320
- mode: "tool",
2321
- agentName: this.params.agentName,
2322
- content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
2323
- })];
2324
- case 1:
2325
- _b.sent();
2326
- return [3 /*break*/, 8];
2327
- case 2:
2328
- if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "flush")) return [3 /*break*/, 5];
2318
+ if (GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "recomplete") {
2319
+ console.warn("agent-swarm model ressurect did not solved the problem (still being called after recomplete patch) for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY));
2320
+ }
2321
+ else if (GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "custom") {
2322
+ console.warn("agent-swarm model ressurect did not solved the problem (still being called after patchedMessage emit) for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY));
2323
+ }
2329
2324
  return [4 /*yield*/, this.params.history.push({
2330
2325
  role: "resque",
2331
2326
  mode: "tool",
2332
2327
  agentName: this.params.agentName,
2333
- content: reason || "Unknown error",
2328
+ content: reason || "_resurrectModel call",
2334
2329
  })];
2335
- case 3:
2330
+ case 1:
2336
2331
  _b.sent();
2337
2332
  return [4 /*yield*/, this.params.history.push({
2338
2333
  role: "user",
@@ -2340,85 +2335,57 @@ var ClientAgent = /** @class */ (function () {
2340
2335
  agentName: this.params.agentName,
2341
2336
  content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_FLUSH_PROMPT,
2342
2337
  })];
2343
- case 4:
2344
- _b.sent();
2345
- return [3 /*break*/, 8];
2346
- case 5:
2347
- if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "custom")) return [3 /*break*/, 7];
2348
- return [4 /*yield*/, GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_CUSTOM_FUNCTION(this.params.clientId, this.params.agentName)];
2349
- case 6:
2338
+ case 2:
2350
2339
  _b.sent();
2351
- return [3 /*break*/, 8];
2352
- case 7: throw new Error("agent-swarm _resurrectModel invalid strategy value=".concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY, " agentName=").concat(this.params.agentName, " clientId=").concat(this.params.clientId));
2353
- case 8: return [4 /*yield*/, this.getCompletion(mode)];
2354
- case 9:
2340
+ return [4 /*yield*/, this.getCompletion(mode)];
2341
+ case 3:
2355
2342
  rawMessage = _b.sent();
2356
- if (!((_a = rawMessage.tool_calls) === null || _a === void 0 ? void 0 : _a.length)) return [3 /*break*/, 13];
2343
+ if (!((_a = rawMessage.tool_calls) === null || _a === void 0 ? void 0 : _a.length)) return [3 /*break*/, 6];
2357
2344
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2358
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel failed due to tool_calls"));
2359
- console.warn("agent-swarm model ressurect did not solved the problem (tool_calls) for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY));
2360
- content = createPlaceholder();
2345
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel should not emit tool_calls"));
2346
+ console.warn("agent-swarm _resurrectModel should not emit tool_calls for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY));
2361
2347
  return [4 /*yield*/, this.params.history.push({
2362
2348
  role: "resque",
2363
2349
  mode: "tool",
2364
2350
  agentName: this.params.agentName,
2365
- content: reason || "Unknown error",
2366
- })];
2367
- case 10:
2368
- _b.sent();
2369
- return [4 /*yield*/, this.params.history.push({
2370
- agentName: this.params.agentName,
2371
- role: "assistant",
2372
- mode: "tool",
2373
- content: content,
2351
+ content: "_resurrectModel should not emit tool calls",
2374
2352
  })];
2375
- case 11:
2353
+ case 4:
2376
2354
  _b.sent();
2377
2355
  return [4 /*yield*/, this._resqueSubject.next(MODEL_RESQUE_SYMBOL)];
2378
- case 12:
2356
+ case 5:
2379
2357
  _b.sent();
2380
- return [2 /*return*/, content];
2381
- case 13: return [4 /*yield*/, this.params.map(rawMessage, this.params.clientId, this.params.agentName)];
2382
- case 14:
2358
+ return [2 /*return*/, placeholder];
2359
+ case 6: return [4 /*yield*/, this.params.map(rawMessage, this.params.clientId, this.params.agentName)];
2360
+ case 7:
2383
2361
  message = _b.sent();
2384
2362
  return [4 /*yield*/, this.params.transform(message.content, this.params.clientId, this.params.agentName)];
2385
- case 15:
2363
+ case 8:
2386
2364
  result = _b.sent();
2387
2365
  validation = null;
2388
2366
  return [4 /*yield*/, this.params.validate(result)];
2389
- case 16:
2390
- if (!(validation = _b.sent())) return [3 /*break*/, 20];
2367
+ case 9:
2368
+ if (!(validation = _b.sent())) return [3 /*break*/, 11];
2391
2369
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2392
2370
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel validation error: ").concat(validation));
2393
- console.warn("agent-swarm model ressurect did not solved the problem for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY));
2394
- content = createPlaceholder();
2371
+ console.warn("agent-swarm model ressurect did not solved the problem for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY, " validation=").concat(validation));
2395
2372
  return [4 /*yield*/, this.params.history.push({
2396
2373
  role: "resque",
2397
2374
  mode: "tool",
2398
2375
  agentName: this.params.agentName,
2399
- content: reason || "Unknown error",
2400
- })];
2401
- case 17:
2402
- _b.sent();
2403
- return [4 /*yield*/, this.params.history.push({
2404
- agentName: this.params.agentName,
2405
- role: "assistant",
2406
- mode: "tool",
2407
- content: content,
2376
+ content: "_resurrectModel failed validation: ".concat(validation),
2408
2377
  })];
2409
- case 18:
2410
- _b.sent();
2411
- return [4 /*yield*/, this._resqueSubject.next(MODEL_RESQUE_SYMBOL)];
2412
- case 19:
2378
+ case 10:
2413
2379
  _b.sent();
2414
- return [2 /*return*/, content];
2415
- case 20: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2416
- case 21:
2380
+ return [3 /*break*/, 13];
2381
+ case 11: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2382
+ case 12:
2417
2383
  _b.sent();
2418
- return [4 /*yield*/, this._resqueSubject.next(MODEL_RESQUE_SYMBOL)];
2419
- case 22:
2384
+ _b.label = 13;
2385
+ case 13: return [4 /*yield*/, this._resqueSubject.next(MODEL_RESQUE_SYMBOL)];
2386
+ case 14:
2420
2387
  _b.sent();
2421
- return [2 /*return*/, result];
2388
+ return [2 /*return*/, placeholder];
2422
2389
  }
2423
2390
  });
2424
2391
  });
@@ -2446,16 +2413,16 @@ var ClientAgent = /** @class */ (function () {
2446
2413
  */
2447
2414
  ClientAgent.prototype.getCompletion = function (mode) {
2448
2415
  return __awaiter(this, void 0, void 0, function () {
2449
- var messages, args, output;
2450
- var _a, _b, _c;
2451
- return __generator(this, function (_d) {
2452
- switch (_d.label) {
2416
+ var messages, args, output, message, result, validation, messages_1, args_1, output_1, output_2;
2417
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
2418
+ return __generator(this, function (_k) {
2419
+ switch (_k.label) {
2453
2420
  case 0:
2454
2421
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2455
2422
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " getCompletion"));
2456
2423
  return [4 /*yield*/, this.params.history.toArrayForAgent(this.params.prompt, this.params.system)];
2457
2424
  case 1:
2458
- messages = _d.sent();
2425
+ messages = _k.sent();
2459
2426
  args = {
2460
2427
  clientId: this.params.clientId,
2461
2428
  agentName: this.params.agentName,
@@ -2467,9 +2434,63 @@ var ClientAgent = /** @class */ (function () {
2467
2434
  };
2468
2435
  return [4 /*yield*/, this.params.completion.getCompletion(args)];
2469
2436
  case 2:
2470
- output = _d.sent();
2471
- ((_b = this.params.completion.callbacks) === null || _b === void 0 ? void 0 : _b.onComplete) &&
2472
- ((_c = this.params.completion.callbacks) === null || _c === void 0 ? void 0 : _c.onComplete(args, output));
2437
+ output = _k.sent();
2438
+ return [4 /*yield*/, this.params.map(output, this.params.clientId, this.params.agentName)];
2439
+ case 3:
2440
+ message = _k.sent();
2441
+ return [4 /*yield*/, this.params.transform(message.content, this.params.clientId, this.params.agentName)];
2442
+ case 4:
2443
+ result = _k.sent();
2444
+ if ((_b = message.tool_calls) === null || _b === void 0 ? void 0 : _b.length) {
2445
+ return [2 /*return*/, __assign(__assign({}, output), { content: output.content || "" })];
2446
+ }
2447
+ return [4 /*yield*/, this.params.validate(result)];
2448
+ case 5:
2449
+ validation = _k.sent();
2450
+ if (!!validation) return [3 /*break*/, 6];
2451
+ ((_c = this.params.completion.callbacks) === null || _c === void 0 ? void 0 : _c.onComplete) &&
2452
+ ((_d = this.params.completion.callbacks) === null || _d === void 0 ? void 0 : _d.onComplete(args, output));
2453
+ return [2 /*return*/, __assign(__assign({}, output), { content: output.content || "" })];
2454
+ case 6:
2455
+ if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "recomplete")) return [3 /*break*/, 10];
2456
+ console.warn("agent-swarm model using recomplete resurrect for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " validation=").concat(validation));
2457
+ return [4 /*yield*/, this.params.history.push({
2458
+ role: "user",
2459
+ mode: "tool",
2460
+ agentName: this.params.agentName,
2461
+ content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
2462
+ })];
2463
+ case 7:
2464
+ _k.sent();
2465
+ return [4 /*yield*/, this.params.history.toArrayForAgent(this.params.prompt, this.params.system)];
2466
+ case 8:
2467
+ messages_1 = _k.sent();
2468
+ args_1 = {
2469
+ clientId: this.params.clientId,
2470
+ agentName: this.params.agentName,
2471
+ messages: messages_1,
2472
+ mode: mode,
2473
+ tools: (_e = this.params.tools) === null || _e === void 0 ? void 0 : _e.map(function (t) {
2474
+ return omit(t, "toolName", "docNote", "call", "validate", "callbacks");
2475
+ }),
2476
+ };
2477
+ return [4 /*yield*/, this.params.completion.getCompletion(args_1)];
2478
+ case 9:
2479
+ output_1 = _k.sent();
2480
+ return [2 /*return*/, __assign(__assign({}, output_1), { content: output_1.content || "" })];
2481
+ case 10:
2482
+ if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "custom")) return [3 /*break*/, 12];
2483
+ console.warn("agent-swarm model using custom resurrect for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " validation=").concat(validation));
2484
+ return [4 /*yield*/, GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_CUSTOM_FUNCTION(this.params.clientId, this.params.agentName)];
2485
+ case 11:
2486
+ output_2 = _k.sent();
2487
+ ((_f = this.params.completion.callbacks) === null || _f === void 0 ? void 0 : _f.onComplete) &&
2488
+ ((_g = this.params.completion.callbacks) === null || _g === void 0 ? void 0 : _g.onComplete(args, output_2));
2489
+ return [2 /*return*/, output_2];
2490
+ case 12:
2491
+ console.warn("agent-swarm model completion pending resurrect for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY, " validation=").concat(validation));
2492
+ ((_h = this.params.completion.callbacks) === null || _h === void 0 ? void 0 : _h.onComplete) &&
2493
+ ((_j = this.params.completion.callbacks) === null || _j === void 0 ? void 0 : _j.onComplete(args, output));
2473
2494
  return [2 /*return*/, __assign(__assign({}, output), { content: output.content || "" })];
2474
2495
  }
2475
2496
  });
@@ -3055,7 +3076,7 @@ var ClientHistory = /** @class */ (function () {
3055
3076
  });
3056
3077
  };
3057
3078
  /**
3058
- * Pushes a message to the history.
3079
+ * Pop a message from the history.
3059
3080
  * @returns {Promise<IModelMessage | null>}
3060
3081
  */
3061
3082
  ClientHistory.prototype.pop = function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.151",
3
+ "version": "1.0.152",
4
4
  "description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
package/types.d.ts CHANGED
@@ -2021,7 +2021,7 @@ declare class ClientHistory implements IHistory {
2021
2021
  */
2022
2022
  push(message: IModelMessage): Promise<void>;
2023
2023
  /**
2024
- * Pushes a message to the history.
2024
+ * Pop a message from the history.
2025
2025
  * @returns {Promise<IModelMessage | null>}
2026
2026
  */
2027
2027
  pop(): Promise<IModelMessage | null>;
@@ -5372,7 +5372,7 @@ declare const GLOBAL_CONFIG: {
5372
5372
  CC_FN_PLANTUML: (uml: string) => Promise<string>;
5373
5373
  CC_PROCESS_UUID: string;
5374
5374
  CC_BANHAMMER_PLACEHOLDER: string;
5375
- CC_TOOL_CALL_EXCEPTION_CUSTOM_FUNCTION: (clientId: string, agentName: AgentName) => Promise<void>;
5375
+ CC_TOOL_CALL_EXCEPTION_CUSTOM_FUNCTION: (clientId: string, agentName: AgentName) => Promise<IModelMessage | null>;
5376
5376
  };
5377
5377
  declare const setConfig: (config: Partial<typeof GLOBAL_CONFIG>) => void;
5378
5378