agent-swarm-kit 1.0.145 → 1.0.147

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
@@ -1817,7 +1817,8 @@ var AGENT_CHANGE_SYMBOL = Symbol("agent-change");
1817
1817
  var MODEL_RESQUE_SYMBOL = Symbol("model-resque");
1818
1818
  var TOOL_ERROR_SYMBOL = Symbol("tool-error");
1819
1819
  var TOOL_STOP_SYMBOL = Symbol("tool-stop");
1820
- var TOOL_NO_OUTPUT_WARNING = 15000;
1820
+ var TOOL_NO_OUTPUT_WARNING_TIMEOUT = 15000;
1821
+ var TOOL_NO_OUTPUT_WARNING_SYMBOL = Symbol("tool-warning-timeout");
1821
1822
  var createPlaceholder = function () {
1822
1823
  return GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS[Math.floor(Math.random() * GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS.length)];
1823
1824
  };
@@ -1933,7 +1934,7 @@ var RUN_FN = function (incoming, self) { return __awaiter(void 0, void 0, void 0
1933
1934
  });
1934
1935
  }); };
1935
1936
  var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void 0, void 0, function () {
1936
- var rawMessage, message, toolCalls_1, lastToolCallRef, isResqued_1, _loop_1, idx, state_1, result, validation, result1;
1937
+ var rawMessage, message, toolCalls_1, lastToolStatusRef, _loop_1, idx, state_1, result, validation, result1;
1937
1938
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1938
1939
  return __generator(this, function (_k) {
1939
1940
  switch (_k.label) {
@@ -1972,20 +1973,14 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
1972
1973
  return [4 /*yield*/, self.params.history.push(__assign(__assign({}, message), { agentName: self.params.agentName }))];
1973
1974
  case 4:
1974
1975
  _k.sent();
1975
- lastToolCallRef = Promise.resolve(null);
1976
- isResqued_1 = false;
1976
+ lastToolStatusRef = Promise.resolve(null);
1977
1977
  _loop_1 = function (idx) {
1978
- var tool, targetFn, result_1, result_2, statusAwaiter, isResolved, status, result_3;
1978
+ var tool, targetFn, result_1, result_2, status, result_3;
1979
1979
  return __generator(this, function (_l) {
1980
1980
  switch (_l.label) {
1981
1981
  case 0:
1982
1982
  tool = toolCalls_1[idx];
1983
1983
  targetFn = (_a = self.params.tools) === null || _a === void 0 ? void 0 : _a.find(function (t) { return t.function.name === tool.function.name; });
1984
- if (isResqued_1) {
1985
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
1986
- self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " tool execution canceled due to the model was resqued in the chain"), self.params.tools);
1987
- return [2 /*return*/, { value: void 0 }];
1988
- }
1989
1984
  if (!!targetFn) return [3 /*break*/, 3];
1990
1985
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
1991
1986
  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);
@@ -2023,44 +2018,53 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
2023
2018
  case 7:
2024
2019
  ((_d = targetFn.callbacks) === null || _d === void 0 ? void 0 : _d.onBeforeCall) &&
2025
2020
  ((_e = targetFn.callbacks) === null || _e === void 0 ? void 0 : _e.onBeforeCall(tool.id, self.params.clientId, self.params.agentName, tool.function.arguments));
2026
- statusAwaiter = Promise.race([
2027
- self._agentChangeSubject.toPromise(),
2028
- self._toolCommitSubject.toPromise(),
2029
- self._toolErrorSubject.toPromise(),
2030
- self._toolStopSubject.toPromise(),
2031
- self._outputSubject.toPromise(),
2032
- self._resqueSubject.toPromise(),
2033
- ]);
2034
2021
  /**
2035
- * Do not await to avoid deadlock! The tool can send the message to other agents by emulating user messages
2022
+ * Do not await directly to avoid the deadlock! The tool can send the message to other agents by emulating user messages
2036
2023
  */
2037
2024
  {
2038
- lastToolCallRef.then(function () {
2039
- if (isResqued_1) {
2025
+ lastToolStatusRef.then(function (lastStatus) {
2026
+ if (lastStatus === MODEL_RESQUE_SYMBOL) {
2027
+ return;
2028
+ }
2029
+ if (lastStatus === AGENT_CHANGE_SYMBOL) {
2030
+ return;
2031
+ }
2032
+ if (lastStatus === TOOL_STOP_SYMBOL) {
2033
+ return;
2034
+ }
2035
+ if (lastStatus === TOOL_ERROR_SYMBOL) {
2040
2036
  return;
2041
2037
  }
2042
2038
  return createToolCall(idx, tool, toolCalls_1, targetFn, self);
2043
2039
  });
2044
- lastToolCallRef = lastToolCallRef.then(function () { return statusAwaiter; });
2040
+ lastToolStatusRef = lastToolStatusRef.then(function () {
2041
+ return Promise.race([
2042
+ self._agentChangeSubject.toPromise(),
2043
+ self._toolCommitSubject.toPromise(),
2044
+ self._toolErrorSubject.toPromise(),
2045
+ self._toolStopSubject.toPromise(),
2046
+ self._resqueSubject.toPromise(),
2047
+ ]);
2048
+ });
2045
2049
  }
2046
2050
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2047
2051
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " tool call executing"));
2048
- isResolved = false;
2049
- functoolsKit.sleep(TOOL_NO_OUTPUT_WARNING).then(function () {
2050
- if (!isResolved) {
2051
- console.warn("agent-swarm no tool output after ".concat(TOOL_NO_OUTPUT_WARNING, "ms clientId=").concat(self.params.clientId, " agentName=").concat(self.params.agentName, " toolId=").concat(tool.id, " functionName=").concat(tool.function.name));
2052
+ Promise.race([
2053
+ functoolsKit.sleep(TOOL_NO_OUTPUT_WARNING_TIMEOUT).then(function () { return TOOL_NO_OUTPUT_WARNING_SYMBOL; }),
2054
+ lastToolStatusRef,
2055
+ ]).then(function (result) {
2056
+ if (result === TOOL_NO_OUTPUT_WARNING_SYMBOL) {
2057
+ console.warn("agent-swarm no tool output after ".concat(TOOL_NO_OUTPUT_WARNING_TIMEOUT, "ms clientId=").concat(self.params.clientId, " agentName=").concat(self.params.agentName, " toolId=").concat(tool.id, " functionName=").concat(tool.function.name));
2052
2058
  }
2053
2059
  });
2054
- return [4 /*yield*/, statusAwaiter];
2060
+ return [4 /*yield*/, lastToolStatusRef];
2055
2061
  case 8:
2056
2062
  status = _l.sent();
2057
- isResolved = true;
2058
2063
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2059
2064
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " tool call end"));
2060
2065
  if (status === MODEL_RESQUE_SYMBOL) {
2061
2066
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2062
2067
  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"));
2063
- isResqued_1 = true;
2064
2068
  ((_f = self.params.callbacks) === null || _f === void 0 ? void 0 : _f.onAfterToolCalls) &&
2065
2069
  self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls_1);
2066
2070
  return [2 /*return*/, { value: void 0 }];
@@ -2342,28 +2346,36 @@ var ClientAgent = /** @class */ (function () {
2342
2346
  validation = null;
2343
2347
  return [4 /*yield*/, this.params.validate(result)];
2344
2348
  case 12:
2345
- if (!(validation = _a.sent())) return [3 /*break*/, 15];
2349
+ if (!(validation = _a.sent())) return [3 /*break*/, 16];
2346
2350
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2347
2351
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel validation error: ").concat(validation));
2348
2352
  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));
2349
2353
  content = createPlaceholder();
2354
+ return [4 /*yield*/, this.params.history.push({
2355
+ role: "resque",
2356
+ mode: "tool",
2357
+ agentName: this.params.agentName,
2358
+ content: reason || "Unknown error",
2359
+ })];
2360
+ case 13:
2361
+ _a.sent();
2350
2362
  return [4 /*yield*/, this.params.history.push({
2351
2363
  agentName: this.params.agentName,
2352
2364
  role: "assistant",
2353
2365
  mode: "tool",
2354
2366
  content: content,
2355
2367
  })];
2356
- case 13:
2368
+ case 14:
2357
2369
  _a.sent();
2358
2370
  return [4 /*yield*/, this._resqueSubject.next(MODEL_RESQUE_SYMBOL)];
2359
- case 14:
2371
+ case 15:
2360
2372
  _a.sent();
2361
2373
  return [2 /*return*/, content];
2362
- case 15: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2363
- case 16:
2374
+ case 16: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2375
+ case 17:
2364
2376
  _a.sent();
2365
2377
  return [4 /*yield*/, this._resqueSubject.next(MODEL_RESQUE_SYMBOL)];
2366
- case 17:
2378
+ case 18:
2367
2379
  _a.sent();
2368
2380
  return [2 /*return*/, result];
2369
2381
  }
package/build/index.mjs CHANGED
@@ -1815,7 +1815,8 @@ var AGENT_CHANGE_SYMBOL = Symbol("agent-change");
1815
1815
  var MODEL_RESQUE_SYMBOL = Symbol("model-resque");
1816
1816
  var TOOL_ERROR_SYMBOL = Symbol("tool-error");
1817
1817
  var TOOL_STOP_SYMBOL = Symbol("tool-stop");
1818
- var TOOL_NO_OUTPUT_WARNING = 15000;
1818
+ var TOOL_NO_OUTPUT_WARNING_TIMEOUT = 15000;
1819
+ var TOOL_NO_OUTPUT_WARNING_SYMBOL = Symbol("tool-warning-timeout");
1819
1820
  var createPlaceholder = function () {
1820
1821
  return GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS[Math.floor(Math.random() * GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS.length)];
1821
1822
  };
@@ -1931,7 +1932,7 @@ var RUN_FN = function (incoming, self) { return __awaiter(void 0, void 0, void 0
1931
1932
  });
1932
1933
  }); };
1933
1934
  var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void 0, void 0, function () {
1934
- var rawMessage, message, toolCalls_1, lastToolCallRef, isResqued_1, _loop_1, idx, state_1, result, validation, result1;
1935
+ var rawMessage, message, toolCalls_1, lastToolStatusRef, _loop_1, idx, state_1, result, validation, result1;
1935
1936
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1936
1937
  return __generator(this, function (_k) {
1937
1938
  switch (_k.label) {
@@ -1970,20 +1971,14 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
1970
1971
  return [4 /*yield*/, self.params.history.push(__assign(__assign({}, message), { agentName: self.params.agentName }))];
1971
1972
  case 4:
1972
1973
  _k.sent();
1973
- lastToolCallRef = Promise.resolve(null);
1974
- isResqued_1 = false;
1974
+ lastToolStatusRef = Promise.resolve(null);
1975
1975
  _loop_1 = function (idx) {
1976
- var tool, targetFn, result_1, result_2, statusAwaiter, isResolved, status, result_3;
1976
+ var tool, targetFn, result_1, result_2, status, result_3;
1977
1977
  return __generator(this, function (_l) {
1978
1978
  switch (_l.label) {
1979
1979
  case 0:
1980
1980
  tool = toolCalls_1[idx];
1981
1981
  targetFn = (_a = self.params.tools) === null || _a === void 0 ? void 0 : _a.find(function (t) { return t.function.name === tool.function.name; });
1982
- if (isResqued_1) {
1983
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
1984
- self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " tool execution canceled due to the model was resqued in the chain"), self.params.tools);
1985
- return [2 /*return*/, { value: void 0 }];
1986
- }
1987
1982
  if (!!targetFn) return [3 /*break*/, 3];
1988
1983
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
1989
1984
  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);
@@ -2021,44 +2016,53 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
2021
2016
  case 7:
2022
2017
  ((_d = targetFn.callbacks) === null || _d === void 0 ? void 0 : _d.onBeforeCall) &&
2023
2018
  ((_e = targetFn.callbacks) === null || _e === void 0 ? void 0 : _e.onBeforeCall(tool.id, self.params.clientId, self.params.agentName, tool.function.arguments));
2024
- statusAwaiter = Promise.race([
2025
- self._agentChangeSubject.toPromise(),
2026
- self._toolCommitSubject.toPromise(),
2027
- self._toolErrorSubject.toPromise(),
2028
- self._toolStopSubject.toPromise(),
2029
- self._outputSubject.toPromise(),
2030
- self._resqueSubject.toPromise(),
2031
- ]);
2032
2019
  /**
2033
- * Do not await to avoid deadlock! The tool can send the message to other agents by emulating user messages
2020
+ * Do not await directly to avoid the deadlock! The tool can send the message to other agents by emulating user messages
2034
2021
  */
2035
2022
  {
2036
- lastToolCallRef.then(function () {
2037
- if (isResqued_1) {
2023
+ lastToolStatusRef.then(function (lastStatus) {
2024
+ if (lastStatus === MODEL_RESQUE_SYMBOL) {
2025
+ return;
2026
+ }
2027
+ if (lastStatus === AGENT_CHANGE_SYMBOL) {
2028
+ return;
2029
+ }
2030
+ if (lastStatus === TOOL_STOP_SYMBOL) {
2031
+ return;
2032
+ }
2033
+ if (lastStatus === TOOL_ERROR_SYMBOL) {
2038
2034
  return;
2039
2035
  }
2040
2036
  return createToolCall(idx, tool, toolCalls_1, targetFn, self);
2041
2037
  });
2042
- lastToolCallRef = lastToolCallRef.then(function () { return statusAwaiter; });
2038
+ lastToolStatusRef = lastToolStatusRef.then(function () {
2039
+ return Promise.race([
2040
+ self._agentChangeSubject.toPromise(),
2041
+ self._toolCommitSubject.toPromise(),
2042
+ self._toolErrorSubject.toPromise(),
2043
+ self._toolStopSubject.toPromise(),
2044
+ self._resqueSubject.toPromise(),
2045
+ ]);
2046
+ });
2043
2047
  }
2044
2048
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2045
2049
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " tool call executing"));
2046
- isResolved = false;
2047
- sleep(TOOL_NO_OUTPUT_WARNING).then(function () {
2048
- if (!isResolved) {
2049
- console.warn("agent-swarm no tool output after ".concat(TOOL_NO_OUTPUT_WARNING, "ms clientId=").concat(self.params.clientId, " agentName=").concat(self.params.agentName, " toolId=").concat(tool.id, " functionName=").concat(tool.function.name));
2050
+ Promise.race([
2051
+ sleep(TOOL_NO_OUTPUT_WARNING_TIMEOUT).then(function () { return TOOL_NO_OUTPUT_WARNING_SYMBOL; }),
2052
+ lastToolStatusRef,
2053
+ ]).then(function (result) {
2054
+ if (result === TOOL_NO_OUTPUT_WARNING_SYMBOL) {
2055
+ console.warn("agent-swarm no tool output after ".concat(TOOL_NO_OUTPUT_WARNING_TIMEOUT, "ms clientId=").concat(self.params.clientId, " agentName=").concat(self.params.agentName, " toolId=").concat(tool.id, " functionName=").concat(tool.function.name));
2050
2056
  }
2051
2057
  });
2052
- return [4 /*yield*/, statusAwaiter];
2058
+ return [4 /*yield*/, lastToolStatusRef];
2053
2059
  case 8:
2054
2060
  status = _l.sent();
2055
- isResolved = true;
2056
2061
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2057
2062
  self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " tool call end"));
2058
2063
  if (status === MODEL_RESQUE_SYMBOL) {
2059
2064
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2060
2065
  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"));
2061
- isResqued_1 = true;
2062
2066
  ((_f = self.params.callbacks) === null || _f === void 0 ? void 0 : _f.onAfterToolCalls) &&
2063
2067
  self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls_1);
2064
2068
  return [2 /*return*/, { value: void 0 }];
@@ -2340,28 +2344,36 @@ var ClientAgent = /** @class */ (function () {
2340
2344
  validation = null;
2341
2345
  return [4 /*yield*/, this.params.validate(result)];
2342
2346
  case 12:
2343
- if (!(validation = _a.sent())) return [3 /*break*/, 15];
2347
+ if (!(validation = _a.sent())) return [3 /*break*/, 16];
2344
2348
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
2345
2349
  this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel validation error: ").concat(validation));
2346
2350
  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));
2347
2351
  content = createPlaceholder();
2352
+ return [4 /*yield*/, this.params.history.push({
2353
+ role: "resque",
2354
+ mode: "tool",
2355
+ agentName: this.params.agentName,
2356
+ content: reason || "Unknown error",
2357
+ })];
2358
+ case 13:
2359
+ _a.sent();
2348
2360
  return [4 /*yield*/, this.params.history.push({
2349
2361
  agentName: this.params.agentName,
2350
2362
  role: "assistant",
2351
2363
  mode: "tool",
2352
2364
  content: content,
2353
2365
  })];
2354
- case 13:
2366
+ case 14:
2355
2367
  _a.sent();
2356
2368
  return [4 /*yield*/, this._resqueSubject.next(MODEL_RESQUE_SYMBOL)];
2357
- case 14:
2369
+ case 15:
2358
2370
  _a.sent();
2359
2371
  return [2 /*return*/, content];
2360
- case 15: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2361
- case 16:
2372
+ case 16: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
2373
+ case 17:
2362
2374
  _a.sent();
2363
2375
  return [4 /*yield*/, this._resqueSubject.next(MODEL_RESQUE_SYMBOL)];
2364
- case 17:
2376
+ case 18:
2365
2377
  _a.sent();
2366
2378
  return [2 /*return*/, result];
2367
2379
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.145",
3
+ "version": "1.0.147",
4
4
  "description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",