agent-swarm-kit 1.0.36 → 1.0.38

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
@@ -413,6 +413,7 @@ var CC_AGENT_HISTORY_FILTER = function (agentName) { return function (message) {
413
413
  var CC_AGENT_OUTPUT_TRANSFORM = removeXmlTags;
414
414
  var CC_KEEP_MESSAGES = 5;
415
415
  var CC_GET_AGENT_HISTORY = function () { return new functoolsKit.PubsubArrayAdapter(); };
416
+ var CC_AGENT_SEPARATE_HISTORY = false;
416
417
  var GLOBAL_CONFIG = {
417
418
  CC_TOOL_CALL_EXCEPTION_PROMPT: CC_TOOL_CALL_EXCEPTION_PROMPT,
418
419
  CC_EMPTY_OUTPUT_PLACEHOLDERS: CC_EMPTY_OUTPUT_PLACEHOLDERS,
@@ -423,6 +424,7 @@ var GLOBAL_CONFIG = {
423
424
  CC_AGENT_DEFAULT_VALIDATION: CC_AGENT_DEFAULT_VALIDATION,
424
425
  CC_AGENT_HISTORY_FILTER: CC_AGENT_HISTORY_FILTER,
425
426
  CC_AGENT_OUTPUT_TRANSFORM: CC_AGENT_OUTPUT_TRANSFORM,
427
+ CC_AGENT_SEPARATE_HISTORY: CC_AGENT_SEPARATE_HISTORY,
426
428
  CC_AGENT_DISALLOWED_TAGS: CC_AGENT_DISALLOWED_TAGS,
427
429
  CC_AGENT_DISALLOWED_SYMBOLS: CC_AGENT_DISALLOWED_SYMBOLS,
428
430
  };
@@ -667,18 +669,19 @@ var ClientAgent = /** @class */ (function () {
667
669
  * @param {string} content - The tool output content.
668
670
  * @returns {Promise<void>}
669
671
  */
670
- this.commitToolOutput = function (content) { return __awaiter(_this, void 0, void 0, function () {
672
+ this.commitToolOutput = function (toolId, content) { return __awaiter(_this, void 0, void 0, function () {
671
673
  return __generator(this, function (_a) {
672
674
  switch (_a.label) {
673
675
  case 0:
674
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitToolOutput"), { content: content });
676
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitToolOutput"), { content: content, toolId: toolId });
675
677
  this.params.onToolOutput &&
676
- this.params.onToolOutput(this.params.clientId, this.params.agentName, content);
678
+ this.params.onToolOutput(toolId, this.params.clientId, this.params.agentName, content);
677
679
  return [4 /*yield*/, this.params.history.push({
678
680
  role: "tool",
679
681
  agentName: this.params.agentName,
680
682
  mode: "tool",
681
683
  content: content,
684
+ tool_call_id: toolId,
682
685
  })];
683
686
  case 1:
684
687
  _a.sent();
@@ -697,9 +700,9 @@ var ClientAgent = /** @class */ (function () {
697
700
  this.execute = functoolsKit.queued(function (incoming, mode) { return __awaiter(_this, void 0, void 0, function () {
698
701
  var message, _loop_1, this_1, _a, _b, tool, state_1, e_1_1, result, validation, result1;
699
702
  var e_1, _c;
700
- var _d, _e, _f, _g, _h;
701
- return __generator(this, function (_j) {
702
- switch (_j.label) {
703
+ var _d, _e, _f, _g, _h, _j;
704
+ return __generator(this, function (_k) {
705
+ switch (_k.label) {
703
706
  case 0:
704
707
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute begin"), { incoming: incoming, mode: mode });
705
708
  this.params.onExecute &&
@@ -711,45 +714,45 @@ var ClientAgent = /** @class */ (function () {
711
714
  content: incoming.trim(),
712
715
  })];
713
716
  case 1:
714
- _j.sent();
717
+ _k.sent();
715
718
  return [4 /*yield*/, this.getCompletion(mode)];
716
719
  case 2:
717
- message = _j.sent();
720
+ message = _k.sent();
718
721
  if (!message.tool_calls) return [3 /*break*/, 11];
719
722
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " tool call begin"));
720
723
  _loop_1 = function (tool) {
721
724
  var targetFn, result_2, result_3;
722
- return __generator(this, function (_k) {
723
- switch (_k.label) {
725
+ return __generator(this, function (_l) {
726
+ switch (_l.label) {
724
727
  case 0:
725
728
  targetFn = (_d = this_1.params.tools) === null || _d === void 0 ? void 0 : _d.find(function (t) { return t.function.name === tool.function.name; });
726
729
  return [4 /*yield*/, this_1.params.history.push(__assign(__assign({}, message), { agentName: this_1.params.agentName }))];
727
730
  case 1:
728
- _k.sent();
731
+ _l.sent();
729
732
  if (!!targetFn) return [3 /*break*/, 4];
730
733
  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);
731
734
  return [4 /*yield*/, this_1._resurrectModel(mode, "No target function for ".concat(tool.function.name))];
732
735
  case 2:
733
- result_2 = _k.sent();
736
+ result_2 = _l.sent();
734
737
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_2));
735
738
  return [4 /*yield*/, this_1._emitOuput(mode, result_2)];
736
739
  case 3:
737
- _k.sent();
740
+ _l.sent();
738
741
  return [2 /*return*/, { value: void 0 }];
739
742
  case 4:
740
743
  ((_e = targetFn.callbacks) === null || _e === void 0 ? void 0 : _e.onValidate) &&
741
744
  ((_f = targetFn.callbacks) === null || _f === void 0 ? void 0 : _f.onValidate(this_1.params.clientId, this_1.params.agentName, tool.function.arguments));
742
745
  return [4 /*yield*/, functoolsKit.not(targetFn.validate(this_1.params.clientId, this_1.params.agentName, tool.function.arguments))];
743
746
  case 5:
744
- if (!_k.sent()) return [3 /*break*/, 8];
747
+ if (!_l.sent()) return [3 /*break*/, 8];
745
748
  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"));
746
749
  return [4 /*yield*/, this_1._resurrectModel(mode, "Function validation failed: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
747
750
  case 6:
748
- result_3 = _k.sent();
751
+ result_3 = _l.sent();
749
752
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_3));
750
753
  return [4 /*yield*/, this_1._emitOuput(mode, result_3)];
751
754
  case 7:
752
- _k.sent();
755
+ _l.sent();
753
756
  return [2 /*return*/, { value: void 0 }];
754
757
  case 8:
755
758
  ((_g = targetFn.callbacks) === null || _g === void 0 ? void 0 : _g.onCall) &&
@@ -757,40 +760,40 @@ var ClientAgent = /** @class */ (function () {
757
760
  /**
758
761
  * @description Do not await to avoid deadlock! The tool can send the message to other agents by emulating user messages
759
762
  */
760
- targetFn.call(this_1.params.clientId, this_1.params.agentName, tool.function.arguments);
763
+ targetFn.call((_j = tool.id) !== null && _j !== void 0 ? _j : functoolsKit.randomString(), this_1.params.clientId, this_1.params.agentName, tool.function.arguments);
761
764
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool call executing"));
762
765
  return [4 /*yield*/, Promise.race([
763
766
  this_1._toolCommitSubject.toPromise(),
764
767
  this_1._outputSubject.toPromise(),
765
768
  ])];
766
769
  case 9:
767
- _k.sent();
770
+ _l.sent();
768
771
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool call end"));
769
772
  return [2 /*return*/];
770
773
  }
771
774
  });
772
775
  };
773
776
  this_1 = this;
774
- _j.label = 3;
777
+ _k.label = 3;
775
778
  case 3:
776
- _j.trys.push([3, 8, 9, 10]);
779
+ _k.trys.push([3, 8, 9, 10]);
777
780
  _a = __values(message.tool_calls), _b = _a.next();
778
- _j.label = 4;
781
+ _k.label = 4;
779
782
  case 4:
780
783
  if (!!_b.done) return [3 /*break*/, 7];
781
784
  tool = _b.value;
782
785
  return [5 /*yield**/, _loop_1(tool)];
783
786
  case 5:
784
- state_1 = _j.sent();
787
+ state_1 = _k.sent();
785
788
  if (typeof state_1 === "object")
786
789
  return [2 /*return*/, state_1.value];
787
- _j.label = 6;
790
+ _k.label = 6;
788
791
  case 6:
789
792
  _b = _a.next();
790
793
  return [3 /*break*/, 4];
791
794
  case 7: return [3 /*break*/, 10];
792
795
  case 8:
793
- e_1_1 = _j.sent();
796
+ e_1_1 = _k.sent();
794
797
  e_1 = { error: e_1_1 };
795
798
  return [3 /*break*/, 10];
796
799
  case 9:
@@ -807,24 +810,24 @@ var ClientAgent = /** @class */ (function () {
807
810
  result = message.content;
808
811
  return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
809
812
  case 12:
810
- _j.sent();
813
+ _k.sent();
811
814
  validation = null;
812
815
  return [4 /*yield*/, this.params.validate(result)];
813
816
  case 13:
814
- if (!(validation = _j.sent())) return [3 /*break*/, 16];
817
+ if (!(validation = _k.sent())) return [3 /*break*/, 16];
815
818
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute invalid tool call detected: ").concat(validation), { result: result });
816
819
  return [4 /*yield*/, this._resurrectModel(mode, "Invalid model output: ".concat(result))];
817
820
  case 14:
818
- result1 = _j.sent();
821
+ result1 = _k.sent();
819
822
  return [4 /*yield*/, this._emitOuput(mode, result1)];
820
823
  case 15:
821
- _j.sent();
824
+ _k.sent();
822
825
  return [2 /*return*/];
823
826
  case 16:
824
827
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute end result=").concat(result));
825
828
  return [4 /*yield*/, this._emitOuput(mode, result)];
826
829
  case 17:
827
- _j.sent();
830
+ _k.sent();
828
831
  return [2 /*return*/];
829
832
  }
830
833
  });
@@ -916,17 +919,19 @@ var AgentConnectionService = /** @class */ (function () {
916
919
  /**
917
920
  * Commits tool output.
918
921
  * @param {string} content - The tool output content.
922
+ * @param {string} toolId - The `tool_call_id` for openai history
919
923
  * @returns {Promise<any>} The commit result.
920
924
  */
921
- this.commitToolOutput = function (content) { return __awaiter(_this, void 0, void 0, function () {
925
+ this.commitToolOutput = function (toolId, content) { return __awaiter(_this, void 0, void 0, function () {
922
926
  return __generator(this, function (_a) {
923
927
  switch (_a.label) {
924
928
  case 0:
925
929
  this.loggerService.log("agentConnectionService commitToolOutput", {
926
930
  content: content,
931
+ toolId: toolId,
927
932
  context: this.contextService.context,
928
933
  });
929
- return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).commitToolOutput(content)];
934
+ return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).commitToolOutput(toolId, content)];
930
935
  case 1: return [2 /*return*/, _a.sent()];
931
936
  }
932
937
  });
@@ -1289,10 +1294,13 @@ var HistoryConnectionService = /** @class */ (function () {
1289
1294
  this.loggerService.log("historyConnectionService dispose", {
1290
1295
  context: this.contextService.context,
1291
1296
  });
1297
+ if (!GLOBAL_CONFIG.CC_AGENT_SEPARATE_HISTORY) return [3 /*break*/, 2];
1292
1298
  return [4 /*yield*/, this.getItems(this.contextService.context.clientId, this.contextService.context.agentName).clear()];
1293
1299
  case 1:
1294
1300
  _a.sent();
1295
1301
  this.getItems.clear(this.contextService.context.clientId);
1302
+ _a.label = 2;
1303
+ case 2:
1296
1304
  this.getHistory.clear("".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.agentName));
1297
1305
  this.sessionValidationService.removeHistoryUsage(this.contextService.context.clientId, this.contextService.context.agentName);
1298
1306
  return [2 /*return*/];
@@ -1779,21 +1787,23 @@ var ClientSession = /** @class */ (function () {
1779
1787
  }); };
1780
1788
  /**
1781
1789
  * Commits tool output.
1790
+ * @param {string} toolId - The `tool_call_id` for openai history
1782
1791
  * @param {string} content - The content to commit.
1783
1792
  * @returns {Promise<void>}
1784
1793
  */
1785
- this.commitToolOutput = function (content) { return __awaiter(_this, void 0, void 0, function () {
1794
+ this.commitToolOutput = function (toolId, content) { return __awaiter(_this, void 0, void 0, function () {
1786
1795
  var agent;
1787
1796
  return __generator(this, function (_a) {
1788
1797
  switch (_a.label) {
1789
1798
  case 0:
1790
1799
  this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " commitToolOutput"), {
1791
1800
  content: content,
1801
+ toolId: toolId,
1792
1802
  });
1793
1803
  return [4 /*yield*/, this.params.swarm.getAgent()];
1794
1804
  case 1:
1795
1805
  agent = _a.sent();
1796
- return [4 /*yield*/, agent.commitToolOutput(content)];
1806
+ return [4 /*yield*/, agent.commitToolOutput(toolId, content)];
1797
1807
  case 2: return [2 /*return*/, _a.sent()];
1798
1808
  }
1799
1809
  });
@@ -2001,18 +2011,20 @@ var SessionConnectionService = /** @class */ (function () {
2001
2011
  };
2002
2012
  /**
2003
2013
  * Commits tool output to the session.
2014
+ * @param {string} toolId - The `tool_call_id` for openai history
2004
2015
  * @param {string} content - The content to commit.
2005
2016
  * @returns {Promise<void>} A promise that resolves when the content is committed.
2006
2017
  */
2007
- this.commitToolOutput = function (content) { return __awaiter(_this, void 0, void 0, function () {
2018
+ this.commitToolOutput = function (toolId, content) { return __awaiter(_this, void 0, void 0, function () {
2008
2019
  return __generator(this, function (_a) {
2009
2020
  switch (_a.label) {
2010
2021
  case 0:
2011
2022
  this.loggerService.log("sessionConnectionService commitToolOutput", {
2012
2023
  context: this.contextService.context,
2013
2024
  content: content,
2025
+ toolId: toolId,
2014
2026
  });
2015
- return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitToolOutput(content)];
2027
+ return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitToolOutput(toolId, content)];
2016
2028
  case 1: return [2 /*return*/, _a.sent()];
2017
2029
  }
2018
2030
  });
@@ -2199,12 +2211,13 @@ var AgentPublicService = /** @class */ (function () {
2199
2211
  }); };
2200
2212
  /**
2201
2213
  * Commits tool output to the agent.
2214
+ * @param {string} toolId - The `tool_call_id` for openai history
2202
2215
  * @param {string} content - The content to commit.
2203
2216
  * @param {string} clientId - The client ID.
2204
2217
  * @param {AgentName} agentName - The name of the agent.
2205
2218
  * @returns {Promise<unknown>} The commit result.
2206
2219
  */
2207
- this.commitToolOutput = function (content, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
2220
+ this.commitToolOutput = function (toolId, content, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
2208
2221
  var _this = this;
2209
2222
  return __generator(this, function (_a) {
2210
2223
  switch (_a.label) {
@@ -2212,12 +2225,13 @@ var AgentPublicService = /** @class */ (function () {
2212
2225
  this.loggerService.log("agentPublicService commitToolOutput", {
2213
2226
  content: content,
2214
2227
  clientId: clientId,
2228
+ toolId: toolId,
2215
2229
  agentName: agentName,
2216
2230
  });
2217
2231
  return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
2218
2232
  return __generator(this, function (_a) {
2219
2233
  switch (_a.label) {
2220
- case 0: return [4 /*yield*/, this.agentConnectionService.commitToolOutput(content)];
2234
+ case 0: return [4 /*yield*/, this.agentConnectionService.commitToolOutput(toolId, content)];
2221
2235
  case 1: return [2 /*return*/, _a.sent()];
2222
2236
  }
2223
2237
  });
@@ -2627,17 +2641,19 @@ var SessionPublicService = /** @class */ (function () {
2627
2641
  };
2628
2642
  /**
2629
2643
  * Commits tool output to the session.
2644
+ * @param {string} toolId - The `tool_call_id` for openai history
2630
2645
  * @param {string} content - The content to commit.
2631
2646
  * @param {string} clientId - The client ID.
2632
2647
  * @param {SwarmName} swarmName - The swarm name.
2633
2648
  * @returns {Promise<void>}
2634
2649
  */
2635
- this.commitToolOutput = function (content, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
2650
+ this.commitToolOutput = function (toolId, content, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
2636
2651
  var _this = this;
2637
2652
  return __generator(this, function (_a) {
2638
2653
  switch (_a.label) {
2639
2654
  case 0:
2640
2655
  this.loggerService.log("sessionPublicService commitToolOutput", {
2656
+ toolId: toolId,
2641
2657
  content: content,
2642
2658
  clientId: clientId,
2643
2659
  swarmName: swarmName,
@@ -2645,7 +2661,7 @@ var SessionPublicService = /** @class */ (function () {
2645
2661
  return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
2646
2662
  return __generator(this, function (_a) {
2647
2663
  switch (_a.label) {
2648
- case 0: return [4 /*yield*/, this.sessionConnectionService.commitToolOutput(content)];
2664
+ case 0: return [4 /*yield*/, this.sessionConnectionService.commitToolOutput(toolId, content)];
2649
2665
  case 1: return [2 /*return*/, _a.sent()];
2650
2666
  }
2651
2667
  });
@@ -4146,12 +4162,13 @@ var getAgentHistory = function (clientId, agentName) { return __awaiter(void 0,
4146
4162
  * @param {AgentName} agentName - The name of the agent committing the output.
4147
4163
  * @returns {Promise<void>} - A promise that resolves when the operation is complete.
4148
4164
  */
4149
- var commitToolOutput = function (content, clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
4165
+ var commitToolOutput = function (toolId, content, clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
4150
4166
  var swarmName, currentAgentName;
4151
4167
  return __generator(this, function (_a) {
4152
4168
  switch (_a.label) {
4153
4169
  case 0:
4154
4170
  swarm.loggerService.log('function commitToolOutput', {
4171
+ toolId: toolId,
4155
4172
  content: content,
4156
4173
  clientId: clientId,
4157
4174
  agentName: agentName,
@@ -4165,13 +4182,14 @@ var commitToolOutput = function (content, clientId, agentName) { return __awaite
4165
4182
  currentAgentName = _a.sent();
4166
4183
  if (currentAgentName !== agentName) {
4167
4184
  swarm.loggerService.log('function "commitToolOutput" skipped due to the agent change', {
4185
+ toolId: toolId,
4168
4186
  currentAgentName: currentAgentName,
4169
4187
  agentName: agentName,
4170
4188
  clientId: clientId,
4171
4189
  });
4172
4190
  return [2 /*return*/];
4173
4191
  }
4174
- return [4 /*yield*/, swarm.sessionPublicService.commitToolOutput(content, clientId, swarmName)];
4192
+ return [4 /*yield*/, swarm.sessionPublicService.commitToolOutput(toolId, content, clientId, swarmName)];
4175
4193
  case 2:
4176
4194
  _a.sent();
4177
4195
  return [2 /*return*/];
package/build/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { scoped } from 'di-scoped';
2
- import { ToolRegistry, trycatch, sleep, PubsubArrayAdapter, Subject, queued, not, memoize, createAwaiter, cancelable, CANCELED_PROMISE_SYMBOL, schedule, ttl, singleshot, Source } from 'functools-kit';
2
+ import { ToolRegistry, trycatch, sleep, PubsubArrayAdapter, Subject, queued, randomString, not, memoize, createAwaiter, cancelable, CANCELED_PROMISE_SYMBOL, schedule, ttl, singleshot, Source } from 'functools-kit';
3
3
  import { createActivator } from 'di-kit';
4
4
  import { omit } from 'lodash-es';
5
5
  import xml2js from 'xml2js';
@@ -411,6 +411,7 @@ var CC_AGENT_HISTORY_FILTER = function (agentName) { return function (message) {
411
411
  var CC_AGENT_OUTPUT_TRANSFORM = removeXmlTags;
412
412
  var CC_KEEP_MESSAGES = 5;
413
413
  var CC_GET_AGENT_HISTORY = function () { return new PubsubArrayAdapter(); };
414
+ var CC_AGENT_SEPARATE_HISTORY = false;
414
415
  var GLOBAL_CONFIG = {
415
416
  CC_TOOL_CALL_EXCEPTION_PROMPT: CC_TOOL_CALL_EXCEPTION_PROMPT,
416
417
  CC_EMPTY_OUTPUT_PLACEHOLDERS: CC_EMPTY_OUTPUT_PLACEHOLDERS,
@@ -421,6 +422,7 @@ var GLOBAL_CONFIG = {
421
422
  CC_AGENT_DEFAULT_VALIDATION: CC_AGENT_DEFAULT_VALIDATION,
422
423
  CC_AGENT_HISTORY_FILTER: CC_AGENT_HISTORY_FILTER,
423
424
  CC_AGENT_OUTPUT_TRANSFORM: CC_AGENT_OUTPUT_TRANSFORM,
425
+ CC_AGENT_SEPARATE_HISTORY: CC_AGENT_SEPARATE_HISTORY,
424
426
  CC_AGENT_DISALLOWED_TAGS: CC_AGENT_DISALLOWED_TAGS,
425
427
  CC_AGENT_DISALLOWED_SYMBOLS: CC_AGENT_DISALLOWED_SYMBOLS,
426
428
  };
@@ -665,18 +667,19 @@ var ClientAgent = /** @class */ (function () {
665
667
  * @param {string} content - The tool output content.
666
668
  * @returns {Promise<void>}
667
669
  */
668
- this.commitToolOutput = function (content) { return __awaiter(_this, void 0, void 0, function () {
670
+ this.commitToolOutput = function (toolId, content) { return __awaiter(_this, void 0, void 0, function () {
669
671
  return __generator(this, function (_a) {
670
672
  switch (_a.label) {
671
673
  case 0:
672
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitToolOutput"), { content: content });
674
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " commitToolOutput"), { content: content, toolId: toolId });
673
675
  this.params.onToolOutput &&
674
- this.params.onToolOutput(this.params.clientId, this.params.agentName, content);
676
+ this.params.onToolOutput(toolId, this.params.clientId, this.params.agentName, content);
675
677
  return [4 /*yield*/, this.params.history.push({
676
678
  role: "tool",
677
679
  agentName: this.params.agentName,
678
680
  mode: "tool",
679
681
  content: content,
682
+ tool_call_id: toolId,
680
683
  })];
681
684
  case 1:
682
685
  _a.sent();
@@ -695,9 +698,9 @@ var ClientAgent = /** @class */ (function () {
695
698
  this.execute = queued(function (incoming, mode) { return __awaiter(_this, void 0, void 0, function () {
696
699
  var message, _loop_1, this_1, _a, _b, tool, state_1, e_1_1, result, validation, result1;
697
700
  var e_1, _c;
698
- var _d, _e, _f, _g, _h;
699
- return __generator(this, function (_j) {
700
- switch (_j.label) {
701
+ var _d, _e, _f, _g, _h, _j;
702
+ return __generator(this, function (_k) {
703
+ switch (_k.label) {
701
704
  case 0:
702
705
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute begin"), { incoming: incoming, mode: mode });
703
706
  this.params.onExecute &&
@@ -709,45 +712,45 @@ var ClientAgent = /** @class */ (function () {
709
712
  content: incoming.trim(),
710
713
  })];
711
714
  case 1:
712
- _j.sent();
715
+ _k.sent();
713
716
  return [4 /*yield*/, this.getCompletion(mode)];
714
717
  case 2:
715
- message = _j.sent();
718
+ message = _k.sent();
716
719
  if (!message.tool_calls) return [3 /*break*/, 11];
717
720
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " tool call begin"));
718
721
  _loop_1 = function (tool) {
719
722
  var targetFn, result_2, result_3;
720
- return __generator(this, function (_k) {
721
- switch (_k.label) {
723
+ return __generator(this, function (_l) {
724
+ switch (_l.label) {
722
725
  case 0:
723
726
  targetFn = (_d = this_1.params.tools) === null || _d === void 0 ? void 0 : _d.find(function (t) { return t.function.name === tool.function.name; });
724
727
  return [4 /*yield*/, this_1.params.history.push(__assign(__assign({}, message), { agentName: this_1.params.agentName }))];
725
728
  case 1:
726
- _k.sent();
729
+ _l.sent();
727
730
  if (!!targetFn) return [3 /*break*/, 4];
728
731
  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);
729
732
  return [4 /*yield*/, this_1._resurrectModel(mode, "No target function for ".concat(tool.function.name))];
730
733
  case 2:
731
- result_2 = _k.sent();
734
+ result_2 = _l.sent();
732
735
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_2));
733
736
  return [4 /*yield*/, this_1._emitOuput(mode, result_2)];
734
737
  case 3:
735
- _k.sent();
738
+ _l.sent();
736
739
  return [2 /*return*/, { value: void 0 }];
737
740
  case 4:
738
741
  ((_e = targetFn.callbacks) === null || _e === void 0 ? void 0 : _e.onValidate) &&
739
742
  ((_f = targetFn.callbacks) === null || _f === void 0 ? void 0 : _f.onValidate(this_1.params.clientId, this_1.params.agentName, tool.function.arguments));
740
743
  return [4 /*yield*/, not(targetFn.validate(this_1.params.clientId, this_1.params.agentName, tool.function.arguments))];
741
744
  case 5:
742
- if (!_k.sent()) return [3 /*break*/, 8];
745
+ if (!_l.sent()) return [3 /*break*/, 8];
743
746
  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"));
744
747
  return [4 /*yield*/, this_1._resurrectModel(mode, "Function validation failed: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
745
748
  case 6:
746
- result_3 = _k.sent();
749
+ result_3 = _l.sent();
747
750
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_3));
748
751
  return [4 /*yield*/, this_1._emitOuput(mode, result_3)];
749
752
  case 7:
750
- _k.sent();
753
+ _l.sent();
751
754
  return [2 /*return*/, { value: void 0 }];
752
755
  case 8:
753
756
  ((_g = targetFn.callbacks) === null || _g === void 0 ? void 0 : _g.onCall) &&
@@ -755,40 +758,40 @@ var ClientAgent = /** @class */ (function () {
755
758
  /**
756
759
  * @description Do not await to avoid deadlock! The tool can send the message to other agents by emulating user messages
757
760
  */
758
- targetFn.call(this_1.params.clientId, this_1.params.agentName, tool.function.arguments);
761
+ targetFn.call((_j = tool.id) !== null && _j !== void 0 ? _j : randomString(), this_1.params.clientId, this_1.params.agentName, tool.function.arguments);
759
762
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool call executing"));
760
763
  return [4 /*yield*/, Promise.race([
761
764
  this_1._toolCommitSubject.toPromise(),
762
765
  this_1._outputSubject.toPromise(),
763
766
  ])];
764
767
  case 9:
765
- _k.sent();
768
+ _l.sent();
766
769
  this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " functionName=").concat(tool.function.name, " tool call end"));
767
770
  return [2 /*return*/];
768
771
  }
769
772
  });
770
773
  };
771
774
  this_1 = this;
772
- _j.label = 3;
775
+ _k.label = 3;
773
776
  case 3:
774
- _j.trys.push([3, 8, 9, 10]);
777
+ _k.trys.push([3, 8, 9, 10]);
775
778
  _a = __values(message.tool_calls), _b = _a.next();
776
- _j.label = 4;
779
+ _k.label = 4;
777
780
  case 4:
778
781
  if (!!_b.done) return [3 /*break*/, 7];
779
782
  tool = _b.value;
780
783
  return [5 /*yield**/, _loop_1(tool)];
781
784
  case 5:
782
- state_1 = _j.sent();
785
+ state_1 = _k.sent();
783
786
  if (typeof state_1 === "object")
784
787
  return [2 /*return*/, state_1.value];
785
- _j.label = 6;
788
+ _k.label = 6;
786
789
  case 6:
787
790
  _b = _a.next();
788
791
  return [3 /*break*/, 4];
789
792
  case 7: return [3 /*break*/, 10];
790
793
  case 8:
791
- e_1_1 = _j.sent();
794
+ e_1_1 = _k.sent();
792
795
  e_1 = { error: e_1_1 };
793
796
  return [3 /*break*/, 10];
794
797
  case 9:
@@ -805,24 +808,24 @@ var ClientAgent = /** @class */ (function () {
805
808
  result = message.content;
806
809
  return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
807
810
  case 12:
808
- _j.sent();
811
+ _k.sent();
809
812
  validation = null;
810
813
  return [4 /*yield*/, this.params.validate(result)];
811
814
  case 13:
812
- if (!(validation = _j.sent())) return [3 /*break*/, 16];
815
+ if (!(validation = _k.sent())) return [3 /*break*/, 16];
813
816
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute invalid tool call detected: ").concat(validation), { result: result });
814
817
  return [4 /*yield*/, this._resurrectModel(mode, "Invalid model output: ".concat(result))];
815
818
  case 14:
816
- result1 = _j.sent();
819
+ result1 = _k.sent();
817
820
  return [4 /*yield*/, this._emitOuput(mode, result1)];
818
821
  case 15:
819
- _j.sent();
822
+ _k.sent();
820
823
  return [2 /*return*/];
821
824
  case 16:
822
825
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute end result=").concat(result));
823
826
  return [4 /*yield*/, this._emitOuput(mode, result)];
824
827
  case 17:
825
- _j.sent();
828
+ _k.sent();
826
829
  return [2 /*return*/];
827
830
  }
828
831
  });
@@ -914,17 +917,19 @@ var AgentConnectionService = /** @class */ (function () {
914
917
  /**
915
918
  * Commits tool output.
916
919
  * @param {string} content - The tool output content.
920
+ * @param {string} toolId - The `tool_call_id` for openai history
917
921
  * @returns {Promise<any>} The commit result.
918
922
  */
919
- this.commitToolOutput = function (content) { return __awaiter(_this, void 0, void 0, function () {
923
+ this.commitToolOutput = function (toolId, content) { return __awaiter(_this, void 0, void 0, function () {
920
924
  return __generator(this, function (_a) {
921
925
  switch (_a.label) {
922
926
  case 0:
923
927
  this.loggerService.log("agentConnectionService commitToolOutput", {
924
928
  content: content,
929
+ toolId: toolId,
925
930
  context: this.contextService.context,
926
931
  });
927
- return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).commitToolOutput(content)];
932
+ return [4 /*yield*/, this.getAgent(this.contextService.context.clientId, this.contextService.context.agentName).commitToolOutput(toolId, content)];
928
933
  case 1: return [2 /*return*/, _a.sent()];
929
934
  }
930
935
  });
@@ -1287,10 +1292,13 @@ var HistoryConnectionService = /** @class */ (function () {
1287
1292
  this.loggerService.log("historyConnectionService dispose", {
1288
1293
  context: this.contextService.context,
1289
1294
  });
1295
+ if (!GLOBAL_CONFIG.CC_AGENT_SEPARATE_HISTORY) return [3 /*break*/, 2];
1290
1296
  return [4 /*yield*/, this.getItems(this.contextService.context.clientId, this.contextService.context.agentName).clear()];
1291
1297
  case 1:
1292
1298
  _a.sent();
1293
1299
  this.getItems.clear(this.contextService.context.clientId);
1300
+ _a.label = 2;
1301
+ case 2:
1294
1302
  this.getHistory.clear("".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.agentName));
1295
1303
  this.sessionValidationService.removeHistoryUsage(this.contextService.context.clientId, this.contextService.context.agentName);
1296
1304
  return [2 /*return*/];
@@ -1777,21 +1785,23 @@ var ClientSession = /** @class */ (function () {
1777
1785
  }); };
1778
1786
  /**
1779
1787
  * Commits tool output.
1788
+ * @param {string} toolId - The `tool_call_id` for openai history
1780
1789
  * @param {string} content - The content to commit.
1781
1790
  * @returns {Promise<void>}
1782
1791
  */
1783
- this.commitToolOutput = function (content) { return __awaiter(_this, void 0, void 0, function () {
1792
+ this.commitToolOutput = function (toolId, content) { return __awaiter(_this, void 0, void 0, function () {
1784
1793
  var agent;
1785
1794
  return __generator(this, function (_a) {
1786
1795
  switch (_a.label) {
1787
1796
  case 0:
1788
1797
  this.params.logger.debug("ClientSession clientId=".concat(this.params.clientId, " commitToolOutput"), {
1789
1798
  content: content,
1799
+ toolId: toolId,
1790
1800
  });
1791
1801
  return [4 /*yield*/, this.params.swarm.getAgent()];
1792
1802
  case 1:
1793
1803
  agent = _a.sent();
1794
- return [4 /*yield*/, agent.commitToolOutput(content)];
1804
+ return [4 /*yield*/, agent.commitToolOutput(toolId, content)];
1795
1805
  case 2: return [2 /*return*/, _a.sent()];
1796
1806
  }
1797
1807
  });
@@ -1999,18 +2009,20 @@ var SessionConnectionService = /** @class */ (function () {
1999
2009
  };
2000
2010
  /**
2001
2011
  * Commits tool output to the session.
2012
+ * @param {string} toolId - The `tool_call_id` for openai history
2002
2013
  * @param {string} content - The content to commit.
2003
2014
  * @returns {Promise<void>} A promise that resolves when the content is committed.
2004
2015
  */
2005
- this.commitToolOutput = function (content) { return __awaiter(_this, void 0, void 0, function () {
2016
+ this.commitToolOutput = function (toolId, content) { return __awaiter(_this, void 0, void 0, function () {
2006
2017
  return __generator(this, function (_a) {
2007
2018
  switch (_a.label) {
2008
2019
  case 0:
2009
2020
  this.loggerService.log("sessionConnectionService commitToolOutput", {
2010
2021
  context: this.contextService.context,
2011
2022
  content: content,
2023
+ toolId: toolId,
2012
2024
  });
2013
- return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitToolOutput(content)];
2025
+ return [4 /*yield*/, this.getSession(this.contextService.context.clientId, this.contextService.context.swarmName).commitToolOutput(toolId, content)];
2014
2026
  case 1: return [2 /*return*/, _a.sent()];
2015
2027
  }
2016
2028
  });
@@ -2197,12 +2209,13 @@ var AgentPublicService = /** @class */ (function () {
2197
2209
  }); };
2198
2210
  /**
2199
2211
  * Commits tool output to the agent.
2212
+ * @param {string} toolId - The `tool_call_id` for openai history
2200
2213
  * @param {string} content - The content to commit.
2201
2214
  * @param {string} clientId - The client ID.
2202
2215
  * @param {AgentName} agentName - The name of the agent.
2203
2216
  * @returns {Promise<unknown>} The commit result.
2204
2217
  */
2205
- this.commitToolOutput = function (content, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
2218
+ this.commitToolOutput = function (toolId, content, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
2206
2219
  var _this = this;
2207
2220
  return __generator(this, function (_a) {
2208
2221
  switch (_a.label) {
@@ -2210,12 +2223,13 @@ var AgentPublicService = /** @class */ (function () {
2210
2223
  this.loggerService.log("agentPublicService commitToolOutput", {
2211
2224
  content: content,
2212
2225
  clientId: clientId,
2226
+ toolId: toolId,
2213
2227
  agentName: agentName,
2214
2228
  });
2215
2229
  return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
2216
2230
  return __generator(this, function (_a) {
2217
2231
  switch (_a.label) {
2218
- case 0: return [4 /*yield*/, this.agentConnectionService.commitToolOutput(content)];
2232
+ case 0: return [4 /*yield*/, this.agentConnectionService.commitToolOutput(toolId, content)];
2219
2233
  case 1: return [2 /*return*/, _a.sent()];
2220
2234
  }
2221
2235
  });
@@ -2625,17 +2639,19 @@ var SessionPublicService = /** @class */ (function () {
2625
2639
  };
2626
2640
  /**
2627
2641
  * Commits tool output to the session.
2642
+ * @param {string} toolId - The `tool_call_id` for openai history
2628
2643
  * @param {string} content - The content to commit.
2629
2644
  * @param {string} clientId - The client ID.
2630
2645
  * @param {SwarmName} swarmName - The swarm name.
2631
2646
  * @returns {Promise<void>}
2632
2647
  */
2633
- this.commitToolOutput = function (content, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
2648
+ this.commitToolOutput = function (toolId, content, clientId, swarmName) { return __awaiter(_this, void 0, void 0, function () {
2634
2649
  var _this = this;
2635
2650
  return __generator(this, function (_a) {
2636
2651
  switch (_a.label) {
2637
2652
  case 0:
2638
2653
  this.loggerService.log("sessionPublicService commitToolOutput", {
2654
+ toolId: toolId,
2639
2655
  content: content,
2640
2656
  clientId: clientId,
2641
2657
  swarmName: swarmName,
@@ -2643,7 +2659,7 @@ var SessionPublicService = /** @class */ (function () {
2643
2659
  return [4 /*yield*/, ContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
2644
2660
  return __generator(this, function (_a) {
2645
2661
  switch (_a.label) {
2646
- case 0: return [4 /*yield*/, this.sessionConnectionService.commitToolOutput(content)];
2662
+ case 0: return [4 /*yield*/, this.sessionConnectionService.commitToolOutput(toolId, content)];
2647
2663
  case 1: return [2 /*return*/, _a.sent()];
2648
2664
  }
2649
2665
  });
@@ -4144,12 +4160,13 @@ var getAgentHistory = function (clientId, agentName) { return __awaiter(void 0,
4144
4160
  * @param {AgentName} agentName - The name of the agent committing the output.
4145
4161
  * @returns {Promise<void>} - A promise that resolves when the operation is complete.
4146
4162
  */
4147
- var commitToolOutput = function (content, clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
4163
+ var commitToolOutput = function (toolId, content, clientId, agentName) { return __awaiter(void 0, void 0, void 0, function () {
4148
4164
  var swarmName, currentAgentName;
4149
4165
  return __generator(this, function (_a) {
4150
4166
  switch (_a.label) {
4151
4167
  case 0:
4152
4168
  swarm.loggerService.log('function commitToolOutput', {
4169
+ toolId: toolId,
4153
4170
  content: content,
4154
4171
  clientId: clientId,
4155
4172
  agentName: agentName,
@@ -4163,13 +4180,14 @@ var commitToolOutput = function (content, clientId, agentName) { return __awaite
4163
4180
  currentAgentName = _a.sent();
4164
4181
  if (currentAgentName !== agentName) {
4165
4182
  swarm.loggerService.log('function "commitToolOutput" skipped due to the agent change', {
4183
+ toolId: toolId,
4166
4184
  currentAgentName: currentAgentName,
4167
4185
  agentName: agentName,
4168
4186
  clientId: clientId,
4169
4187
  });
4170
4188
  return [2 /*return*/];
4171
4189
  }
4172
- return [4 /*yield*/, swarm.sessionPublicService.commitToolOutput(content, clientId, swarmName)];
4190
+ return [4 /*yield*/, swarm.sessionPublicService.commitToolOutput(toolId, content, clientId, swarmName)];
4173
4191
  case 2:
4174
4192
  _a.sent();
4175
4193
  return [2 /*return*/];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.36",
3
+ "version": "1.0.38",
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
@@ -218,10 +218,11 @@ interface ISession {
218
218
  connect(connector: SendMessageFn$1): ReceiveMessageFn;
219
219
  /**
220
220
  * Commit tool output.
221
+ * @param {string} toolId - The `tool_call_id` for openai history
221
222
  * @param {string} content - The content to commit.
222
223
  * @returns {Promise<void>}
223
224
  */
224
- commitToolOutput(content: string): Promise<void>;
225
+ commitToolOutput(toolId: string, content: string): Promise<void>;
225
226
  /**
226
227
  * Commit user message without answer
227
228
  * @param {string} message - The message to commit.
@@ -257,6 +258,86 @@ type SessionMode = "session" | "makeConnection" | "complete";
257
258
  */
258
259
  type ExecutionMode = "tool" | "user";
259
260
 
261
+ /**
262
+ * Represents a tool call with a function name and arguments.
263
+ */
264
+ interface IToolCall {
265
+ /**
266
+ * The ID of the tool call.
267
+ */
268
+ id: string;
269
+ /**
270
+ * The type of the tool. Currently, only `function` is supported.
271
+ */
272
+ type: 'function';
273
+ /**
274
+ * The function that the model called.
275
+ */
276
+ function: {
277
+ /**
278
+ * The name of the function to be called.
279
+ */
280
+ name: string;
281
+ /**
282
+ * The arguments to be passed to the function.
283
+ */
284
+ arguments: {
285
+ [key: string]: any;
286
+ };
287
+ };
288
+ }
289
+ /**
290
+ * Represents a tool with a type and function details.
291
+ */
292
+ interface ITool {
293
+ /**
294
+ * The type of the tool.
295
+ */
296
+ type: string;
297
+ function: {
298
+ /**
299
+ * The name of the function.
300
+ */
301
+ name: string;
302
+ /**
303
+ * The description of the function.
304
+ */
305
+ description: string;
306
+ /**
307
+ * The parameters required by the function.
308
+ */
309
+ parameters: {
310
+ /**
311
+ * The type of the parameters.
312
+ */
313
+ type: string;
314
+ /**
315
+ * The list of required parameters.
316
+ */
317
+ required: string[];
318
+ /**
319
+ * The properties of the parameters.
320
+ */
321
+ properties: {
322
+ [key: string]: {
323
+ /**
324
+ * The type of the property.
325
+ */
326
+ type: string;
327
+ /**
328
+ * The description of the property.
329
+ */
330
+ description: string;
331
+ /**
332
+ * The possible values for the property.
333
+ */
334
+ enum?: string[];
335
+ };
336
+ };
337
+ };
338
+ };
339
+ }
340
+
260
341
  /**
261
342
  * Interface representing a model message.
262
343
  */
@@ -285,14 +366,11 @@ interface IModelMessage {
285
366
  * Optional tool calls associated with the message.
286
367
  * @type {Array<{ function: { name: string; arguments: { [key: string]: any; }; }; }>}
287
368
  */
288
- tool_calls?: {
289
- function: {
290
- name: string;
291
- arguments: {
292
- [key: string]: any;
293
- };
294
- };
295
- }[];
369
+ tool_calls?: IToolCall[];
370
+ /**
371
+ * Tool call that this message is responding to.
372
+ */
373
+ tool_call_id?: string;
296
374
  }
297
375
 
298
376
  /**
@@ -348,75 +426,6 @@ interface IHistorySchema {
348
426
  items: IPubsubArray<IModelMessage>;
349
427
  }
350
428
 
351
- /**
352
- * Represents a tool call with a function name and arguments.
353
- */
354
- interface IToolCall {
355
- function: {
356
- /**
357
- * The name of the function to be called.
358
- */
359
- name: string;
360
- /**
361
- * The arguments to be passed to the function.
362
- */
363
- arguments: {
364
- [key: string]: any;
365
- };
366
- };
367
- }
368
- /**
369
- * Represents a tool with a type and function details.
370
- */
371
- interface ITool {
372
- /**
373
- * The type of the tool.
374
- */
375
- type: string;
376
- function: {
377
- /**
378
- * The name of the function.
379
- */
380
- name: string;
381
- /**
382
- * The description of the function.
383
- */
384
- description: string;
385
- /**
386
- * The parameters required by the function.
387
- */
388
- parameters: {
389
- /**
390
- * The type of the parameters.
391
- */
392
- type: string;
393
- /**
394
- * The list of required parameters.
395
- */
396
- required: string[];
397
- /**
398
- * The properties of the parameters.
399
- */
400
- properties: {
401
- [key: string]: {
402
- /**
403
- * The type of the property.
404
- */
405
- type: string;
406
- /**
407
- * The description of the property.
408
- */
409
- description: string;
410
- /**
411
- * The possible values for the property.
412
- */
413
- enum?: string[];
414
- };
415
- };
416
- };
417
- };
418
- }
419
-
420
429
  /**
421
430
  * Interface representing a completion.
422
431
  */
@@ -518,7 +527,7 @@ interface IAgentTool<T = Record<string, unknown>> extends ITool {
518
527
  * @param params - The parameters for the tool.
519
528
  * @returns A promise that resolves when the tool call is complete.
520
529
  */
521
- call(clientId: string, agentName: AgentName, params: T): Promise<void>;
530
+ call(toolId: string, clientId: string, agentName: AgentName, params: T): Promise<void>;
522
531
  /**
523
532
  * Validates the parameters for the tool.
524
533
  * @param clientId - The ID of the client.
@@ -569,11 +578,12 @@ interface IAgentSchemaCallbacks {
569
578
  onExecute?: (clientId: string, agentName: AgentName, input: string, mode: ExecutionMode) => void;
570
579
  /**
571
580
  * Callback triggered when there is tool output.
581
+ * @param toolId - The `tool_call_id` for openai history
572
582
  * @param clientId - The ID of the client.
573
583
  * @param agentName - The name of the agent.
574
584
  * @param content - The content of the tool output.
575
585
  */
576
- onToolOutput?: (clientId: string, agentName: AgentName, content: string) => void;
586
+ onToolOutput?: (toolId: string, clientId: string, agentName: AgentName, content: string) => void;
577
587
  /**
578
588
  * Callback triggered when there is a system message.
579
589
  * @param clientId - The ID of the client.
@@ -665,10 +675,11 @@ interface IAgent {
665
675
  waitForOutput: () => Promise<string>;
666
676
  /**
667
677
  * Commits the tool output.
678
+ * @param {string} toolId - The `tool_call_id` for openai history
668
679
  * @param content - The content of the tool output.
669
680
  * @returns A promise that resolves when the tool output is committed.
670
681
  */
671
- commitToolOutput(content: string): Promise<void>;
682
+ commitToolOutput(toolId: string, content: string): Promise<void>;
672
683
  /**
673
684
  * Commits a system message.
674
685
  * @param message - The system message to commit.
@@ -793,7 +804,7 @@ declare class ClientAgent implements IAgent {
793
804
  * @param {string} content - The tool output content.
794
805
  * @returns {Promise<void>}
795
806
  */
796
- commitToolOutput: (content: string) => Promise<void>;
807
+ commitToolOutput: (toolId: string, content: string) => Promise<void>;
797
808
  /**
798
809
  * Executes the incoming message and processes tool calls if any.
799
810
  * @param {string} incoming - The incoming message content.
@@ -840,9 +851,10 @@ declare class AgentConnectionService implements IAgent {
840
851
  /**
841
852
  * Commits tool output.
842
853
  * @param {string} content - The tool output content.
854
+ * @param {string} toolId - The `tool_call_id` for openai history
843
855
  * @returns {Promise<any>} The commit result.
844
856
  */
845
- commitToolOutput: (content: string) => Promise<void>;
857
+ commitToolOutput: (toolId: string, content: string) => Promise<void>;
846
858
  /**
847
859
  * Commits a system message.
848
860
  * @param {string} message - The system message.
@@ -1148,10 +1160,11 @@ declare class ClientSession implements ISession {
1148
1160
  execute: (message: string, mode: ExecutionMode) => Promise<string>;
1149
1161
  /**
1150
1162
  * Commits tool output.
1163
+ * @param {string} toolId - The `tool_call_id` for openai history
1151
1164
  * @param {string} content - The content to commit.
1152
1165
  * @returns {Promise<void>}
1153
1166
  */
1154
- commitToolOutput: (content: string) => Promise<void>;
1167
+ commitToolOutput: (toolId: string, content: string) => Promise<void>;
1155
1168
  /**
1156
1169
  * Commits user message without answer.
1157
1170
  * @param {string} message - The message to commit.
@@ -1218,10 +1231,11 @@ declare class SessionConnectionService implements ISession {
1218
1231
  connect: (connector: SendMessageFn$1) => ReceiveMessageFn;
1219
1232
  /**
1220
1233
  * Commits tool output to the session.
1234
+ * @param {string} toolId - The `tool_call_id` for openai history
1221
1235
  * @param {string} content - The content to commit.
1222
1236
  * @returns {Promise<void>} A promise that resolves when the content is committed.
1223
1237
  */
1224
- commitToolOutput: (content: string) => Promise<void>;
1238
+ commitToolOutput: (toolId: string, content: string) => Promise<void>;
1225
1239
  /**
1226
1240
  * Commits a system message to the session.
1227
1241
  * @param {string} message - The message to commit.
@@ -1285,12 +1299,13 @@ declare class AgentPublicService implements TAgentConnectionService {
1285
1299
  waitForOutput: (clientId: string, agentName: AgentName) => Promise<string>;
1286
1300
  /**
1287
1301
  * Commits tool output to the agent.
1302
+ * @param {string} toolId - The `tool_call_id` for openai history
1288
1303
  * @param {string} content - The content to commit.
1289
1304
  * @param {string} clientId - The client ID.
1290
1305
  * @param {AgentName} agentName - The name of the agent.
1291
1306
  * @returns {Promise<unknown>} The commit result.
1292
1307
  */
1293
- commitToolOutput: (content: string, clientId: string, agentName: AgentName) => Promise<void>;
1308
+ commitToolOutput: (toolId: string, content: string, clientId: string, agentName: AgentName) => Promise<void>;
1294
1309
  /**
1295
1310
  * Commits a system message to the agent.
1296
1311
  * @param {string} message - The message to commit.
@@ -1410,12 +1425,13 @@ declare class SessionPublicService implements TSessionConnectionService {
1410
1425
  connect: (connector: SendMessageFn$1, clientId: string, swarmName: SwarmName) => ReceiveMessageFn;
1411
1426
  /**
1412
1427
  * Commits tool output to the session.
1428
+ * @param {string} toolId - The `tool_call_id` for openai history
1413
1429
  * @param {string} content - The content to commit.
1414
1430
  * @param {string} clientId - The client ID.
1415
1431
  * @param {SwarmName} swarmName - The swarm name.
1416
1432
  * @returns {Promise<void>}
1417
1433
  */
1418
- commitToolOutput: (content: string, clientId: string, swarmName: SwarmName) => Promise<void>;
1434
+ commitToolOutput: (toolId: string, content: string, clientId: string, swarmName: SwarmName) => Promise<void>;
1419
1435
  /**
1420
1436
  * Commits a system message to the session.
1421
1437
  * @param {string} message - The message to commit.
@@ -1907,7 +1923,7 @@ declare const getAgentHistory: (clientId: string, agentName: AgentName) => Promi
1907
1923
  * @param {AgentName} agentName - The name of the agent committing the output.
1908
1924
  * @returns {Promise<void>} - A promise that resolves when the operation is complete.
1909
1925
  */
1910
- declare const commitToolOutput: (content: string, clientId: string, agentName: AgentName) => Promise<void>;
1926
+ declare const commitToolOutput: (toolId: string, content: string, clientId: string, agentName: AgentName) => Promise<void>;
1911
1927
 
1912
1928
  /**
1913
1929
  * Commits a system message to the active agent in as swarm.
@@ -2052,6 +2068,7 @@ declare const GLOBAL_CONFIG: {
2052
2068
  CC_AGENT_DEFAULT_VALIDATION: (output: string) => Promise<string | null>;
2053
2069
  CC_AGENT_HISTORY_FILTER: (agentName: AgentName) => (message: IModelMessage) => boolean;
2054
2070
  CC_AGENT_OUTPUT_TRANSFORM: (input: string) => string;
2071
+ CC_AGENT_SEPARATE_HISTORY: boolean;
2055
2072
  CC_AGENT_DISALLOWED_TAGS: string[];
2056
2073
  CC_AGENT_DISALLOWED_SYMBOLS: string[];
2057
2074
  };