agent-swarm-kit 1.0.141 → 1.0.142
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 +84 -37
- package/build/index.mjs +85 -38
- package/package.json +1 -1
package/build/index.cjs
CHANGED
|
@@ -1546,7 +1546,7 @@ var CC_AGENT_HISTORY_FILTER = function (agentName) {
|
|
|
1546
1546
|
};
|
|
1547
1547
|
var CC_AGENT_OUTPUT_TRANSFORM = removeXmlTags;
|
|
1548
1548
|
var CC_KEEP_MESSAGES = 15;
|
|
1549
|
-
var CC_MAX_TOOLS =
|
|
1549
|
+
var CC_MAX_TOOLS = 3;
|
|
1550
1550
|
var CC_GET_AGENT_HISTORY_ADAPTER = function () { return HistoryAdapter; };
|
|
1551
1551
|
var CC_GET_CLIENT_LOGGER_ADAPTER = function () { return LoggerAdapter; };
|
|
1552
1552
|
var CC_AGENT_OUTPUT_MAP = function (message) { return message; };
|
|
@@ -1818,9 +1818,51 @@ 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
1820
|
var TOOL_NO_OUTPUT_WARNING = 15000;
|
|
1821
|
-
var
|
|
1821
|
+
var createPlaceholder = function () {
|
|
1822
1822
|
return GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS[Math.floor(Math.random() * GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS.length)];
|
|
1823
1823
|
};
|
|
1824
|
+
var createToolCall = function (idx, tool, toolCalls, targetFn, self, isResqued) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1825
|
+
var error_1;
|
|
1826
|
+
var _a, _b, _c, _d;
|
|
1827
|
+
return __generator(this, function (_e) {
|
|
1828
|
+
switch (_e.label) {
|
|
1829
|
+
case 0:
|
|
1830
|
+
if (isResqued()) {
|
|
1831
|
+
return [2 /*return*/];
|
|
1832
|
+
}
|
|
1833
|
+
_e.label = 1;
|
|
1834
|
+
case 1:
|
|
1835
|
+
_e.trys.push([1, 3, , 4]);
|
|
1836
|
+
return [4 /*yield*/, targetFn.call({
|
|
1837
|
+
toolId: tool.id,
|
|
1838
|
+
clientId: self.params.clientId,
|
|
1839
|
+
agentName: self.params.agentName,
|
|
1840
|
+
params: tool.function.arguments,
|
|
1841
|
+
isLast: idx === toolCalls.length - 1,
|
|
1842
|
+
toolCalls: toolCalls,
|
|
1843
|
+
})];
|
|
1844
|
+
case 2:
|
|
1845
|
+
_e.sent();
|
|
1846
|
+
((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onAfterCall) &&
|
|
1847
|
+
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onAfterCall(tool.id, self.params.clientId, self.params.agentName, tool.function.arguments));
|
|
1848
|
+
return [3 /*break*/, 4];
|
|
1849
|
+
case 3:
|
|
1850
|
+
error_1 = _e.sent();
|
|
1851
|
+
console.error("agent-swarm tool call error functionName=".concat(tool.function.name, " error=").concat(functoolsKit.getErrorMessage(error_1)), {
|
|
1852
|
+
clientId: self.params.clientId,
|
|
1853
|
+
agentName: self.params.agentName,
|
|
1854
|
+
tool_call_id: tool.id,
|
|
1855
|
+
arguments: tool.function.arguments,
|
|
1856
|
+
error: functoolsKit.errorData(error_1),
|
|
1857
|
+
});
|
|
1858
|
+
((_c = targetFn.callbacks) === null || _c === void 0 ? void 0 : _c.onCallError) &&
|
|
1859
|
+
((_d = targetFn.callbacks) === null || _d === void 0 ? void 0 : _d.onCallError(tool.id, self.params.clientId, self.params.agentName, tool.function.arguments, error_1));
|
|
1860
|
+
self._toolErrorSubject.next(TOOL_ERROR_SYMBOL);
|
|
1861
|
+
return [3 /*break*/, 4];
|
|
1862
|
+
case 4: return [2 /*return*/];
|
|
1863
|
+
}
|
|
1864
|
+
});
|
|
1865
|
+
}); };
|
|
1824
1866
|
var RUN_FN = function (incoming, self) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1825
1867
|
var messages, args, rawMessage, message, result, validation;
|
|
1826
1868
|
var _a, _b, _c;
|
|
@@ -1896,7 +1938,7 @@ var RUN_FN = function (incoming, self) { return __awaiter(void 0, void 0, void 0
|
|
|
1896
1938
|
});
|
|
1897
1939
|
}); };
|
|
1898
1940
|
var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1899
|
-
var rawMessage, message,
|
|
1941
|
+
var rawMessage, message, toolCalls_1, lastToolCallRef, isResqued_1, unResque, _loop_1, idx, state_1, result, validation, result1;
|
|
1900
1942
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
1901
1943
|
return __generator(this, function (_k) {
|
|
1902
1944
|
switch (_k.label) {
|
|
@@ -1922,7 +1964,7 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
|
|
|
1922
1964
|
if (!message.tool_calls) return [3 /*break*/, 9];
|
|
1923
1965
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1924
1966
|
self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " tool call begin"));
|
|
1925
|
-
|
|
1967
|
+
toolCalls_1 = message.tool_calls
|
|
1926
1968
|
.map(function (call) {
|
|
1927
1969
|
var _a, _b;
|
|
1928
1970
|
return ({
|
|
@@ -1935,13 +1977,41 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
|
|
|
1935
1977
|
return [4 /*yield*/, self.params.history.push(__assign(__assign({}, message), { agentName: self.params.agentName }))];
|
|
1936
1978
|
case 4:
|
|
1937
1979
|
_k.sent();
|
|
1980
|
+
lastToolCallRef = Promise.resolve();
|
|
1981
|
+
isResqued_1 = false;
|
|
1982
|
+
{
|
|
1983
|
+
unResque = self._modelResqueSubject.once(function () {
|
|
1984
|
+
isResqued_1 = false;
|
|
1985
|
+
});
|
|
1986
|
+
/**
|
|
1987
|
+
* Effective way of garbage collection cause the agent
|
|
1988
|
+
* will defenitely say something or will be recreated on change
|
|
1989
|
+
*
|
|
1990
|
+
* On navigation:
|
|
1991
|
+
*
|
|
1992
|
+
* 1. Agent.dispose
|
|
1993
|
+
* 2. Agent.createAgentRef
|
|
1994
|
+
* 3. Swarm.setAgentRef
|
|
1995
|
+
*
|
|
1996
|
+
* That means the _outputSubject being marked for GC so this
|
|
1997
|
+
* does not matter are we listening it or not
|
|
1998
|
+
*
|
|
1999
|
+
* @see /src/function/navigate/changeToAgent
|
|
2000
|
+
*/
|
|
2001
|
+
self._outputSubject.once(unResque);
|
|
2002
|
+
}
|
|
1938
2003
|
_loop_1 = function (idx) {
|
|
1939
2004
|
var tool, targetFn, result_1, result_2, isResolved, status, result_3;
|
|
1940
2005
|
return __generator(this, function (_l) {
|
|
1941
2006
|
switch (_l.label) {
|
|
1942
2007
|
case 0:
|
|
1943
|
-
tool =
|
|
2008
|
+
tool = toolCalls_1[idx];
|
|
1944
2009
|
targetFn = (_a = self.params.tools) === null || _a === void 0 ? void 0 : _a.find(function (t) { return t.function.name === tool.function.name; });
|
|
2010
|
+
if (isResqued_1) {
|
|
2011
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2012
|
+
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);
|
|
2013
|
+
return [2 /*return*/, { value: void 0 }];
|
|
2014
|
+
}
|
|
1945
2015
|
if (!!targetFn) return [3 /*break*/, 3];
|
|
1946
2016
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1947
2017
|
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);
|
|
@@ -1961,7 +2031,7 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
|
|
|
1961
2031
|
clientId: self.params.clientId,
|
|
1962
2032
|
agentName: self.params.agentName,
|
|
1963
2033
|
params: tool.function.arguments,
|
|
1964
|
-
toolCalls:
|
|
2034
|
+
toolCalls: toolCalls_1,
|
|
1965
2035
|
}))];
|
|
1966
2036
|
case 4:
|
|
1967
2037
|
if (!_l.sent()) return [3 /*break*/, 7];
|
|
@@ -1982,31 +2052,8 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
|
|
|
1982
2052
|
/**
|
|
1983
2053
|
* @description Do not await to avoid deadlock! The tool can send the message to other agents by emulating user messages
|
|
1984
2054
|
*/
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
clientId: self.params.clientId,
|
|
1988
|
-
agentName: self.params.agentName,
|
|
1989
|
-
params: tool.function.arguments,
|
|
1990
|
-
isLast: idx === toolCalls.length - 1,
|
|
1991
|
-
toolCalls: toolCalls,
|
|
1992
|
-
}))
|
|
1993
|
-
.then(function () {
|
|
1994
|
-
var _a, _b;
|
|
1995
|
-
((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onAfterCall) &&
|
|
1996
|
-
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onAfterCall(tool.id, self.params.clientId, self.params.agentName, tool.function.arguments));
|
|
1997
|
-
})
|
|
1998
|
-
.catch(function (error) {
|
|
1999
|
-
var _a, _b;
|
|
2000
|
-
console.error("agent-swarm tool call error functionName=".concat(tool.function.name, " error=").concat(functoolsKit.getErrorMessage(error)), {
|
|
2001
|
-
clientId: self.params.clientId,
|
|
2002
|
-
agentName: self.params.agentName,
|
|
2003
|
-
tool_call_id: tool.id,
|
|
2004
|
-
arguments: tool.function.arguments,
|
|
2005
|
-
error: functoolsKit.errorData(error),
|
|
2006
|
-
});
|
|
2007
|
-
((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onCallError) &&
|
|
2008
|
-
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onCallError(tool.id, self.params.clientId, self.params.agentName, tool.function.arguments, error));
|
|
2009
|
-
self._toolErrorSubject.next(TOOL_ERROR_SYMBOL);
|
|
2055
|
+
lastToolCallRef = lastToolCallRef.then(function () {
|
|
2056
|
+
return createToolCall(idx, tool, toolCalls_1, targetFn, self, function () { return isResqued_1; });
|
|
2010
2057
|
});
|
|
2011
2058
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2012
2059
|
self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " tool call executing"));
|
|
@@ -2033,21 +2080,21 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
|
|
|
2033
2080
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2034
2081
|
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
2082
|
((_f = self.params.callbacks) === null || _f === void 0 ? void 0 : _f.onAfterToolCalls) &&
|
|
2036
|
-
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName,
|
|
2083
|
+
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls_1);
|
|
2037
2084
|
return [2 /*return*/, { value: void 0 }];
|
|
2038
2085
|
}
|
|
2039
2086
|
if (status === AGENT_CHANGE_SYMBOL) {
|
|
2040
2087
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2041
2088
|
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"));
|
|
2042
2089
|
((_g = self.params.callbacks) === null || _g === void 0 ? void 0 : _g.onAfterToolCalls) &&
|
|
2043
|
-
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName,
|
|
2090
|
+
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls_1);
|
|
2044
2091
|
return [2 /*return*/, { value: void 0 }];
|
|
2045
2092
|
}
|
|
2046
2093
|
if (status === TOOL_STOP_SYMBOL) {
|
|
2047
2094
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2048
2095
|
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"));
|
|
2049
2096
|
((_h = self.params.callbacks) === null || _h === void 0 ? void 0 : _h.onAfterToolCalls) &&
|
|
2050
|
-
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName,
|
|
2097
|
+
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls_1);
|
|
2051
2098
|
return [2 /*return*/, { value: void 0 }];
|
|
2052
2099
|
}
|
|
2053
2100
|
if (!(status === TOOL_ERROR_SYMBOL)) return [3 /*break*/, 11];
|
|
@@ -2069,7 +2116,7 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
|
|
|
2069
2116
|
idx = 0;
|
|
2070
2117
|
_k.label = 5;
|
|
2071
2118
|
case 5:
|
|
2072
|
-
if (!(idx !==
|
|
2119
|
+
if (!(idx !== toolCalls_1.length)) return [3 /*break*/, 8];
|
|
2073
2120
|
return [5 /*yield**/, _loop_1(idx)];
|
|
2074
2121
|
case 6:
|
|
2075
2122
|
state_1 = _k.sent();
|
|
@@ -2081,7 +2128,7 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
|
|
|
2081
2128
|
return [3 /*break*/, 5];
|
|
2082
2129
|
case 8:
|
|
2083
2130
|
((_j = self.params.callbacks) === null || _j === void 0 ? void 0 : _j.onAfterToolCalls) &&
|
|
2084
|
-
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName,
|
|
2131
|
+
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls_1);
|
|
2085
2132
|
return [2 /*return*/];
|
|
2086
2133
|
case 9:
|
|
2087
2134
|
if (!message.tool_calls) {
|
|
@@ -2317,7 +2364,7 @@ var ClientAgent = /** @class */ (function () {
|
|
|
2317
2364
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2318
2365
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel validation error: ").concat(validation));
|
|
2319
2366
|
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));
|
|
2320
|
-
content =
|
|
2367
|
+
content = createPlaceholder();
|
|
2321
2368
|
return [4 /*yield*/, this.params.history.push({
|
|
2322
2369
|
agentName: this.params.agentName,
|
|
2323
2370
|
role: "assistant",
|
package/build/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { scoped } from 'di-scoped';
|
|
2
2
|
import { createActivator } from 'di-kit';
|
|
3
|
-
import { trycatch, singleshot, memoize, str, randomString, ToolRegistry, Subject, queued,
|
|
3
|
+
import { trycatch, singleshot, memoize, str, randomString, ToolRegistry, Subject, queued, sleep, not, getErrorMessage, errorData, isObject, createAwaiter, cancelable, CANCELED_PROMISE_SYMBOL, execpool, SortedArray, Source, schedule, rate, ttl } from 'functools-kit';
|
|
4
4
|
import xml2js from 'xml2js';
|
|
5
5
|
import { AsyncResource } from 'async_hooks';
|
|
6
6
|
import { omit } from 'lodash-es';
|
|
@@ -1544,7 +1544,7 @@ var CC_AGENT_HISTORY_FILTER = function (agentName) {
|
|
|
1544
1544
|
};
|
|
1545
1545
|
var CC_AGENT_OUTPUT_TRANSFORM = removeXmlTags;
|
|
1546
1546
|
var CC_KEEP_MESSAGES = 15;
|
|
1547
|
-
var CC_MAX_TOOLS =
|
|
1547
|
+
var CC_MAX_TOOLS = 3;
|
|
1548
1548
|
var CC_GET_AGENT_HISTORY_ADAPTER = function () { return HistoryAdapter; };
|
|
1549
1549
|
var CC_GET_CLIENT_LOGGER_ADAPTER = function () { return LoggerAdapter; };
|
|
1550
1550
|
var CC_AGENT_OUTPUT_MAP = function (message) { return message; };
|
|
@@ -1816,9 +1816,51 @@ 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
1818
|
var TOOL_NO_OUTPUT_WARNING = 15000;
|
|
1819
|
-
var
|
|
1819
|
+
var createPlaceholder = function () {
|
|
1820
1820
|
return GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS[Math.floor(Math.random() * GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS.length)];
|
|
1821
1821
|
};
|
|
1822
|
+
var createToolCall = function (idx, tool, toolCalls, targetFn, self, isResqued) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1823
|
+
var error_1;
|
|
1824
|
+
var _a, _b, _c, _d;
|
|
1825
|
+
return __generator(this, function (_e) {
|
|
1826
|
+
switch (_e.label) {
|
|
1827
|
+
case 0:
|
|
1828
|
+
if (isResqued()) {
|
|
1829
|
+
return [2 /*return*/];
|
|
1830
|
+
}
|
|
1831
|
+
_e.label = 1;
|
|
1832
|
+
case 1:
|
|
1833
|
+
_e.trys.push([1, 3, , 4]);
|
|
1834
|
+
return [4 /*yield*/, targetFn.call({
|
|
1835
|
+
toolId: tool.id,
|
|
1836
|
+
clientId: self.params.clientId,
|
|
1837
|
+
agentName: self.params.agentName,
|
|
1838
|
+
params: tool.function.arguments,
|
|
1839
|
+
isLast: idx === toolCalls.length - 1,
|
|
1840
|
+
toolCalls: toolCalls,
|
|
1841
|
+
})];
|
|
1842
|
+
case 2:
|
|
1843
|
+
_e.sent();
|
|
1844
|
+
((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onAfterCall) &&
|
|
1845
|
+
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onAfterCall(tool.id, self.params.clientId, self.params.agentName, tool.function.arguments));
|
|
1846
|
+
return [3 /*break*/, 4];
|
|
1847
|
+
case 3:
|
|
1848
|
+
error_1 = _e.sent();
|
|
1849
|
+
console.error("agent-swarm tool call error functionName=".concat(tool.function.name, " error=").concat(getErrorMessage(error_1)), {
|
|
1850
|
+
clientId: self.params.clientId,
|
|
1851
|
+
agentName: self.params.agentName,
|
|
1852
|
+
tool_call_id: tool.id,
|
|
1853
|
+
arguments: tool.function.arguments,
|
|
1854
|
+
error: errorData(error_1),
|
|
1855
|
+
});
|
|
1856
|
+
((_c = targetFn.callbacks) === null || _c === void 0 ? void 0 : _c.onCallError) &&
|
|
1857
|
+
((_d = targetFn.callbacks) === null || _d === void 0 ? void 0 : _d.onCallError(tool.id, self.params.clientId, self.params.agentName, tool.function.arguments, error_1));
|
|
1858
|
+
self._toolErrorSubject.next(TOOL_ERROR_SYMBOL);
|
|
1859
|
+
return [3 /*break*/, 4];
|
|
1860
|
+
case 4: return [2 /*return*/];
|
|
1861
|
+
}
|
|
1862
|
+
});
|
|
1863
|
+
}); };
|
|
1822
1864
|
var RUN_FN = function (incoming, self) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1823
1865
|
var messages, args, rawMessage, message, result, validation;
|
|
1824
1866
|
var _a, _b, _c;
|
|
@@ -1894,7 +1936,7 @@ var RUN_FN = function (incoming, self) { return __awaiter(void 0, void 0, void 0
|
|
|
1894
1936
|
});
|
|
1895
1937
|
}); };
|
|
1896
1938
|
var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1897
|
-
var rawMessage, message,
|
|
1939
|
+
var rawMessage, message, toolCalls_1, lastToolCallRef, isResqued_1, unResque, _loop_1, idx, state_1, result, validation, result1;
|
|
1898
1940
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
1899
1941
|
return __generator(this, function (_k) {
|
|
1900
1942
|
switch (_k.label) {
|
|
@@ -1920,7 +1962,7 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
|
|
|
1920
1962
|
if (!message.tool_calls) return [3 /*break*/, 9];
|
|
1921
1963
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1922
1964
|
self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " tool call begin"));
|
|
1923
|
-
|
|
1965
|
+
toolCalls_1 = message.tool_calls
|
|
1924
1966
|
.map(function (call) {
|
|
1925
1967
|
var _a, _b;
|
|
1926
1968
|
return ({
|
|
@@ -1933,13 +1975,41 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
|
|
|
1933
1975
|
return [4 /*yield*/, self.params.history.push(__assign(__assign({}, message), { agentName: self.params.agentName }))];
|
|
1934
1976
|
case 4:
|
|
1935
1977
|
_k.sent();
|
|
1978
|
+
lastToolCallRef = Promise.resolve();
|
|
1979
|
+
isResqued_1 = false;
|
|
1980
|
+
{
|
|
1981
|
+
unResque = self._modelResqueSubject.once(function () {
|
|
1982
|
+
isResqued_1 = false;
|
|
1983
|
+
});
|
|
1984
|
+
/**
|
|
1985
|
+
* Effective way of garbage collection cause the agent
|
|
1986
|
+
* will defenitely say something or will be recreated on change
|
|
1987
|
+
*
|
|
1988
|
+
* On navigation:
|
|
1989
|
+
*
|
|
1990
|
+
* 1. Agent.dispose
|
|
1991
|
+
* 2. Agent.createAgentRef
|
|
1992
|
+
* 3. Swarm.setAgentRef
|
|
1993
|
+
*
|
|
1994
|
+
* That means the _outputSubject being marked for GC so this
|
|
1995
|
+
* does not matter are we listening it or not
|
|
1996
|
+
*
|
|
1997
|
+
* @see /src/function/navigate/changeToAgent
|
|
1998
|
+
*/
|
|
1999
|
+
self._outputSubject.once(unResque);
|
|
2000
|
+
}
|
|
1936
2001
|
_loop_1 = function (idx) {
|
|
1937
2002
|
var tool, targetFn, result_1, result_2, isResolved, status, result_3;
|
|
1938
2003
|
return __generator(this, function (_l) {
|
|
1939
2004
|
switch (_l.label) {
|
|
1940
2005
|
case 0:
|
|
1941
|
-
tool =
|
|
2006
|
+
tool = toolCalls_1[idx];
|
|
1942
2007
|
targetFn = (_a = self.params.tools) === null || _a === void 0 ? void 0 : _a.find(function (t) { return t.function.name === tool.function.name; });
|
|
2008
|
+
if (isResqued_1) {
|
|
2009
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2010
|
+
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);
|
|
2011
|
+
return [2 /*return*/, { value: void 0 }];
|
|
2012
|
+
}
|
|
1943
2013
|
if (!!targetFn) return [3 /*break*/, 3];
|
|
1944
2014
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
1945
2015
|
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);
|
|
@@ -1959,7 +2029,7 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
|
|
|
1959
2029
|
clientId: self.params.clientId,
|
|
1960
2030
|
agentName: self.params.agentName,
|
|
1961
2031
|
params: tool.function.arguments,
|
|
1962
|
-
toolCalls:
|
|
2032
|
+
toolCalls: toolCalls_1,
|
|
1963
2033
|
}))];
|
|
1964
2034
|
case 4:
|
|
1965
2035
|
if (!_l.sent()) return [3 /*break*/, 7];
|
|
@@ -1980,31 +2050,8 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
|
|
|
1980
2050
|
/**
|
|
1981
2051
|
* @description Do not await to avoid deadlock! The tool can send the message to other agents by emulating user messages
|
|
1982
2052
|
*/
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
clientId: self.params.clientId,
|
|
1986
|
-
agentName: self.params.agentName,
|
|
1987
|
-
params: tool.function.arguments,
|
|
1988
|
-
isLast: idx === toolCalls.length - 1,
|
|
1989
|
-
toolCalls: toolCalls,
|
|
1990
|
-
}))
|
|
1991
|
-
.then(function () {
|
|
1992
|
-
var _a, _b;
|
|
1993
|
-
((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onAfterCall) &&
|
|
1994
|
-
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onAfterCall(tool.id, self.params.clientId, self.params.agentName, tool.function.arguments));
|
|
1995
|
-
})
|
|
1996
|
-
.catch(function (error) {
|
|
1997
|
-
var _a, _b;
|
|
1998
|
-
console.error("agent-swarm tool call error functionName=".concat(tool.function.name, " error=").concat(getErrorMessage(error)), {
|
|
1999
|
-
clientId: self.params.clientId,
|
|
2000
|
-
agentName: self.params.agentName,
|
|
2001
|
-
tool_call_id: tool.id,
|
|
2002
|
-
arguments: tool.function.arguments,
|
|
2003
|
-
error: errorData(error),
|
|
2004
|
-
});
|
|
2005
|
-
((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onCallError) &&
|
|
2006
|
-
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onCallError(tool.id, self.params.clientId, self.params.agentName, tool.function.arguments, error));
|
|
2007
|
-
self._toolErrorSubject.next(TOOL_ERROR_SYMBOL);
|
|
2053
|
+
lastToolCallRef = lastToolCallRef.then(function () {
|
|
2054
|
+
return createToolCall(idx, tool, toolCalls_1, targetFn, self, function () { return isResqued_1; });
|
|
2008
2055
|
});
|
|
2009
2056
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2010
2057
|
self.params.logger.debug("ClientAgent agentName=".concat(self.params.agentName, " clientId=").concat(self.params.clientId, " functionName=").concat(tool.function.name, " tool call executing"));
|
|
@@ -2031,21 +2078,21 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
|
|
|
2031
2078
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2032
2079
|
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
2080
|
((_f = self.params.callbacks) === null || _f === void 0 ? void 0 : _f.onAfterToolCalls) &&
|
|
2034
|
-
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName,
|
|
2081
|
+
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls_1);
|
|
2035
2082
|
return [2 /*return*/, { value: void 0 }];
|
|
2036
2083
|
}
|
|
2037
2084
|
if (status === AGENT_CHANGE_SYMBOL) {
|
|
2038
2085
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2039
2086
|
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"));
|
|
2040
2087
|
((_g = self.params.callbacks) === null || _g === void 0 ? void 0 : _g.onAfterToolCalls) &&
|
|
2041
|
-
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName,
|
|
2088
|
+
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls_1);
|
|
2042
2089
|
return [2 /*return*/, { value: void 0 }];
|
|
2043
2090
|
}
|
|
2044
2091
|
if (status === TOOL_STOP_SYMBOL) {
|
|
2045
2092
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2046
2093
|
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"));
|
|
2047
2094
|
((_h = self.params.callbacks) === null || _h === void 0 ? void 0 : _h.onAfterToolCalls) &&
|
|
2048
|
-
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName,
|
|
2095
|
+
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls_1);
|
|
2049
2096
|
return [2 /*return*/, { value: void 0 }];
|
|
2050
2097
|
}
|
|
2051
2098
|
if (!(status === TOOL_ERROR_SYMBOL)) return [3 /*break*/, 11];
|
|
@@ -2067,7 +2114,7 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
|
|
|
2067
2114
|
idx = 0;
|
|
2068
2115
|
_k.label = 5;
|
|
2069
2116
|
case 5:
|
|
2070
|
-
if (!(idx !==
|
|
2117
|
+
if (!(idx !== toolCalls_1.length)) return [3 /*break*/, 8];
|
|
2071
2118
|
return [5 /*yield**/, _loop_1(idx)];
|
|
2072
2119
|
case 6:
|
|
2073
2120
|
state_1 = _k.sent();
|
|
@@ -2079,7 +2126,7 @@ var EXECUTE_FN = function (incoming, mode, self) { return __awaiter(void 0, void
|
|
|
2079
2126
|
return [3 /*break*/, 5];
|
|
2080
2127
|
case 8:
|
|
2081
2128
|
((_j = self.params.callbacks) === null || _j === void 0 ? void 0 : _j.onAfterToolCalls) &&
|
|
2082
|
-
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName,
|
|
2129
|
+
self.params.callbacks.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls_1);
|
|
2083
2130
|
return [2 /*return*/];
|
|
2084
2131
|
case 9:
|
|
2085
2132
|
if (!message.tool_calls) {
|
|
@@ -2315,7 +2362,7 @@ var ClientAgent = /** @class */ (function () {
|
|
|
2315
2362
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2316
2363
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel validation error: ").concat(validation));
|
|
2317
2364
|
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
|
-
content =
|
|
2365
|
+
content = createPlaceholder();
|
|
2319
2366
|
return [4 /*yield*/, this.params.history.push({
|
|
2320
2367
|
agentName: this.params.agentName,
|
|
2321
2368
|
role: "assistant",
|