agent-swarm-kit 1.0.29 → 1.0.30

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
@@ -438,7 +438,7 @@ var ClientAgent = /** @class */ (function () {
438
438
  * @returns {Promise<void>}
439
439
  * @private
440
440
  */
441
- this._emitOuput = function (result) { return __awaiter(_this, void 0, void 0, function () {
441
+ this._emitOuput = function (mode, result) { return __awaiter(_this, void 0, void 0, function () {
442
442
  var validation, result_1;
443
443
  return __generator(this, function (_a) {
444
444
  switch (_a.label) {
@@ -448,7 +448,7 @@ var ClientAgent = /** @class */ (function () {
448
448
  return [4 /*yield*/, this.params.validate(result)];
449
449
  case 1:
450
450
  if (!(validation = _a.sent())) return [3 /*break*/, 5];
451
- return [4 /*yield*/, this._resurrectModel(validation)];
451
+ return [4 /*yield*/, this._resurrectModel(mode, validation)];
452
452
  case 2:
453
453
  result_1 = _a.sent();
454
454
  return [4 /*yield*/, this.params.validate(result_1)];
@@ -473,7 +473,7 @@ var ClientAgent = /** @class */ (function () {
473
473
  * @returns {Promise<string>}
474
474
  * @private
475
475
  */
476
- this._resurrectModel = function (reason) { return __awaiter(_this, void 0, void 0, function () {
476
+ this._resurrectModel = function (mode, reason) { return __awaiter(_this, void 0, void 0, function () {
477
477
  var message, result, validation, content;
478
478
  return __generator(this, function (_a) {
479
479
  switch (_a.label) {
@@ -495,7 +495,7 @@ var ClientAgent = /** @class */ (function () {
495
495
  })];
496
496
  case 2:
497
497
  _a.sent();
498
- return [4 /*yield*/, this.getCompletion()];
498
+ return [4 /*yield*/, this.getCompletion(mode)];
499
499
  case 3:
500
500
  message = _a.sent();
501
501
  result = message.content;
@@ -539,7 +539,7 @@ var ClientAgent = /** @class */ (function () {
539
539
  * Gets the completion message from the model.
540
540
  * @returns {Promise<IModelMessage>}
541
541
  */
542
- this.getCompletion = function () { return __awaiter(_this, void 0, void 0, function () {
542
+ this.getCompletion = function (mode) { return __awaiter(_this, void 0, void 0, function () {
543
543
  var messages;
544
544
  var _a;
545
545
  return __generator(this, function (_b) {
@@ -553,6 +553,7 @@ var ClientAgent = /** @class */ (function () {
553
553
  clientId: this.params.clientId,
554
554
  agentName: this.params.agentName,
555
555
  messages: messages,
556
+ mode: mode,
556
557
  tools: (_a = this.params.tools) === null || _a === void 0 ? void 0 : _a.map(function (t) {
557
558
  return lodashEs.omit(t, "toolName", "call", "validate");
558
559
  }),
@@ -651,7 +652,7 @@ var ClientAgent = /** @class */ (function () {
651
652
  })];
652
653
  case 1:
653
654
  _e.sent();
654
- return [4 /*yield*/, this.getCompletion()];
655
+ return [4 /*yield*/, this.getCompletion(mode)];
655
656
  case 2:
656
657
  message = _e.sent();
657
658
  if (!message.tool_calls) return [3 /*break*/, 11];
@@ -667,11 +668,11 @@ var ClientAgent = /** @class */ (function () {
667
668
  _f.sent();
668
669
  if (!!targetFn) return [3 /*break*/, 4];
669
670
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool function not found"), this_1.params.tools);
670
- return [4 /*yield*/, this_1._resurrectModel("No target function for ".concat(tool.function.name))];
671
+ return [4 /*yield*/, this_1._resurrectModel(mode, "No target function for ".concat(tool.function.name))];
671
672
  case 2:
672
673
  result_2 = _f.sent();
673
674
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_2));
674
- return [4 /*yield*/, this_1._emitOuput(result_2)];
675
+ return [4 /*yield*/, this_1._emitOuput(mode, result_2)];
675
676
  case 3:
676
677
  _f.sent();
677
678
  return [2 /*return*/, { value: void 0 }];
@@ -679,11 +680,11 @@ var ClientAgent = /** @class */ (function () {
679
680
  case 5:
680
681
  if (!_f.sent()) return [3 /*break*/, 8];
681
682
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool validation not passed"));
682
- return [4 /*yield*/, this_1._resurrectModel("Function validation failed: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
683
+ return [4 /*yield*/, this_1._resurrectModel(mode, "Function validation failed: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
683
684
  case 6:
684
685
  result_3 = _f.sent();
685
686
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_3));
686
- return [4 /*yield*/, this_1._emitOuput(result_3)];
687
+ return [4 /*yield*/, this_1._emitOuput(mode, result_3)];
687
688
  case 7:
688
689
  _f.sent();
689
690
  return [2 /*return*/, { value: void 0 }];
@@ -747,16 +748,16 @@ var ClientAgent = /** @class */ (function () {
747
748
  case 13:
748
749
  if (!(validation = _e.sent())) return [3 /*break*/, 16];
749
750
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute invalid tool call detected: ").concat(validation), { result: result });
750
- return [4 /*yield*/, this._resurrectModel("Invalid model output: ".concat(result))];
751
+ return [4 /*yield*/, this._resurrectModel(mode, "Invalid model output: ".concat(result))];
751
752
  case 14:
752
753
  result1 = _e.sent();
753
- return [4 /*yield*/, this._emitOuput(result1)];
754
+ return [4 /*yield*/, this._emitOuput(mode, result1)];
754
755
  case 15:
755
756
  _e.sent();
756
757
  return [2 /*return*/];
757
758
  case 16:
758
759
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute end result=").concat(result));
759
- return [4 /*yield*/, this._emitOuput(result)];
760
+ return [4 /*yield*/, this._emitOuput(mode, result)];
760
761
  case 17:
761
762
  _e.sent();
762
763
  return [2 /*return*/];
package/build/index.mjs CHANGED
@@ -436,7 +436,7 @@ var ClientAgent = /** @class */ (function () {
436
436
  * @returns {Promise<void>}
437
437
  * @private
438
438
  */
439
- this._emitOuput = function (result) { return __awaiter(_this, void 0, void 0, function () {
439
+ this._emitOuput = function (mode, result) { return __awaiter(_this, void 0, void 0, function () {
440
440
  var validation, result_1;
441
441
  return __generator(this, function (_a) {
442
442
  switch (_a.label) {
@@ -446,7 +446,7 @@ var ClientAgent = /** @class */ (function () {
446
446
  return [4 /*yield*/, this.params.validate(result)];
447
447
  case 1:
448
448
  if (!(validation = _a.sent())) return [3 /*break*/, 5];
449
- return [4 /*yield*/, this._resurrectModel(validation)];
449
+ return [4 /*yield*/, this._resurrectModel(mode, validation)];
450
450
  case 2:
451
451
  result_1 = _a.sent();
452
452
  return [4 /*yield*/, this.params.validate(result_1)];
@@ -471,7 +471,7 @@ var ClientAgent = /** @class */ (function () {
471
471
  * @returns {Promise<string>}
472
472
  * @private
473
473
  */
474
- this._resurrectModel = function (reason) { return __awaiter(_this, void 0, void 0, function () {
474
+ this._resurrectModel = function (mode, reason) { return __awaiter(_this, void 0, void 0, function () {
475
475
  var message, result, validation, content;
476
476
  return __generator(this, function (_a) {
477
477
  switch (_a.label) {
@@ -493,7 +493,7 @@ var ClientAgent = /** @class */ (function () {
493
493
  })];
494
494
  case 2:
495
495
  _a.sent();
496
- return [4 /*yield*/, this.getCompletion()];
496
+ return [4 /*yield*/, this.getCompletion(mode)];
497
497
  case 3:
498
498
  message = _a.sent();
499
499
  result = message.content;
@@ -537,7 +537,7 @@ var ClientAgent = /** @class */ (function () {
537
537
  * Gets the completion message from the model.
538
538
  * @returns {Promise<IModelMessage>}
539
539
  */
540
- this.getCompletion = function () { return __awaiter(_this, void 0, void 0, function () {
540
+ this.getCompletion = function (mode) { return __awaiter(_this, void 0, void 0, function () {
541
541
  var messages;
542
542
  var _a;
543
543
  return __generator(this, function (_b) {
@@ -551,6 +551,7 @@ var ClientAgent = /** @class */ (function () {
551
551
  clientId: this.params.clientId,
552
552
  agentName: this.params.agentName,
553
553
  messages: messages,
554
+ mode: mode,
554
555
  tools: (_a = this.params.tools) === null || _a === void 0 ? void 0 : _a.map(function (t) {
555
556
  return omit(t, "toolName", "call", "validate");
556
557
  }),
@@ -649,7 +650,7 @@ var ClientAgent = /** @class */ (function () {
649
650
  })];
650
651
  case 1:
651
652
  _e.sent();
652
- return [4 /*yield*/, this.getCompletion()];
653
+ return [4 /*yield*/, this.getCompletion(mode)];
653
654
  case 2:
654
655
  message = _e.sent();
655
656
  if (!message.tool_calls) return [3 /*break*/, 11];
@@ -665,11 +666,11 @@ var ClientAgent = /** @class */ (function () {
665
666
  _f.sent();
666
667
  if (!!targetFn) return [3 /*break*/, 4];
667
668
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool function not found"), this_1.params.tools);
668
- return [4 /*yield*/, this_1._resurrectModel("No target function for ".concat(tool.function.name))];
669
+ return [4 /*yield*/, this_1._resurrectModel(mode, "No target function for ".concat(tool.function.name))];
669
670
  case 2:
670
671
  result_2 = _f.sent();
671
672
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_2));
672
- return [4 /*yield*/, this_1._emitOuput(result_2)];
673
+ return [4 /*yield*/, this_1._emitOuput(mode, result_2)];
673
674
  case 3:
674
675
  _f.sent();
675
676
  return [2 /*return*/, { value: void 0 }];
@@ -677,11 +678,11 @@ var ClientAgent = /** @class */ (function () {
677
678
  case 5:
678
679
  if (!_f.sent()) return [3 /*break*/, 8];
679
680
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool validation not passed"));
680
- return [4 /*yield*/, this_1._resurrectModel("Function validation failed: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
681
+ return [4 /*yield*/, this_1._resurrectModel(mode, "Function validation failed: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
681
682
  case 6:
682
683
  result_3 = _f.sent();
683
684
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_3));
684
- return [4 /*yield*/, this_1._emitOuput(result_3)];
685
+ return [4 /*yield*/, this_1._emitOuput(mode, result_3)];
685
686
  case 7:
686
687
  _f.sent();
687
688
  return [2 /*return*/, { value: void 0 }];
@@ -745,16 +746,16 @@ var ClientAgent = /** @class */ (function () {
745
746
  case 13:
746
747
  if (!(validation = _e.sent())) return [3 /*break*/, 16];
747
748
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute invalid tool call detected: ").concat(validation), { result: result });
748
- return [4 /*yield*/, this._resurrectModel("Invalid model output: ".concat(result))];
749
+ return [4 /*yield*/, this._resurrectModel(mode, "Invalid model output: ".concat(result))];
749
750
  case 14:
750
751
  result1 = _e.sent();
751
- return [4 /*yield*/, this._emitOuput(result1)];
752
+ return [4 /*yield*/, this._emitOuput(mode, result1)];
752
753
  case 15:
753
754
  _e.sent();
754
755
  return [2 /*return*/];
755
756
  case 16:
756
757
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute end result=").concat(result));
757
- return [4 /*yield*/, this._emitOuput(result)];
758
+ return [4 /*yield*/, this._emitOuput(mode, result)];
758
759
  case 17:
759
760
  _e.sent();
760
761
  return [2 /*return*/];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.29",
3
+ "version": "1.0.30",
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
@@ -179,52 +179,6 @@ interface ITool {
179
179
  };
180
180
  }
181
181
 
182
- /**
183
- * Interface representing a completion.
184
- */
185
- interface ICompletion extends ICompletionSchema {
186
- }
187
- /**
188
- * Arguments required to get a completion.
189
- */
190
- interface ICompletionArgs {
191
- /**
192
- * Client ID.
193
- */
194
- clientId: string;
195
- /**
196
- * Name of the agent.
197
- */
198
- agentName: AgentName;
199
- /**
200
- * Array of model messages.
201
- */
202
- messages: IModelMessage[];
203
- /**
204
- * Optional array of tools.
205
- */
206
- tools?: ITool[];
207
- }
208
- /**
209
- * Schema for a completion.
210
- */
211
- interface ICompletionSchema {
212
- /**
213
- * Name of the completion.
214
- */
215
- completionName: CompletionName;
216
- /**
217
- * Method to get a completion.
218
- * @param args - Arguments required to get a completion.
219
- * @returns A promise that resolves to a model message.
220
- */
221
- getCompletion(args: ICompletionArgs): Promise<IModelMessage>;
222
- }
223
- /**
224
- * Type representing the name of a completion.
225
- */
226
- type CompletionName = string;
227
-
228
182
  /**
229
183
  * Interface representing an incoming message.
230
184
  */
@@ -415,6 +369,56 @@ type SessionMode = "session" | "makeConnection" | "complete";
415
369
  */
416
370
  type ExecutionMode = "tool" | "user";
417
371
 
372
+ /**
373
+ * Interface representing a completion.
374
+ */
375
+ interface ICompletion extends ICompletionSchema {
376
+ }
377
+ /**
378
+ * Arguments required to get a completion.
379
+ */
380
+ interface ICompletionArgs {
381
+ /**
382
+ * Client ID.
383
+ */
384
+ clientId: string;
385
+ /**
386
+ * Name of the agent.
387
+ */
388
+ agentName: AgentName;
389
+ /**
390
+ * The source of the last message: tool or user
391
+ */
392
+ mode: ExecutionMode;
393
+ /**
394
+ * Array of model messages.
395
+ */
396
+ messages: IModelMessage[];
397
+ /**
398
+ * Optional array of tools.
399
+ */
400
+ tools?: ITool[];
401
+ }
402
+ /**
403
+ * Schema for a completion.
404
+ */
405
+ interface ICompletionSchema {
406
+ /**
407
+ * Name of the completion.
408
+ */
409
+ completionName: CompletionName;
410
+ /**
411
+ * Method to get a completion.
412
+ * @param args - Arguments required to get a completion.
413
+ * @returns A promise that resolves to a model message.
414
+ */
415
+ getCompletion(args: ICompletionArgs): Promise<IModelMessage>;
416
+ }
417
+ /**
418
+ * Type representing the name of a completion.
419
+ */
420
+ type CompletionName = string;
421
+
418
422
  /**
419
423
  * Interface representing a tool used by an agent.
420
424
  * @template T - The type of the parameters for the tool.
@@ -586,14 +590,14 @@ declare class ClientAgent implements IAgent {
586
590
  * @returns {Promise<void>}
587
591
  * @private
588
592
  */
589
- _emitOuput: (result: string) => Promise<void>;
593
+ _emitOuput: (mode: ExecutionMode, result: string) => Promise<void>;
590
594
  /**
591
595
  * Resurrects the model based on the given reason.
592
596
  * @param {string} [reason] - The reason for resurrecting the model.
593
597
  * @returns {Promise<string>}
594
598
  * @private
595
599
  */
596
- _resurrectModel: (reason?: string) => Promise<string>;
600
+ _resurrectModel: (mode: ExecutionMode, reason?: string) => Promise<string>;
597
601
  /**
598
602
  * Waits for the output to be available.
599
603
  * @returns {Promise<string>}
@@ -603,7 +607,7 @@ declare class ClientAgent implements IAgent {
603
607
  * Gets the completion message from the model.
604
608
  * @returns {Promise<IModelMessage>}
605
609
  */
606
- getCompletion: () => Promise<IModelMessage>;
610
+ getCompletion: (mode: ExecutionMode) => Promise<IModelMessage>;
607
611
  /**
608
612
  * Commits a user message to the history without answer.
609
613
  * @param {string} message - The message to commit.