agent-swarm-kit 1.0.27 → 1.0.29

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
@@ -481,6 +481,7 @@ var ClientAgent = /** @class */ (function () {
481
481
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel"));
482
482
  return [4 /*yield*/, this.params.history.push({
483
483
  role: "resque",
484
+ mode: 'tool',
484
485
  agentName: this.params.agentName,
485
486
  content: reason || "Unknown error",
486
487
  })];
@@ -488,6 +489,7 @@ var ClientAgent = /** @class */ (function () {
488
489
  _a.sent();
489
490
  return [4 /*yield*/, this.params.history.push({
490
491
  role: "user",
492
+ mode: 'tool',
491
493
  agentName: this.params.agentName,
492
494
  content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_PROMPT,
493
495
  })];
@@ -506,6 +508,7 @@ var ClientAgent = /** @class */ (function () {
506
508
  return [4 /*yield*/, this.params.history.push({
507
509
  agentName: this.params.agentName,
508
510
  role: "assistant",
511
+ mode: 'tool',
509
512
  content: content,
510
513
  })];
511
514
  case 5:
@@ -571,6 +574,7 @@ var ClientAgent = /** @class */ (function () {
571
574
  return [4 /*yield*/, this.params.history.push({
572
575
  role: "user",
573
576
  agentName: this.params.agentName,
577
+ mode: 'user',
574
578
  content: message.trim(),
575
579
  })];
576
580
  case 1:
@@ -592,6 +596,7 @@ var ClientAgent = /** @class */ (function () {
592
596
  return [4 /*yield*/, this.params.history.push({
593
597
  role: "system",
594
598
  agentName: this.params.agentName,
599
+ mode: 'tool',
595
600
  content: message.trim(),
596
601
  })];
597
602
  case 1:
@@ -613,6 +618,7 @@ var ClientAgent = /** @class */ (function () {
613
618
  return [4 /*yield*/, this.params.history.push({
614
619
  role: "tool",
615
620
  agentName: this.params.agentName,
621
+ mode: 'tool',
616
622
  content: content,
617
623
  })];
618
624
  case 1:
@@ -629,16 +635,17 @@ var ClientAgent = /** @class */ (function () {
629
635
  * @param {string} incoming - The incoming message content.
630
636
  * @returns {Promise<void>}
631
637
  */
632
- this.execute = functoolsKit.queued(function (incoming) { return __awaiter(_this, void 0, void 0, function () {
638
+ this.execute = functoolsKit.queued(function (incoming, mode) { return __awaiter(_this, void 0, void 0, function () {
633
639
  var message, _loop_1, this_1, _a, _b, tool, state_1, e_1_1, result, validation, result1;
634
640
  var e_1, _c;
635
641
  var _d;
636
642
  return __generator(this, function (_e) {
637
643
  switch (_e.label) {
638
644
  case 0:
639
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute begin"), { incoming: incoming });
645
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute begin"), { incoming: incoming, mode: mode });
640
646
  return [4 /*yield*/, this.params.history.push({
641
647
  role: "user",
648
+ mode: mode,
642
649
  agentName: this.params.agentName,
643
650
  content: incoming.trim(),
644
651
  })];
@@ -807,15 +814,16 @@ var AgentConnectionService = /** @class */ (function () {
807
814
  * @param {string} input - The input command.
808
815
  * @returns {Promise<any>} The execution result.
809
816
  */
810
- this.execute = function (input) { return __awaiter(_this, void 0, void 0, function () {
817
+ this.execute = function (input, mode) { return __awaiter(_this, void 0, void 0, function () {
811
818
  return __generator(this, function (_a) {
812
819
  switch (_a.label) {
813
820
  case 0:
814
821
  this.loggerService.log("agentConnectionService execute", {
815
822
  input: input,
823
+ mode: mode,
816
824
  context: this.contextService.context,
817
825
  });
818
- return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).execute(input)];
826
+ return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).execute(input, mode)];
819
827
  case 1: return [2 /*return*/, _a.sent()];
820
828
  }
821
829
  });
@@ -1068,14 +1076,19 @@ var ClientHistory = /** @class */ (function () {
1068
1076
  {
1069
1077
  promptMessages.push({
1070
1078
  agentName: this.params.agentName,
1079
+ mode: 'tool',
1071
1080
  content: prompt,
1072
1081
  role: "system",
1073
1082
  });
1074
- system && promptMessages.push({
1075
- agentName: this.params.agentName,
1076
- content: system,
1077
- role: "system",
1078
- });
1083
+ system &&
1084
+ system.forEach(function (content) {
1085
+ return promptMessages.push({
1086
+ agentName: _this.params.agentName,
1087
+ mode: 'tool',
1088
+ content: content,
1089
+ role: "system",
1090
+ });
1091
+ });
1079
1092
  }
1080
1093
  return [2 /*return*/, __spreadArray(__spreadArray(__spreadArray([], __read(promptMessages), false), __read(systemMessages), false), __read(commonMessages), false)];
1081
1094
  }
@@ -1636,12 +1649,12 @@ var ClientSession = /** @class */ (function () {
1636
1649
  * @param {boolean} [noEmit=false] - Whether to emit the output or not.
1637
1650
  * @returns {Promise<string>} - The output of the execution.
1638
1651
  */
1639
- this.execute = function (message_1) {
1652
+ this.execute = function (message_1, mode_1) {
1640
1653
  var args_1 = [];
1641
- for (var _i = 1; _i < arguments.length; _i++) {
1642
- args_1[_i - 1] = arguments[_i];
1654
+ for (var _i = 2; _i < arguments.length; _i++) {
1655
+ args_1[_i - 2] = arguments[_i];
1643
1656
  }
1644
- return __awaiter(_this, __spreadArray([message_1], __read(args_1), false), void 0, function (message, noEmit) {
1657
+ return __awaiter(_this, __spreadArray([message_1, mode_1], __read(args_1), false), void 0, function (message, mode, noEmit) {
1645
1658
  var agent, outputAwaiter, output, _a;
1646
1659
  if (noEmit === void 0) { noEmit = false; }
1647
1660
  return __generator(this, function (_b) {
@@ -1649,13 +1662,14 @@ var ClientSession = /** @class */ (function () {
1649
1662
  case 0:
1650
1663
  this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " execute"), {
1651
1664
  message: message,
1665
+ mode: mode,
1652
1666
  noEmit: noEmit,
1653
1667
  });
1654
1668
  return [4 /*yield*/, this.params.swarm.getAgent()];
1655
1669
  case 1:
1656
1670
  agent = _b.sent();
1657
1671
  outputAwaiter = this.params.swarm.waitForOutput();
1658
- agent.execute(message);
1672
+ agent.execute(message, mode);
1659
1673
  return [4 /*yield*/, outputAwaiter];
1660
1674
  case 2:
1661
1675
  output = _b.sent();
@@ -1768,7 +1782,7 @@ var ClientSession = /** @class */ (function () {
1768
1782
  this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " connect call"));
1769
1783
  _a = connector;
1770
1784
  _b = {};
1771
- return [4 /*yield*/, this.execute(incoming.data, true)];
1785
+ return [4 /*yield*/, this.execute(incoming.data, "user", true)];
1772
1786
  case 1:
1773
1787
  _b.data = _c.sent();
1774
1788
  return [4 /*yield*/, this.params.swarm.getAgentName()];
@@ -1837,14 +1851,16 @@ var SessionConnectionService = /** @class */ (function () {
1837
1851
  * @param {string} content - The content to execute.
1838
1852
  * @returns {Promise<string>} A promise that resolves with the execution result.
1839
1853
  */
1840
- this.execute = function (content) { return __awaiter(_this, void 0, void 0, function () {
1854
+ this.execute = function (content, mode) { return __awaiter(_this, void 0, void 0, function () {
1841
1855
  return __generator(this, function (_a) {
1842
1856
  switch (_a.label) {
1843
1857
  case 0:
1844
1858
  this.loggerService.log("sessionConnectionService execute", {
1845
1859
  context: this.contextService.context,
1860
+ content: content,
1861
+ mode: mode,
1846
1862
  });
1847
- return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).execute(content)];
1863
+ return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).execute(content, mode)];
1848
1864
  case 1: return [2 /*return*/, _a.sent()];
1849
1865
  }
1850
1866
  });
@@ -1974,7 +1990,7 @@ var AgentPublicService = /** @class */ (function () {
1974
1990
  * @param {AgentName} agentName - The name of the agent.
1975
1991
  * @returns {Promise<unknown>} The execution result.
1976
1992
  */
1977
- this.execute = function (input, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
1993
+ this.execute = function (input, mode, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
1978
1994
  var _this = this;
1979
1995
  return __generator(this, function (_a) {
1980
1996
  switch (_a.label) {
@@ -1983,11 +1999,12 @@ var AgentPublicService = /** @class */ (function () {
1983
1999
  input: input,
1984
2000
  clientId: clientId,
1985
2001
  agentName: agentName,
2002
+ mode: mode,
1986
2003
  });
1987
2004
  return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
1988
2005
  return __generator(this, function (_a) {
1989
2006
  switch (_a.label) {
1990
- case 0: return [4 /*yield*/, this.agentConnectionService.execute(input)];
2007
+ case 0: return [4 /*yield*/, this.agentConnectionService.execute(input, mode)];
1991
2008
  case 1: return [2 /*return*/, _a.sent()];
1992
2009
  }
1993
2010
  });
@@ -2353,20 +2370,21 @@ var SessionPublicService = /** @class */ (function () {
2353
2370
  * @param {SwarmName} swarmName - The swarm name.
2354
2371
  * @returns {Promise<void>}
2355
2372
  */
2356
- this.execute = function (content, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
2373
+ this.execute = function (content, mode, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
2357
2374
  var _this = this;
2358
2375
  return __generator(this, function (_a) {
2359
2376
  switch (_a.label) {
2360
2377
  case 0:
2361
2378
  this.loggerService.log("sessionPublicService execute", {
2362
2379
  content: content,
2380
+ mode: mode,
2363
2381
  clientId: clientId,
2364
2382
  swarmName: swarmName,
2365
2383
  });
2366
2384
  return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
2367
2385
  return __generator(this, function (_a) {
2368
2386
  switch (_a.label) {
2369
- case 0: return [4 /*yield*/, this.sessionConnectionService.execute(content)];
2387
+ case 0: return [4 /*yield*/, this.sessionConnectionService.execute(content, mode)];
2370
2388
  case 1: return [2 /*return*/, _a.sent()];
2371
2389
  }
2372
2390
  });
@@ -3658,7 +3676,7 @@ var createComplete = functoolsKit.ttl(function (clientId, swarmName) {
3658
3676
  case 0:
3659
3677
  swarm.swarmValidationService.validate(swarmName, "complete");
3660
3678
  swarm.sessionValidationService.addSession(clientId, swarmName, "complete");
3661
- return [4 /*yield*/, swarm.sessionPublicService.execute(content, clientId, swarmName)];
3679
+ return [4 /*yield*/, swarm.sessionPublicService.execute(content, "user", clientId, swarmName)];
3662
3680
  case 1:
3663
3681
  result = _a.sent();
3664
3682
  return [4 /*yield*/, disposeConnection(clientId, swarmName)];
@@ -3743,7 +3761,7 @@ var session = function (clientId, swarmName) {
3743
3761
  switch (_a.label) {
3744
3762
  case 0:
3745
3763
  swarm.sessionValidationService.validate(clientId, "session");
3746
- return [4 /*yield*/, swarm.sessionPublicService.execute(content, clientId, swarmName)];
3764
+ return [4 /*yield*/, swarm.sessionPublicService.execute(content, "user", clientId, swarmName)];
3747
3765
  case 1: return [2 /*return*/, _a.sent()];
3748
3766
  }
3749
3767
  });
@@ -4025,7 +4043,7 @@ var execute = function (content, clientId, agentName) { return __awaiter(void 0,
4025
4043
  });
4026
4044
  return [2 /*return*/];
4027
4045
  }
4028
- return [4 /*yield*/, swarm.sessionPublicService.execute(content, clientId, swarmName)];
4046
+ return [4 /*yield*/, swarm.sessionPublicService.execute(content, "tool", clientId, swarmName)];
4029
4047
  case 2: return [2 /*return*/, _a.sent()];
4030
4048
  }
4031
4049
  });
@@ -4093,8 +4111,8 @@ var getLastUserMessage = function (clientId) { return __awaiter(void 0, void 0,
4093
4111
  case 1:
4094
4112
  history = _a.sent();
4095
4113
  last = history.findLast(function (_a) {
4096
- var role = _a.role;
4097
- return role === "user";
4114
+ var role = _a.role, mode = _a.mode;
4115
+ return role === "user" && mode === "user";
4098
4116
  });
4099
4117
  return [2 /*return*/, last ? last.content : null];
4100
4118
  }
@@ -4119,8 +4137,8 @@ var getUserHistory = function (clientId) { return __awaiter(void 0, void 0, void
4119
4137
  case 1:
4120
4138
  history = _a.sent();
4121
4139
  return [2 /*return*/, history.filter(function (_a) {
4122
- var role = _a.role;
4123
- return role === "user";
4140
+ var role = _a.role, mode = _a.mode;
4141
+ return role === "user" && mode === "user";
4124
4142
  })];
4125
4143
  }
4126
4144
  });
package/build/index.mjs CHANGED
@@ -479,6 +479,7 @@ var ClientAgent = /** @class */ (function () {
479
479
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel"));
480
480
  return [4 /*yield*/, this.params.history.push({
481
481
  role: "resque",
482
+ mode: 'tool',
482
483
  agentName: this.params.agentName,
483
484
  content: reason || "Unknown error",
484
485
  })];
@@ -486,6 +487,7 @@ var ClientAgent = /** @class */ (function () {
486
487
  _a.sent();
487
488
  return [4 /*yield*/, this.params.history.push({
488
489
  role: "user",
490
+ mode: 'tool',
489
491
  agentName: this.params.agentName,
490
492
  content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_PROMPT,
491
493
  })];
@@ -504,6 +506,7 @@ var ClientAgent = /** @class */ (function () {
504
506
  return [4 /*yield*/, this.params.history.push({
505
507
  agentName: this.params.agentName,
506
508
  role: "assistant",
509
+ mode: 'tool',
507
510
  content: content,
508
511
  })];
509
512
  case 5:
@@ -569,6 +572,7 @@ var ClientAgent = /** @class */ (function () {
569
572
  return [4 /*yield*/, this.params.history.push({
570
573
  role: "user",
571
574
  agentName: this.params.agentName,
575
+ mode: 'user',
572
576
  content: message.trim(),
573
577
  })];
574
578
  case 1:
@@ -590,6 +594,7 @@ var ClientAgent = /** @class */ (function () {
590
594
  return [4 /*yield*/, this.params.history.push({
591
595
  role: "system",
592
596
  agentName: this.params.agentName,
597
+ mode: 'tool',
593
598
  content: message.trim(),
594
599
  })];
595
600
  case 1:
@@ -611,6 +616,7 @@ var ClientAgent = /** @class */ (function () {
611
616
  return [4 /*yield*/, this.params.history.push({
612
617
  role: "tool",
613
618
  agentName: this.params.agentName,
619
+ mode: 'tool',
614
620
  content: content,
615
621
  })];
616
622
  case 1:
@@ -627,16 +633,17 @@ var ClientAgent = /** @class */ (function () {
627
633
  * @param {string} incoming - The incoming message content.
628
634
  * @returns {Promise<void>}
629
635
  */
630
- this.execute = queued(function (incoming) { return __awaiter(_this, void 0, void 0, function () {
636
+ this.execute = queued(function (incoming, mode) { return __awaiter(_this, void 0, void 0, function () {
631
637
  var message, _loop_1, this_1, _a, _b, tool, state_1, e_1_1, result, validation, result1;
632
638
  var e_1, _c;
633
639
  var _d;
634
640
  return __generator(this, function (_e) {
635
641
  switch (_e.label) {
636
642
  case 0:
637
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute begin"), { incoming: incoming });
643
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute begin"), { incoming: incoming, mode: mode });
638
644
  return [4 /*yield*/, this.params.history.push({
639
645
  role: "user",
646
+ mode: mode,
640
647
  agentName: this.params.agentName,
641
648
  content: incoming.trim(),
642
649
  })];
@@ -805,15 +812,16 @@ var AgentConnectionService = /** @class */ (function () {
805
812
  * @param {string} input - The input command.
806
813
  * @returns {Promise<any>} The execution result.
807
814
  */
808
- this.execute = function (input) { return __awaiter(_this, void 0, void 0, function () {
815
+ this.execute = function (input, mode) { return __awaiter(_this, void 0, void 0, function () {
809
816
  return __generator(this, function (_a) {
810
817
  switch (_a.label) {
811
818
  case 0:
812
819
  this.loggerService.log("agentConnectionService execute", {
813
820
  input: input,
821
+ mode: mode,
814
822
  context: this.contextService.context,
815
823
  });
816
- return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).execute(input)];
824
+ return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).execute(input, mode)];
817
825
  case 1: return [2 /*return*/, _a.sent()];
818
826
  }
819
827
  });
@@ -1066,14 +1074,19 @@ var ClientHistory = /** @class */ (function () {
1066
1074
  {
1067
1075
  promptMessages.push({
1068
1076
  agentName: this.params.agentName,
1077
+ mode: 'tool',
1069
1078
  content: prompt,
1070
1079
  role: "system",
1071
1080
  });
1072
- system && promptMessages.push({
1073
- agentName: this.params.agentName,
1074
- content: system,
1075
- role: "system",
1076
- });
1081
+ system &&
1082
+ system.forEach(function (content) {
1083
+ return promptMessages.push({
1084
+ agentName: _this.params.agentName,
1085
+ mode: 'tool',
1086
+ content: content,
1087
+ role: "system",
1088
+ });
1089
+ });
1077
1090
  }
1078
1091
  return [2 /*return*/, __spreadArray(__spreadArray(__spreadArray([], __read(promptMessages), false), __read(systemMessages), false), __read(commonMessages), false)];
1079
1092
  }
@@ -1634,12 +1647,12 @@ var ClientSession = /** @class */ (function () {
1634
1647
  * @param {boolean} [noEmit=false] - Whether to emit the output or not.
1635
1648
  * @returns {Promise<string>} - The output of the execution.
1636
1649
  */
1637
- this.execute = function (message_1) {
1650
+ this.execute = function (message_1, mode_1) {
1638
1651
  var args_1 = [];
1639
- for (var _i = 1; _i < arguments.length; _i++) {
1640
- args_1[_i - 1] = arguments[_i];
1652
+ for (var _i = 2; _i < arguments.length; _i++) {
1653
+ args_1[_i - 2] = arguments[_i];
1641
1654
  }
1642
- return __awaiter(_this, __spreadArray([message_1], __read(args_1), false), void 0, function (message, noEmit) {
1655
+ return __awaiter(_this, __spreadArray([message_1, mode_1], __read(args_1), false), void 0, function (message, mode, noEmit) {
1643
1656
  var agent, outputAwaiter, output, _a;
1644
1657
  if (noEmit === void 0) { noEmit = false; }
1645
1658
  return __generator(this, function (_b) {
@@ -1647,13 +1660,14 @@ var ClientSession = /** @class */ (function () {
1647
1660
  case 0:
1648
1661
  this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " execute"), {
1649
1662
  message: message,
1663
+ mode: mode,
1650
1664
  noEmit: noEmit,
1651
1665
  });
1652
1666
  return [4 /*yield*/, this.params.swarm.getAgent()];
1653
1667
  case 1:
1654
1668
  agent = _b.sent();
1655
1669
  outputAwaiter = this.params.swarm.waitForOutput();
1656
- agent.execute(message);
1670
+ agent.execute(message, mode);
1657
1671
  return [4 /*yield*/, outputAwaiter];
1658
1672
  case 2:
1659
1673
  output = _b.sent();
@@ -1766,7 +1780,7 @@ var ClientSession = /** @class */ (function () {
1766
1780
  this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " connect call"));
1767
1781
  _a = connector;
1768
1782
  _b = {};
1769
- return [4 /*yield*/, this.execute(incoming.data, true)];
1783
+ return [4 /*yield*/, this.execute(incoming.data, "user", true)];
1770
1784
  case 1:
1771
1785
  _b.data = _c.sent();
1772
1786
  return [4 /*yield*/, this.params.swarm.getAgentName()];
@@ -1835,14 +1849,16 @@ var SessionConnectionService = /** @class */ (function () {
1835
1849
  * @param {string} content - The content to execute.
1836
1850
  * @returns {Promise<string>} A promise that resolves with the execution result.
1837
1851
  */
1838
- this.execute = function (content) { return __awaiter(_this, void 0, void 0, function () {
1852
+ this.execute = function (content, mode) { return __awaiter(_this, void 0, void 0, function () {
1839
1853
  return __generator(this, function (_a) {
1840
1854
  switch (_a.label) {
1841
1855
  case 0:
1842
1856
  this.loggerService.log("sessionConnectionService execute", {
1843
1857
  context: this.contextService.context,
1858
+ content: content,
1859
+ mode: mode,
1844
1860
  });
1845
- return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).execute(content)];
1861
+ return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).execute(content, mode)];
1846
1862
  case 1: return [2 /*return*/, _a.sent()];
1847
1863
  }
1848
1864
  });
@@ -1972,7 +1988,7 @@ var AgentPublicService = /** @class */ (function () {
1972
1988
  * @param {AgentName} agentName - The name of the agent.
1973
1989
  * @returns {Promise<unknown>} The execution result.
1974
1990
  */
1975
- this.execute = function (input, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
1991
+ this.execute = function (input, mode, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
1976
1992
  var _this = this;
1977
1993
  return __generator(this, function (_a) {
1978
1994
  switch (_a.label) {
@@ -1981,11 +1997,12 @@ var AgentPublicService = /** @class */ (function () {
1981
1997
  input: input,
1982
1998
  clientId: clientId,
1983
1999
  agentName: agentName,
2000
+ mode: mode,
1984
2001
  });
1985
2002
  return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
1986
2003
  return __generator(this, function (_a) {
1987
2004
  switch (_a.label) {
1988
- case 0: return [4 /*yield*/, this.agentConnectionService.execute(input)];
2005
+ case 0: return [4 /*yield*/, this.agentConnectionService.execute(input, mode)];
1989
2006
  case 1: return [2 /*return*/, _a.sent()];
1990
2007
  }
1991
2008
  });
@@ -2351,20 +2368,21 @@ var SessionPublicService = /** @class */ (function () {
2351
2368
  * @param {SwarmName} swarmName - The swarm name.
2352
2369
  * @returns {Promise<void>}
2353
2370
  */
2354
- this.execute = function (content, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
2371
+ this.execute = function (content, mode, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
2355
2372
  var _this = this;
2356
2373
  return __generator(this, function (_a) {
2357
2374
  switch (_a.label) {
2358
2375
  case 0:
2359
2376
  this.loggerService.log("sessionPublicService execute", {
2360
2377
  content: content,
2378
+ mode: mode,
2361
2379
  clientId: clientId,
2362
2380
  swarmName: swarmName,
2363
2381
  });
2364
2382
  return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
2365
2383
  return __generator(this, function (_a) {
2366
2384
  switch (_a.label) {
2367
- case 0: return [4 /*yield*/, this.sessionConnectionService.execute(content)];
2385
+ case 0: return [4 /*yield*/, this.sessionConnectionService.execute(content, mode)];
2368
2386
  case 1: return [2 /*return*/, _a.sent()];
2369
2387
  }
2370
2388
  });
@@ -3656,7 +3674,7 @@ var createComplete = ttl(function (clientId, swarmName) {
3656
3674
  case 0:
3657
3675
  swarm.swarmValidationService.validate(swarmName, "complete");
3658
3676
  swarm.sessionValidationService.addSession(clientId, swarmName, "complete");
3659
- return [4 /*yield*/, swarm.sessionPublicService.execute(content, clientId, swarmName)];
3677
+ return [4 /*yield*/, swarm.sessionPublicService.execute(content, "user", clientId, swarmName)];
3660
3678
  case 1:
3661
3679
  result = _a.sent();
3662
3680
  return [4 /*yield*/, disposeConnection(clientId, swarmName)];
@@ -3741,7 +3759,7 @@ var session = function (clientId, swarmName) {
3741
3759
  switch (_a.label) {
3742
3760
  case 0:
3743
3761
  swarm.sessionValidationService.validate(clientId, "session");
3744
- return [4 /*yield*/, swarm.sessionPublicService.execute(content, clientId, swarmName)];
3762
+ return [4 /*yield*/, swarm.sessionPublicService.execute(content, "user", clientId, swarmName)];
3745
3763
  case 1: return [2 /*return*/, _a.sent()];
3746
3764
  }
3747
3765
  });
@@ -4023,7 +4041,7 @@ var execute = function (content, clientId, agentName) { return __awaiter(void 0,
4023
4041
  });
4024
4042
  return [2 /*return*/];
4025
4043
  }
4026
- return [4 /*yield*/, swarm.sessionPublicService.execute(content, clientId, swarmName)];
4044
+ return [4 /*yield*/, swarm.sessionPublicService.execute(content, "tool", clientId, swarmName)];
4027
4045
  case 2: return [2 /*return*/, _a.sent()];
4028
4046
  }
4029
4047
  });
@@ -4091,8 +4109,8 @@ var getLastUserMessage = function (clientId) { return __awaiter(void 0, void 0,
4091
4109
  case 1:
4092
4110
  history = _a.sent();
4093
4111
  last = history.findLast(function (_a) {
4094
- var role = _a.role;
4095
- return role === "user";
4112
+ var role = _a.role, mode = _a.mode;
4113
+ return role === "user" && mode === "user";
4096
4114
  });
4097
4115
  return [2 /*return*/, last ? last.content : null];
4098
4116
  }
@@ -4117,8 +4135,8 @@ var getUserHistory = function (clientId) { return __awaiter(void 0, void 0, void
4117
4135
  case 1:
4118
4136
  history = _a.sent();
4119
4137
  return [2 /*return*/, history.filter(function (_a) {
4120
- var role = _a.role;
4121
- return role === "user";
4138
+ var role = _a.role, mode = _a.mode;
4139
+ return role === "user" && mode === "user";
4122
4140
  })];
4123
4141
  }
4124
4142
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
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
@@ -1,4 +1,5 @@
1
1
  import * as di_scoped from 'di-scoped';
2
+ import { ExecutionMode as ExecutionMode$1 } from 'src/interfaces/Session.interface';
2
3
  import * as functools_kit from 'functools-kit';
3
4
  import { IPubsubArray, Subject } from 'functools-kit';
4
5
 
@@ -10,7 +11,7 @@ interface IModelMessage {
10
11
  * The role of the message sender.
11
12
  * @type {'assistant' | 'system' | 'tool' | 'user' | 'resque'}
12
13
  */
13
- role: 'assistant' | 'system' | 'tool' | 'user' | 'resque';
14
+ role: "assistant" | "system" | "tool" | "user" | "resque";
14
15
  /**
15
16
  * The name of the agent sending the message.
16
17
  * @type {string}
@@ -21,6 +22,11 @@ interface IModelMessage {
21
22
  * @type {string}
22
23
  */
23
24
  content: string;
25
+ /**
26
+ * The source of message: tool or user
27
+ * @type {ExecutionMode}
28
+ */
29
+ mode: ExecutionMode$1;
24
30
  /**
25
31
  * Optional tool calls associated with the message.
26
32
  * @type {Array<{ function: { name: string; arguments: { [key: string]: any; }; }; }>}
@@ -66,7 +72,7 @@ interface IHistory {
66
72
  * @param {string} prompt - The prompt to filter messages for the agent.
67
73
  * @returns {Promise<IModelMessage[]>}
68
74
  */
69
- toArrayForAgent(prompt: string, system?: string): Promise<IModelMessage[]>;
75
+ toArrayForAgent(prompt: string, system?: string[]): Promise<IModelMessage[]>;
70
76
  /**
71
77
  * Converts the history to an array of raw messages.
72
78
  * @returns {Promise<IModelMessage[]>}
@@ -219,6 +225,196 @@ interface ICompletionSchema {
219
225
  */
220
226
  type CompletionName = string;
221
227
 
228
+ /**
229
+ * Interface representing an incoming message.
230
+ */
231
+ interface IIncomingMessage {
232
+ /**
233
+ * The ID of the client sending the message.
234
+ */
235
+ clientId: string;
236
+ /**
237
+ * The data contained in the message.
238
+ */
239
+ data: string;
240
+ /**
241
+ * The name of the agent sending the message.
242
+ */
243
+ agentName: AgentName;
244
+ }
245
+ /**
246
+ * Interface representing an outgoing message.
247
+ */
248
+ interface IOutgoingMessage {
249
+ /**
250
+ * The ID of the client receiving the message.
251
+ */
252
+ clientId: string;
253
+ /**
254
+ * The data contained in the message.
255
+ */
256
+ data: string;
257
+ /**
258
+ * The name of the agent sending the message.
259
+ */
260
+ agentName: AgentName;
261
+ }
262
+
263
+ /**
264
+ * Parameters for initializing a swarm.
265
+ * @interface
266
+ * @extends {Omit<ISwarmSchema, 'agentList'>}
267
+ */
268
+ interface ISwarmParams extends Omit<ISwarmSchema, keyof {
269
+ agentList: never;
270
+ }> {
271
+ /** Client identifier */
272
+ clientId: string;
273
+ /** Logger instance */
274
+ logger: ILogger;
275
+ /** Map of agent names to agent instances */
276
+ agentMap: Record<AgentName, IAgent>;
277
+ /** Emit the callback on agent change */
278
+ onAgentChanged(clientId: string, agentName: AgentName, swarmName: SwarmName): Promise<void>;
279
+ }
280
+ /**
281
+ * Schema for defining a swarm.
282
+ * @interface
283
+ */
284
+ interface ISwarmSchema {
285
+ /** Default agent name */
286
+ defaultAgent: AgentName;
287
+ /** Name of the swarm */
288
+ swarmName: string;
289
+ /** List of agent names */
290
+ agentList: string[];
291
+ }
292
+ /**
293
+ * Interface for a swarm.
294
+ * @interface
295
+ */
296
+ interface ISwarm {
297
+ /**
298
+ * Waits for the output from the swarm.
299
+ * @returns {Promise<string>} The output from the swarm.
300
+ */
301
+ waitForOutput(): Promise<string>;
302
+ /**
303
+ * Gets the name of the agent.
304
+ * @returns {Promise<AgentName>} The name of the agent.
305
+ */
306
+ getAgentName(): Promise<AgentName>;
307
+ /**
308
+ * Gets the agent instance.
309
+ * @returns {Promise<IAgent>} The agent instance.
310
+ */
311
+ getAgent(): Promise<IAgent>;
312
+ /**
313
+ * Sets the reference to an agent.
314
+ * @param {AgentName} agentName - The name of the agent.
315
+ * @param {IAgent} agent - The agent instance.
316
+ * @returns {Promise<void>}
317
+ */
318
+ setAgentRef(agentName: AgentName, agent: IAgent): Promise<void>;
319
+ /**
320
+ * Sets the name of the agent.
321
+ * @param {AgentName} agentName - The name of the agent.
322
+ * @returns {Promise<void>}
323
+ */
324
+ setAgentName(agentName: AgentName): Promise<void>;
325
+ }
326
+ /** Type alias for swarm name */
327
+ type SwarmName = string;
328
+
329
+ /**
330
+ * Parameters required to create a session.
331
+ * @interface
332
+ */
333
+ interface ISessionParams extends ISessionSchema {
334
+ clientId: string;
335
+ logger: ILogger;
336
+ swarm: ISwarm;
337
+ }
338
+ /**
339
+ * Schema for session data.
340
+ * @interface
341
+ */
342
+ interface ISessionSchema {
343
+ }
344
+ /**
345
+ * Function type for sending messages.
346
+ * @typedef {function} SendMessageFn
347
+ * @param {IOutgoingMessage} outgoing - The outgoing message.
348
+ * @returns {Promise<void> | void}
349
+ */
350
+ type SendMessageFn$1 = (outgoing: IOutgoingMessage) => Promise<void> | void;
351
+ /**
352
+ * Function type for receiving messages.
353
+ * @typedef {function} ReceiveMessageFn
354
+ * @param {IIncomingMessage} incoming - The incoming message.
355
+ * @returns {Promise<void> | void}
356
+ */
357
+ type ReceiveMessageFn = (incoming: IIncomingMessage) => Promise<void> | void;
358
+ /**
359
+ * Interface for a session.
360
+ * @interface
361
+ */
362
+ interface ISession {
363
+ /**
364
+ * Emit a message.
365
+ * @param {string} message - The message to emit.
366
+ * @returns {Promise<void>}
367
+ */
368
+ emit(message: string): Promise<void>;
369
+ /**
370
+ * Execute a command.
371
+ * @param {string} content - The content to execute.
372
+ * @param {string} mode - The source of execution: tool or user
373
+ * @returns {Promise<string>}
374
+ */
375
+ execute(content: string, mode: ExecutionMode): Promise<string>;
376
+ /**
377
+ * Connect to a message sender.
378
+ * @param {SendMessageFn} connector - The function to send messages.
379
+ * @returns {ReceiveMessageFn}
380
+ */
381
+ connect(connector: SendMessageFn$1): ReceiveMessageFn;
382
+ /**
383
+ * Commit tool output.
384
+ * @param {string} content - The content to commit.
385
+ * @returns {Promise<void>}
386
+ */
387
+ commitToolOutput(content: string): Promise<void>;
388
+ /**
389
+ * Commit user message without answer
390
+ * @param {string} message - The message to commit.
391
+ * @returns {Promise<void>}
392
+ */
393
+ commitUserMessage: (message: string) => Promise<void>;
394
+ /**
395
+ * Commit a system message.
396
+ * @param {string} message - The message to commit.
397
+ * @returns {Promise<void>}
398
+ */
399
+ commitSystemMessage(message: string): Promise<void>;
400
+ }
401
+ /**
402
+ * Type for session ID.
403
+ * @typedef {string} SessionId
404
+ */
405
+ type SessionId = string;
406
+ /**
407
+ * Type for session mode.
408
+ * @typedef {"session" | "makeConnection" | "complete"} SessionMode
409
+ */
410
+ type SessionMode = "session" | "makeConnection" | "complete";
411
+ /**
412
+ * Tools can emit user messages to trigger user friendly responses.
413
+ * Should be ignored for `getUserHistory`
414
+ * @typedef {"tool" | "user"} ExecutionMode
415
+ */
416
+ type ExecutionMode = "tool" | "user";
417
+
222
418
  /**
223
419
  * Interface representing a tool used by an agent.
224
420
  * @template T - The type of the parameters for the tool.
@@ -279,7 +475,7 @@ interface IAgentSchema {
279
475
  /** The prompt for the agent. */
280
476
  prompt: string;
281
477
  /** The system prompt. Usually used for tool calling protocol. */
282
- system?: string;
478
+ system?: string[];
283
479
  /** The names of the tools used by the agent. */
284
480
  tools?: ToolName[];
285
481
  /**
@@ -296,9 +492,10 @@ interface IAgent {
296
492
  /**
297
493
  * Executes the agent with the given input.
298
494
  * @param input - The input to execute.
495
+ * @param mode - The source of execution: tool or user
299
496
  * @returns A promise that resolves when the execution is complete.
300
497
  */
301
- execute: (input: string) => Promise<void>;
498
+ execute: (input: string, mode: ExecutionMode) => Promise<void>;
302
499
  /**
303
500
  * Waits for the output from the agent.
304
501
  * @returns A promise that resolves to the output string.
@@ -328,72 +525,6 @@ type AgentName = string;
328
525
  /** Type representing the name of a tool. */
329
526
  type ToolName = string;
330
527
 
331
- /**
332
- * Parameters for initializing a swarm.
333
- * @interface
334
- * @extends {Omit<ISwarmSchema, 'agentList'>}
335
- */
336
- interface ISwarmParams extends Omit<ISwarmSchema, keyof {
337
- agentList: never;
338
- }> {
339
- /** Client identifier */
340
- clientId: string;
341
- /** Logger instance */
342
- logger: ILogger;
343
- /** Map of agent names to agent instances */
344
- agentMap: Record<AgentName, IAgent>;
345
- /** Emit the callback on agent change */
346
- onAgentChanged(clientId: string, agentName: AgentName, swarmName: SwarmName): Promise<void>;
347
- }
348
- /**
349
- * Schema for defining a swarm.
350
- * @interface
351
- */
352
- interface ISwarmSchema {
353
- /** Default agent name */
354
- defaultAgent: AgentName;
355
- /** Name of the swarm */
356
- swarmName: string;
357
- /** List of agent names */
358
- agentList: string[];
359
- }
360
- /**
361
- * Interface for a swarm.
362
- * @interface
363
- */
364
- interface ISwarm {
365
- /**
366
- * Waits for the output from the swarm.
367
- * @returns {Promise<string>} The output from the swarm.
368
- */
369
- waitForOutput(): Promise<string>;
370
- /**
371
- * Gets the name of the agent.
372
- * @returns {Promise<AgentName>} The name of the agent.
373
- */
374
- getAgentName(): Promise<AgentName>;
375
- /**
376
- * Gets the agent instance.
377
- * @returns {Promise<IAgent>} The agent instance.
378
- */
379
- getAgent(): Promise<IAgent>;
380
- /**
381
- * Sets the reference to an agent.
382
- * @param {AgentName} agentName - The name of the agent.
383
- * @param {IAgent} agent - The agent instance.
384
- * @returns {Promise<void>}
385
- */
386
- setAgentRef(agentName: AgentName, agent: IAgent): Promise<void>;
387
- /**
388
- * Sets the name of the agent.
389
- * @param {AgentName} agentName - The name of the agent.
390
- * @returns {Promise<void>}
391
- */
392
- setAgentName(agentName: AgentName): Promise<void>;
393
- }
394
- /** Type alias for swarm name */
395
- type SwarmName = string;
396
-
397
528
  /**
398
529
  * Interface representing the context.
399
530
  */
@@ -523,7 +654,7 @@ declare class AgentConnectionService implements IAgent {
523
654
  * @param {string} input - The input command.
524
655
  * @returns {Promise<any>} The execution result.
525
656
  */
526
- execute: (input: string) => Promise<void>;
657
+ execute: (input: string, mode: ExecutionMode) => Promise<void>;
527
658
  /**
528
659
  * Waits for the output from the agent.
529
660
  * @returns {Promise<any>} The output result.
@@ -582,7 +713,7 @@ declare class ClientHistory implements IHistory {
582
713
  * @param {string} system - The tool calling protocol
583
714
  * @returns {Promise<IModelMessage[]>} - The array of messages for the agent.
584
715
  */
585
- toArrayForAgent: (prompt: string, system?: string) => Promise<IModelMessage[]>;
716
+ toArrayForAgent: (prompt: string, system?: string[]) => Promise<IModelMessage[]>;
586
717
  }
587
718
 
588
719
  /**
@@ -804,123 +935,6 @@ declare class CompletionSchemaService {
804
935
  get: (key: string) => ICompletionSchema;
805
936
  }
806
937
 
807
- /**
808
- * Interface representing an incoming message.
809
- */
810
- interface IIncomingMessage {
811
- /**
812
- * The ID of the client sending the message.
813
- */
814
- clientId: string;
815
- /**
816
- * The data contained in the message.
817
- */
818
- data: string;
819
- /**
820
- * The name of the agent sending the message.
821
- */
822
- agentName: AgentName;
823
- }
824
- /**
825
- * Interface representing an outgoing message.
826
- */
827
- interface IOutgoingMessage {
828
- /**
829
- * The ID of the client receiving the message.
830
- */
831
- clientId: string;
832
- /**
833
- * The data contained in the message.
834
- */
835
- data: string;
836
- /**
837
- * The name of the agent sending the message.
838
- */
839
- agentName: AgentName;
840
- }
841
-
842
- /**
843
- * Parameters required to create a session.
844
- * @interface
845
- */
846
- interface ISessionParams extends ISessionSchema {
847
- clientId: string;
848
- logger: ILogger;
849
- swarm: ISwarm;
850
- }
851
- /**
852
- * Schema for session data.
853
- * @interface
854
- */
855
- interface ISessionSchema {
856
- }
857
- /**
858
- * Function type for sending messages.
859
- * @typedef {function} SendMessageFn
860
- * @param {IOutgoingMessage} outgoing - The outgoing message.
861
- * @returns {Promise<void> | void}
862
- */
863
- type SendMessageFn$1 = (outgoing: IOutgoingMessage) => Promise<void> | void;
864
- /**
865
- * Function type for receiving messages.
866
- * @typedef {function} ReceiveMessageFn
867
- * @param {IIncomingMessage} incoming - The incoming message.
868
- * @returns {Promise<void> | void}
869
- */
870
- type ReceiveMessageFn = (incoming: IIncomingMessage) => Promise<void> | void;
871
- /**
872
- * Interface for a session.
873
- * @interface
874
- */
875
- interface ISession {
876
- /**
877
- * Emit a message.
878
- * @param {string} message - The message to emit.
879
- * @returns {Promise<void>}
880
- */
881
- emit(message: string): Promise<void>;
882
- /**
883
- * Execute a command.
884
- * @param {string} content - The content to execute.
885
- * @returns {Promise<string>}
886
- */
887
- execute(content: string): Promise<string>;
888
- /**
889
- * Connect to a message sender.
890
- * @param {SendMessageFn} connector - The function to send messages.
891
- * @returns {ReceiveMessageFn}
892
- */
893
- connect(connector: SendMessageFn$1): ReceiveMessageFn;
894
- /**
895
- * Commit tool output.
896
- * @param {string} content - The content to commit.
897
- * @returns {Promise<void>}
898
- */
899
- commitToolOutput(content: string): Promise<void>;
900
- /**
901
- * Commit user message without answer
902
- * @param {string} message - The message to commit.
903
- * @returns {Promise<void>}
904
- */
905
- commitUserMessage: (message: string) => Promise<void>;
906
- /**
907
- * Commit a system message.
908
- * @param {string} message - The message to commit.
909
- * @returns {Promise<void>}
910
- */
911
- commitSystemMessage(message: string): Promise<void>;
912
- }
913
- /**
914
- * Type for session ID.
915
- * @typedef {string} SessionId
916
- */
917
- type SessionId = string;
918
- /**
919
- * Type for session mode.
920
- * @typedef {"session" | "makeConnection" | "complete"} SessionMode
921
- */
922
- type SessionMode = "session" | "makeConnection" | "complete";
923
-
924
938
  /**
925
939
  * ClientSession class implements the ISession interface.
926
940
  */
@@ -944,7 +958,7 @@ declare class ClientSession implements ISession {
944
958
  * @param {boolean} [noEmit=false] - Whether to emit the output or not.
945
959
  * @returns {Promise<string>} - The output of the execution.
946
960
  */
947
- execute: (message: string, noEmit?: boolean) => Promise<string>;
961
+ execute: (message: string, mode: ExecutionMode, noEmit?: boolean) => Promise<string>;
948
962
  /**
949
963
  * Commits tool output.
950
964
  * @param {string} content - The content to commit.
@@ -997,7 +1011,7 @@ declare class SessionConnectionService implements ISession {
997
1011
  * @param {string} content - The content to execute.
998
1012
  * @returns {Promise<string>} A promise that resolves with the execution result.
999
1013
  */
1000
- execute: (content: string) => Promise<string>;
1014
+ execute: (content: string, mode: ExecutionMode) => Promise<string>;
1001
1015
  /**
1002
1016
  * Connects to the session using the provided connector.
1003
1017
  * @param {SendMessageFn} connector - The function to send messages.
@@ -1057,7 +1071,7 @@ declare class AgentPublicService implements TAgentConnectionService {
1057
1071
  * @param {AgentName} agentName - The name of the agent.
1058
1072
  * @returns {Promise<unknown>} The execution result.
1059
1073
  */
1060
- execute: (input: string, clientId: string, agentName: AgentName) => Promise<void>;
1074
+ execute: (input: string, mode: ExecutionMode, clientId: string, agentName: AgentName) => Promise<void>;
1061
1075
  /**
1062
1076
  * Waits for the agent's output.
1063
1077
  * @param {string} clientId - The client ID.
@@ -1174,7 +1188,7 @@ declare class SessionPublicService implements TSessionConnectionService {
1174
1188
  * @param {SwarmName} swarmName - The swarm name.
1175
1189
  * @returns {Promise<void>}
1176
1190
  */
1177
- execute: (content: string, clientId: string, swarmName: SwarmName) => Promise<string>;
1191
+ execute: (content: string, mode: ExecutionMode, clientId: string, swarmName: SwarmName) => Promise<string>;
1178
1192
  /**
1179
1193
  * Connects to the session.
1180
1194
  * @param {SendMessageFn} connector - The function to send messages.