agent-swarm-kit 1.0.140 → 1.0.141

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
@@ -1814,6 +1814,7 @@ var AgentSchemaService = /** @class */ (function () {
1814
1814
  }());
1815
1815
 
1816
1816
  var AGENT_CHANGE_SYMBOL = Symbol("agent-change");
1817
+ var MODEL_RESQUE_SYMBOL = Symbol("model-resque");
1817
1818
  var TOOL_ERROR_SYMBOL = Symbol("tool-error");
1818
1819
  var TOOL_STOP_SYMBOL = Symbol("tool-stop");
1819
1820
  var TOOL_NO_OUTPUT_WARNING = 15000;
@@ -1896,9 +1897,9 @@ var RUN_FN = function (incoming, self) { return __awaiter(void 0, void 0, void 0
1896
1897
  }); };
1897
1898
  var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void 0, void 0, function () {
1898
1899
  var rawMessage, message, toolCalls, _loop_1, idx, state_1, result, validation, result1;
1899
- var _a, _b, _c, _d, _e, _f, _g, _h;
1900
- return __generator(this, function (_j) {
1901
- switch (_j.label) {
1900
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1901
+ return __generator(this, function (_k) {
1902
+ switch (_k.label) {
1902
1903
  case 0:
1903
1904
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
1904
1905
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " execute begin"), { incoming: incoming, mode: mode });
@@ -1911,35 +1912,34 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
1911
1912
  content: incoming.trim(),
1912
1913
  })];
1913
1914
  case 1:
1914
- _j.sent();
1915
+ _k.sent();
1915
1916
  return [4 /*yield*/, self.getCompletion(mode)];
1916
1917
  case 2:
1917
- rawMessage = _j.sent();
1918
+ rawMessage = _k.sent();
1918
1919
  return [4 /*yield*/, self.params.map(rawMessage, self.params.clientId, self.params.agentName)];
1919
1920
  case 3:
1920
- message = _j.sent();
1921
+ message = _k.sent();
1921
1922
  if (!message.tool_calls) return [3 /*break*/, 9];
1922
1923
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
1923
1924
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " tool call begin"));
1924
- toolCalls = message.tool_calls.map(function (call) {
1925
+ toolCalls = message.tool_calls
1926
+ .map(function (call) {
1925
1927
  var _a, _b;
1926
1928
  return ({
1927
1929
  function: call.function,
1928
1930
  id: (_a = call.id) !== null && _a !== void 0 ? _a : functoolsKit.randomString(),
1929
1931
  type: (_b = call.type) !== null && _b !== void 0 ? _b : "function",
1930
1932
  });
1931
- });
1933
+ })
1934
+ .slice(0, GLOBAL_CONFIG.CC_MAX_TOOLS);
1932
1935
  return [4 /*yield*/, self.params.history.push(__assign(__assign({}, message), { agentName: self.params.agentName }))];
1933
1936
  case 4:
1934
- _j.sent();
1937
+ _k.sent();
1935
1938
  _loop_1 = function (idx) {
1936
1939
  var tool, targetFn, result_1, result_2, isResolved, status, result_3;
1937
- return __generator(this, function (_k) {
1938
- switch (_k.label) {
1940
+ return __generator(this, function (_l) {
1941
+ switch (_l.label) {
1939
1942
  case 0:
1940
- if (idx >= GLOBAL_CONFIG.CC_MAX_TOOLS) {
1941
- return [2 /*return*/, "break"];
1942
- }
1943
1943
  tool = toolCalls[idx];
1944
1944
  targetFn = (_a = self.params.tools) === null || _a === void 0 ? void 0 : _a.find(function (t) { return t.function.name === tool.function.name; });
1945
1945
  if (!!targetFn) return [3 /*break*/, 3];
@@ -1947,12 +1947,12 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
1947
1947
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " tool function not found"), self.params.tools);
1948
1948
  return [4 /*yield*/, self._resurrectModel(mode, "No target function for ".concat(tool.function.name))];
1949
1949
  case 1:
1950
- result_1 = _k.sent();
1950
+ result_1 = _l.sent();
1951
1951
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
1952
1952
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " execute end result=").concat(result_1));
1953
1953
  return [4 /*yield*/, self._emitOuput(mode, result_1)];
1954
1954
  case 2:
1955
- _k.sent();
1955
+ _l.sent();
1956
1956
  return [2 /*return*/, { value: void 0 }];
1957
1957
  case 3:
1958
1958
  ((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onValidate) &&
@@ -1964,17 +1964,17 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
1964
1964
  toolCalls: toolCalls,
1965
1965
  }))];
1966
1966
  case 4:
1967
- if (!_k.sent()) return [3 /*break*/, 7];
1967
+ if (!_l.sent()) return [3 /*break*/, 7];
1968
1968
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
1969
1969
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " tool validation not passed"));
1970
1970
  return [4 /*yield*/, self._resurrectModel(mode, "Function validation failed: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
1971
1971
  case 5:
1972
- result_2 = _k.sent();
1972
+ result_2 = _l.sent();
1973
1973
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
1974
1974
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " execute end result=").concat(result_2));
1975
1975
  return [4 /*yield*/, self._emitOuput(mode, result_2)];
1976
1976
  case 6:
1977
- _k.sent();
1977
+ _l.sent();
1978
1978
  return [2 /*return*/, { value: void 0 }];
1979
1979
  case 7:
1980
1980
  ((_d = targetFn.callbacks) === null || _d === void 0 ? void 0 : _d.onBeforeCall) &&
@@ -2022,23 +2022,31 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
2022
2022
  self._toolErrorSubject.toPromise(),
2023
2023
  self._toolStopSubject.toPromise(),
2024
2024
  self._outputSubject.toPromise(),
2025
+ self._modelResqueSubject.toPromise(),
2025
2026
  ])];
2026
2027
  case 8:
2027
- status = _k.sent();
2028
+ status = _l.sent();
2028
2029
  isResolved = true;
2029
2030
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2030
2031
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " tool call end"));
2032
+ if (status === MODEL_RESQUE_SYMBOL) {
2033
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2034
+ self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " the next tool execution stopped due to the model resque"));
2035
+ ((_f = self.params.callbacks) === null || _f === void 0 ? void 0 : _f.onAfterToolCalls) &&
2036
+ self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls);
2037
+ return [2 /*return*/, { value: void 0 }];
2038
+ }
2031
2039
  if (status === AGENT_CHANGE_SYMBOL) {
2032
2040
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2033
2041
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " the next tool execution stopped due to the agent changed"));
2034
- ((_f = self.params.callbacks) === null || _f === void 0 ? void 0 : _f.onAfterToolCalls) &&
2042
+ ((_g = self.params.callbacks) === null || _g === void 0 ? void 0 : _g.onAfterToolCalls) &&
2035
2043
  self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls);
2036
2044
  return [2 /*return*/, { value: void 0 }];
2037
2045
  }
2038
2046
  if (status === TOOL_STOP_SYMBOL) {
2039
2047
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2040
2048
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " the next tool execution stopped due to the commitStopTools call"));
2041
- ((_g = self.params.callbacks) === null || _g === void 0 ? void 0 : _g.onAfterToolCalls) &&
2049
+ ((_h = self.params.callbacks) === null || _h === void 0 ? void 0 : _h.onAfterToolCalls) &&
2042
2050
  self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls);
2043
2051
  return [2 /*return*/, { value: void 0 }];
2044
2052
  }
@@ -2047,34 +2055,32 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
2047
2055
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " the next tool execution stopped due to the call error"));
2048
2056
  return [4 /*yield*/, self._resurrectModel(mode, "Function call failed with error: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
2049
2057
  case 9:
2050
- result_3 = _k.sent();
2058
+ result_3 = _l.sent();
2051
2059
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2052
2060
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " execute end result=").concat(result_3));
2053
2061
  return [4 /*yield*/, self._emitOuput(mode, result_3)];
2054
2062
  case 10:
2055
- _k.sent();
2063
+ _l.sent();
2056
2064
  return [2 /*return*/, { value: void 0 }];
2057
2065
  case 11: return [2 /*return*/];
2058
2066
  }
2059
2067
  });
2060
2068
  };
2061
2069
  idx = 0;
2062
- _j.label = 5;
2070
+ _k.label = 5;
2063
2071
  case 5:
2064
2072
  if (!(idx !== toolCalls.length)) return [3 /*break*/, 8];
2065
2073
  return [5 /*yield**/, _loop_1(idx)];
2066
2074
  case 6:
2067
- state_1 = _j.sent();
2075
+ state_1 = _k.sent();
2068
2076
  if (typeof state_1 === "object")
2069
2077
  return [2 /*return*/, state_1.value];
2070
- if (state_1 === "break")
2071
- return [3 /*break*/, 8];
2072
- _j.label = 7;
2078
+ _k.label = 7;
2073
2079
  case 7:
2074
2080
  idx++;
2075
2081
  return [3 /*break*/, 5];
2076
2082
  case 8:
2077
- ((_h = self.params.callbacks) === null || _h === void 0 ? void 0 : _h.onAfterToolCalls) &&
2083
+ ((_j = self.params.callbacks) === null || _j === void 0 ? void 0 : _j.onAfterToolCalls) &&
2078
2084
  self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls);
2079
2085
  return [2 /*return*/];
2080
2086
  case 9:
@@ -2084,29 +2090,29 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
2084
2090
  }
2085
2091
  return [4 /*yield*/, self.params.transform(message.content, self.params.clientId, self.params.agentName)];
2086
2092
  case 10:
2087
- result = _j.sent();
2093
+ result = _k.sent();
2088
2094
  return [4 /*yield*/, self.params.history.push(__assign(__assign({}, message), { agentName: self.params.agentName }))];
2089
2095
  case 11:
2090
- _j.sent();
2096
+ _k.sent();
2091
2097
  validation = null;
2092
2098
  return [4 /*yield*/, self.params.validate(result)];
2093
2099
  case 12:
2094
- if (!(validation = _j.sent())) return [3 /*break*/, 15];
2100
+ if (!(validation = _k.sent())) return [3 /*break*/, 15];
2095
2101
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2096
2102
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " execute invalid tool call detected: ").concat(validation), { result: result });
2097
2103
  return [4 /*yield*/, self._resurrectModel(mode, "Invalid model output: ".concat(result))];
2098
2104
  case 13:
2099
- result1 = _j.sent();
2105
+ result1 = _k.sent();
2100
2106
  return [4 /*yield*/, self._emitOuput(mode, result1)];
2101
2107
  case 14:
2102
- _j.sent();
2108
+ _k.sent();
2103
2109
  return [2 /*return*/];
2104
2110
  case 15:
2105
2111
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2106
2112
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " execute end result=").concat(result));
2107
2113
  return [4 /*yield*/, self._emitOuput(mode, result)];
2108
2114
  case 16:
2109
- _j.sent();
2115
+ _k.sent();
2110
2116
  return [2 /*return*/];
2111
2117
  }
2112
2118
  });
@@ -2124,6 +2130,7 @@ var ClientAgent = /** @class */ (function () {
2124
2130
  var _this = this;
2125
2131
  this.params = params;
2126
2132
  this._agentChangeSubject = new functoolsKit.Subject();
2133
+ this._modelResqueSubject = new functoolsKit.Subject();
2127
2134
  this._toolErrorSubject = new functoolsKit.Subject();
2128
2135
  this._toolStopSubject = new functoolsKit.Subject();
2129
2136
  this._toolCommitSubject = new functoolsKit.Subject();
@@ -2306,7 +2313,7 @@ var ClientAgent = /** @class */ (function () {
2306
2313
  validation = null;
2307
2314
  return [4 /*yield*/, this.params.validate(result)];
2308
2315
  case 12:
2309
- if (!(validation = _a.sent())) return [3 /*break*/, 14];
2316
+ if (!(validation = _a.sent())) return [3 /*break*/, 15];
2310
2317
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2311
2318
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel validation error: ").concat(validation));
2312
2319
  console.warn("agent-swarm model ressurect did not solved the problem for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY));
@@ -2318,10 +2325,16 @@ var ClientAgent = /** @class */ (function () {
2318
2325
  content: content,
2319
2326
  })];
2320
2327
  case 13:
2328
+ _a.sent();
2329
+ return [4 /*yield*/, this._modelResqueSubject.next(MODEL_RESQUE_SYMBOL)];
2330
+ case 14:
2321
2331
  _a.sent();
2322
2332
  return [2 /*return*/, content];
2323
- case 14: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2324
- case 15:
2333
+ case 15: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2334
+ case 16:
2335
+ _a.sent();
2336
+ return [4 /*yield*/, this._modelResqueSubject.next(MODEL_RESQUE_SYMBOL)];
2337
+ case 17:
2325
2338
  _a.sent();
2326
2339
  return [2 /*return*/, result];
2327
2340
  }
package/build/index.mjs CHANGED
@@ -1812,6 +1812,7 @@ var AgentSchemaService = /** @class */ (function () {
1812
1812
  }());
1813
1813
 
1814
1814
  var AGENT_CHANGE_SYMBOL = Symbol("agent-change");
1815
+ var MODEL_RESQUE_SYMBOL = Symbol("model-resque");
1815
1816
  var TOOL_ERROR_SYMBOL = Symbol("tool-error");
1816
1817
  var TOOL_STOP_SYMBOL = Symbol("tool-stop");
1817
1818
  var TOOL_NO_OUTPUT_WARNING = 15000;
@@ -1894,9 +1895,9 @@ var RUN_FN = function (incoming, self) { return __awaiter(void 0, void 0, void 0
1894
1895
  }); };
1895
1896
  var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void 0, void 0, function () {
1896
1897
  var rawMessage, message, toolCalls, _loop_1, idx, state_1, result, validation, result1;
1897
- var _a, _b, _c, _d, _e, _f, _g, _h;
1898
- return __generator(this, function (_j) {
1899
- switch (_j.label) {
1898
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1899
+ return __generator(this, function (_k) {
1900
+ switch (_k.label) {
1900
1901
  case 0:
1901
1902
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
1902
1903
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " execute begin"), { incoming: incoming, mode: mode });
@@ -1909,35 +1910,34 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
1909
1910
  content: incoming.trim(),
1910
1911
  })];
1911
1912
  case 1:
1912
- _j.sent();
1913
+ _k.sent();
1913
1914
  return [4 /*yield*/, self.getCompletion(mode)];
1914
1915
  case 2:
1915
- rawMessage = _j.sent();
1916
+ rawMessage = _k.sent();
1916
1917
  return [4 /*yield*/, self.params.map(rawMessage, self.params.clientId, self.params.agentName)];
1917
1918
  case 3:
1918
- message = _j.sent();
1919
+ message = _k.sent();
1919
1920
  if (!message.tool_calls) return [3 /*break*/, 9];
1920
1921
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
1921
1922
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " tool call begin"));
1922
- toolCalls = message.tool_calls.map(function (call) {
1923
+ toolCalls = message.tool_calls
1924
+ .map(function (call) {
1923
1925
  var _a, _b;
1924
1926
  return ({
1925
1927
  function: call.function,
1926
1928
  id: (_a = call.id) !== null && _a !== void 0 ? _a : randomString(),
1927
1929
  type: (_b = call.type) !== null && _b !== void 0 ? _b : "function",
1928
1930
  });
1929
- });
1931
+ })
1932
+ .slice(0, GLOBAL_CONFIG.CC_MAX_TOOLS);
1930
1933
  return [4 /*yield*/, self.params.history.push(__assign(__assign({}, message), { agentName: self.params.agentName }))];
1931
1934
  case 4:
1932
- _j.sent();
1935
+ _k.sent();
1933
1936
  _loop_1 = function (idx) {
1934
1937
  var tool, targetFn, result_1, result_2, isResolved, status, result_3;
1935
- return __generator(this, function (_k) {
1936
- switch (_k.label) {
1938
+ return __generator(this, function (_l) {
1939
+ switch (_l.label) {
1937
1940
  case 0:
1938
- if (idx >= GLOBAL_CONFIG.CC_MAX_TOOLS) {
1939
- return [2 /*return*/, "break"];
1940
- }
1941
1941
  tool = toolCalls[idx];
1942
1942
  targetFn = (_a = self.params.tools) === null || _a === void 0 ? void 0 : _a.find(function (t) { return t.function.name === tool.function.name; });
1943
1943
  if (!!targetFn) return [3 /*break*/, 3];
@@ -1945,12 +1945,12 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
1945
1945
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " tool function not found"), self.params.tools);
1946
1946
  return [4 /*yield*/, self._resurrectModel(mode, "No target function for ".concat(tool.function.name))];
1947
1947
  case 1:
1948
- result_1 = _k.sent();
1948
+ result_1 = _l.sent();
1949
1949
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
1950
1950
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " execute end result=").concat(result_1));
1951
1951
  return [4 /*yield*/, self._emitOuput(mode, result_1)];
1952
1952
  case 2:
1953
- _k.sent();
1953
+ _l.sent();
1954
1954
  return [2 /*return*/, { value: void 0 }];
1955
1955
  case 3:
1956
1956
  ((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onValidate) &&
@@ -1962,17 +1962,17 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
1962
1962
  toolCalls: toolCalls,
1963
1963
  }))];
1964
1964
  case 4:
1965
- if (!_k.sent()) return [3 /*break*/, 7];
1965
+ if (!_l.sent()) return [3 /*break*/, 7];
1966
1966
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
1967
1967
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " tool validation not passed"));
1968
1968
  return [4 /*yield*/, self._resurrectModel(mode, "Function validation failed: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
1969
1969
  case 5:
1970
- result_2 = _k.sent();
1970
+ result_2 = _l.sent();
1971
1971
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
1972
1972
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " execute end result=").concat(result_2));
1973
1973
  return [4 /*yield*/, self._emitOuput(mode, result_2)];
1974
1974
  case 6:
1975
- _k.sent();
1975
+ _l.sent();
1976
1976
  return [2 /*return*/, { value: void 0 }];
1977
1977
  case 7:
1978
1978
  ((_d = targetFn.callbacks) === null || _d === void 0 ? void 0 : _d.onBeforeCall) &&
@@ -2020,23 +2020,31 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
2020
2020
  self._toolErrorSubject.toPromise(),
2021
2021
  self._toolStopSubject.toPromise(),
2022
2022
  self._outputSubject.toPromise(),
2023
+ self._modelResqueSubject.toPromise(),
2023
2024
  ])];
2024
2025
  case 8:
2025
- status = _k.sent();
2026
+ status = _l.sent();
2026
2027
  isResolved = true;
2027
2028
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2028
2029
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " tool call end"));
2030
+ if (status === MODEL_RESQUE_SYMBOL) {
2031
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2032
+ self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " the next tool execution stopped due to the model resque"));
2033
+ ((_f = self.params.callbacks) === null || _f === void 0 ? void 0 : _f.onAfterToolCalls) &&
2034
+ self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls);
2035
+ return [2 /*return*/, { value: void 0 }];
2036
+ }
2029
2037
  if (status === AGENT_CHANGE_SYMBOL) {
2030
2038
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2031
2039
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " the next tool execution stopped due to the agent changed"));
2032
- ((_f = self.params.callbacks) === null || _f === void 0 ? void 0 : _f.onAfterToolCalls) &&
2040
+ ((_g = self.params.callbacks) === null || _g === void 0 ? void 0 : _g.onAfterToolCalls) &&
2033
2041
  self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls);
2034
2042
  return [2 /*return*/, { value: void 0 }];
2035
2043
  }
2036
2044
  if (status === TOOL_STOP_SYMBOL) {
2037
2045
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2038
2046
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " the next tool execution stopped due to the commitStopTools call"));
2039
- ((_g = self.params.callbacks) === null || _g === void 0 ? void 0 : _g.onAfterToolCalls) &&
2047
+ ((_h = self.params.callbacks) === null || _h === void 0 ? void 0 : _h.onAfterToolCalls) &&
2040
2048
  self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls);
2041
2049
  return [2 /*return*/, { value: void 0 }];
2042
2050
  }
@@ -2045,34 +2053,32 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
2045
2053
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " the next tool execution stopped due to the call error"));
2046
2054
  return [4 /*yield*/, self._resurrectModel(mode, "Function call failed with error: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
2047
2055
  case 9:
2048
- result_3 = _k.sent();
2056
+ result_3 = _l.sent();
2049
2057
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2050
2058
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " execute end result=").concat(result_3));
2051
2059
  return [4 /*yield*/, self._emitOuput(mode, result_3)];
2052
2060
  case 10:
2053
- _k.sent();
2061
+ _l.sent();
2054
2062
  return [2 /*return*/, { value: void 0 }];
2055
2063
  case 11: return [2 /*return*/];
2056
2064
  }
2057
2065
  });
2058
2066
  };
2059
2067
  idx = 0;
2060
- _j.label = 5;
2068
+ _k.label = 5;
2061
2069
  case 5:
2062
2070
  if (!(idx !== toolCalls.length)) return [3 /*break*/, 8];
2063
2071
  return [5 /*yield**/, _loop_1(idx)];
2064
2072
  case 6:
2065
- state_1 = _j.sent();
2073
+ state_1 = _k.sent();
2066
2074
  if (typeof state_1 === "object")
2067
2075
  return [2 /*return*/, state_1.value];
2068
- if (state_1 === "break")
2069
- return [3 /*break*/, 8];
2070
- _j.label = 7;
2076
+ _k.label = 7;
2071
2077
  case 7:
2072
2078
  idx++;
2073
2079
  return [3 /*break*/, 5];
2074
2080
  case 8:
2075
- ((_h = self.params.callbacks) === null || _h === void 0 ? void 0 : _h.onAfterToolCalls) &&
2081
+ ((_j = self.params.callbacks) === null || _j === void 0 ? void 0 : _j.onAfterToolCalls) &&
2076
2082
  self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls);
2077
2083
  return [2 /*return*/];
2078
2084
  case 9:
@@ -2082,29 +2088,29 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
2082
2088
  }
2083
2089
  return [4 /*yield*/, self.params.transform(message.content, self.params.clientId, self.params.agentName)];
2084
2090
  case 10:
2085
- result = _j.sent();
2091
+ result = _k.sent();
2086
2092
  return [4 /*yield*/, self.params.history.push(__assign(__assign({}, message), { agentName: self.params.agentName }))];
2087
2093
  case 11:
2088
- _j.sent();
2094
+ _k.sent();
2089
2095
  validation = null;
2090
2096
  return [4 /*yield*/, self.params.validate(result)];
2091
2097
  case 12:
2092
- if (!(validation = _j.sent())) return [3 /*break*/, 15];
2098
+ if (!(validation = _k.sent())) return [3 /*break*/, 15];
2093
2099
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2094
2100
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " execute invalid tool call detected: ").concat(validation), { result: result });
2095
2101
  return [4 /*yield*/, self._resurrectModel(mode, "Invalid model output: ".concat(result))];
2096
2102
  case 13:
2097
- result1 = _j.sent();
2103
+ result1 = _k.sent();
2098
2104
  return [4 /*yield*/, self._emitOuput(mode, result1)];
2099
2105
  case 14:
2100
- _j.sent();
2106
+ _k.sent();
2101
2107
  return [2 /*return*/];
2102
2108
  case 15:
2103
2109
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2104
2110
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " execute end result=").concat(result));
2105
2111
  return [4 /*yield*/, self._emitOuput(mode, result)];
2106
2112
  case 16:
2107
- _j.sent();
2113
+ _k.sent();
2108
2114
  return [2 /*return*/];
2109
2115
  }
2110
2116
  });
@@ -2122,6 +2128,7 @@ var ClientAgent = /** @class */ (function () {
2122
2128
  var _this = this;
2123
2129
  this.params = params;
2124
2130
  this._agentChangeSubject = new Subject();
2131
+ this._modelResqueSubject = new Subject();
2125
2132
  this._toolErrorSubject = new Subject();
2126
2133
  this._toolStopSubject = new Subject();
2127
2134
  this._toolCommitSubject = new Subject();
@@ -2304,7 +2311,7 @@ var ClientAgent = /** @class */ (function () {
2304
2311
  validation = null;
2305
2312
  return [4 /*yield*/, this.params.validate(result)];
2306
2313
  case 12:
2307
- if (!(validation = _a.sent())) return [3 /*break*/, 14];
2314
+ if (!(validation = _a.sent())) return [3 /*break*/, 15];
2308
2315
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2309
2316
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel validation error: ").concat(validation));
2310
2317
  console.warn("agent-swarm model ressurect did not solved the problem for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY));
@@ -2316,10 +2323,16 @@ var ClientAgent = /** @class */ (function () {
2316
2323
  content: content,
2317
2324
  })];
2318
2325
  case 13:
2326
+ _a.sent();
2327
+ return [4 /*yield*/, this._modelResqueSubject.next(MODEL_RESQUE_SYMBOL)];
2328
+ case 14:
2319
2329
  _a.sent();
2320
2330
  return [2 /*return*/, content];
2321
- case 14: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2322
- case 15:
2331
+ case 15: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2332
+ case 16:
2333
+ _a.sent();
2334
+ return [4 /*yield*/, this._modelResqueSubject.next(MODEL_RESQUE_SYMBOL)];
2335
+ case 17:
2323
2336
  _a.sent();
2324
2337
  return [2 /*return*/, result];
2325
2338
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.140",
3
+ "version": "1.0.141",
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
@@ -1807,6 +1807,7 @@ declare class LoggerService implements ILogger {
1807
1807
  }
1808
1808
 
1809
1809
  declare const AGENT_CHANGE_SYMBOL: unique symbol;
1810
+ declare const MODEL_RESQUE_SYMBOL: unique symbol;
1810
1811
  declare const TOOL_ERROR_SYMBOL: unique symbol;
1811
1812
  declare const TOOL_STOP_SYMBOL: unique symbol;
1812
1813
  /**
@@ -1816,6 +1817,7 @@ declare const TOOL_STOP_SYMBOL: unique symbol;
1816
1817
  declare class ClientAgent implements IAgent {
1817
1818
  readonly params: IAgentParams;
1818
1819
  readonly _agentChangeSubject: Subject<typeof AGENT_CHANGE_SYMBOL>;
1820
+ readonly _modelResqueSubject: Subject<typeof MODEL_RESQUE_SYMBOL>;
1819
1821
  readonly _toolErrorSubject: Subject<typeof TOOL_ERROR_SYMBOL>;
1820
1822
  readonly _toolStopSubject: Subject<typeof TOOL_STOP_SYMBOL>;
1821
1823
  readonly _toolCommitSubject: Subject<void>;