agent-swarm-kit 1.0.42 → 1.0.44
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 +59 -70
- package/build/index.mjs +59 -70
- package/package.json +1 -1
- package/types.d.ts +1 -1
package/build/index.cjs
CHANGED
|
@@ -536,11 +536,13 @@ var ClientAgent = /** @class */ (function () {
|
|
|
536
536
|
return [4 /*yield*/, this.params.map(rawMessage, this.params.clientId, this.params.agentName)];
|
|
537
537
|
case 4:
|
|
538
538
|
message = _a.sent();
|
|
539
|
-
|
|
539
|
+
return [4 /*yield*/, this.params.transform(message.content, this.params.clientId, this.params.agentName)];
|
|
540
|
+
case 5:
|
|
541
|
+
result = _a.sent();
|
|
540
542
|
validation = null;
|
|
541
543
|
return [4 /*yield*/, this.params.validate(result)];
|
|
542
|
-
case
|
|
543
|
-
if (!(validation = _a.sent())) return [3 /*break*/,
|
|
544
|
+
case 6:
|
|
545
|
+
if (!(validation = _a.sent())) return [3 /*break*/, 8];
|
|
544
546
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel validation error: ").concat(validation));
|
|
545
547
|
content = getPlaceholder();
|
|
546
548
|
return [4 /*yield*/, this.params.history.push({
|
|
@@ -549,11 +551,11 @@ var ClientAgent = /** @class */ (function () {
|
|
|
549
551
|
mode: "tool",
|
|
550
552
|
content: content,
|
|
551
553
|
})];
|
|
552
|
-
case
|
|
554
|
+
case 7:
|
|
553
555
|
_a.sent();
|
|
554
556
|
return [2 /*return*/, content];
|
|
555
|
-
case
|
|
556
|
-
case
|
|
557
|
+
case 8: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
|
|
558
|
+
case 9:
|
|
557
559
|
_a.sent();
|
|
558
560
|
return [2 /*return*/, result];
|
|
559
561
|
}
|
|
@@ -710,12 +712,11 @@ var ClientAgent = /** @class */ (function () {
|
|
|
710
712
|
* @returns {Promise<void>}
|
|
711
713
|
*/
|
|
712
714
|
this.execute = functoolsKit.queued(function (incoming, mode) { return __awaiter(_this, void 0, void 0, function () {
|
|
713
|
-
var rawMessage, message, toolCalls, _loop_1, this_1,
|
|
714
|
-
var e_1, _a;
|
|
715
|
+
var rawMessage, message, toolCalls, _loop_1, this_1, idx, state_1, result, validation, result1;
|
|
715
716
|
var _this = this;
|
|
716
|
-
var _b, _c, _d, _e, _f
|
|
717
|
-
return __generator(this, function (
|
|
718
|
-
switch (
|
|
717
|
+
var _a, _b, _c, _d, _e, _f;
|
|
718
|
+
return __generator(this, function (_g) {
|
|
719
|
+
switch (_g.label) {
|
|
719
720
|
case 0:
|
|
720
721
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute begin"), { incoming: incoming, mode: mode });
|
|
721
722
|
this.params.onExecute &&
|
|
@@ -727,14 +728,14 @@ var ClientAgent = /** @class */ (function () {
|
|
|
727
728
|
content: incoming.trim(),
|
|
728
729
|
})];
|
|
729
730
|
case 1:
|
|
730
|
-
|
|
731
|
+
_g.sent();
|
|
731
732
|
return [4 /*yield*/, this.getCompletion(mode)];
|
|
732
733
|
case 2:
|
|
733
|
-
rawMessage =
|
|
734
|
+
rawMessage = _g.sent();
|
|
734
735
|
return [4 /*yield*/, this.params.map(rawMessage, this.params.clientId, this.params.agentName)];
|
|
735
736
|
case 3:
|
|
736
|
-
message =
|
|
737
|
-
if (!message.tool_calls) return [3 /*break*/,
|
|
737
|
+
message = _g.sent();
|
|
738
|
+
if (!message.tool_calls) return [3 /*break*/, 9];
|
|
738
739
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " tool call begin"));
|
|
739
740
|
toolCalls = message.tool_calls.map(function (call) {
|
|
740
741
|
var _a, _b;
|
|
@@ -746,45 +747,46 @@ var ClientAgent = /** @class */ (function () {
|
|
|
746
747
|
});
|
|
747
748
|
return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
|
|
748
749
|
case 4:
|
|
749
|
-
|
|
750
|
-
_loop_1 = function (
|
|
751
|
-
var targetFn, result_2, result_3;
|
|
752
|
-
return __generator(this, function (
|
|
753
|
-
switch (
|
|
750
|
+
_g.sent();
|
|
751
|
+
_loop_1 = function (idx) {
|
|
752
|
+
var tool, targetFn, result_2, result_3;
|
|
753
|
+
return __generator(this, function (_h) {
|
|
754
|
+
switch (_h.label) {
|
|
754
755
|
case 0:
|
|
755
|
-
|
|
756
|
+
tool = toolCalls[idx];
|
|
757
|
+
targetFn = (_a = this_1.params.tools) === null || _a === void 0 ? void 0 : _a.find(function (t) { return t.function.name === tool.function.name; });
|
|
756
758
|
if (!!targetFn) return [3 /*break*/, 3];
|
|
757
759
|
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);
|
|
758
760
|
return [4 /*yield*/, this_1._resurrectModel(mode, "No target function for ".concat(tool.function.name))];
|
|
759
761
|
case 1:
|
|
760
|
-
result_2 =
|
|
762
|
+
result_2 = _h.sent();
|
|
761
763
|
this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_2));
|
|
762
764
|
return [4 /*yield*/, this_1._emitOuput(mode, result_2)];
|
|
763
765
|
case 2:
|
|
764
|
-
|
|
766
|
+
_h.sent();
|
|
765
767
|
return [2 /*return*/, { value: void 0 }];
|
|
766
768
|
case 3:
|
|
767
|
-
((
|
|
768
|
-
((
|
|
769
|
+
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onValidate) &&
|
|
770
|
+
((_c = targetFn.callbacks) === null || _c === void 0 ? void 0 : _c.onValidate(this_1.params.clientId, this_1.params.agentName, tool.function.arguments));
|
|
769
771
|
return [4 /*yield*/, functoolsKit.not(targetFn.validate(this_1.params.clientId, this_1.params.agentName, tool.function.arguments))];
|
|
770
772
|
case 4:
|
|
771
|
-
if (!
|
|
773
|
+
if (!_h.sent()) return [3 /*break*/, 7];
|
|
772
774
|
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"));
|
|
773
775
|
return [4 /*yield*/, this_1._resurrectModel(mode, "Function validation failed: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
|
|
774
776
|
case 5:
|
|
775
|
-
result_3 =
|
|
777
|
+
result_3 = _h.sent();
|
|
776
778
|
this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_3));
|
|
777
779
|
return [4 /*yield*/, this_1._emitOuput(mode, result_3)];
|
|
778
780
|
case 6:
|
|
779
|
-
|
|
781
|
+
_h.sent();
|
|
780
782
|
return [2 /*return*/, { value: void 0 }];
|
|
781
783
|
case 7:
|
|
782
|
-
((
|
|
783
|
-
((
|
|
784
|
+
((_d = targetFn.callbacks) === null || _d === void 0 ? void 0 : _d.onBeforeCall) &&
|
|
785
|
+
((_e = targetFn.callbacks) === null || _e === void 0 ? void 0 : _e.onBeforeCall(tool.id, this_1.params.clientId, this_1.params.agentName, tool.function.arguments));
|
|
784
786
|
/**
|
|
785
787
|
* @description Do not await to avoid deadlock! The tool can send the message to other agents by emulating user messages
|
|
786
788
|
*/
|
|
787
|
-
Promise.resolve(targetFn.call(tool.id, this_1.params.clientId, this_1.params.agentName, tool.function.arguments)).then(function () {
|
|
789
|
+
Promise.resolve(targetFn.call(tool.id, this_1.params.clientId, this_1.params.agentName, tool.function.arguments, idx === toolCalls.length - 1)).then(function () {
|
|
788
790
|
var _a, _b;
|
|
789
791
|
((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onAfterCall) &&
|
|
790
792
|
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onAfterCall(tool.id, _this.params.clientId, _this.params.agentName, tool.function.arguments));
|
|
@@ -795,70 +797,57 @@ var ClientAgent = /** @class */ (function () {
|
|
|
795
797
|
this_1._outputSubject.toPromise(),
|
|
796
798
|
])];
|
|
797
799
|
case 8:
|
|
798
|
-
|
|
800
|
+
_h.sent();
|
|
799
801
|
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"));
|
|
800
802
|
return [2 /*return*/];
|
|
801
803
|
}
|
|
802
804
|
});
|
|
803
805
|
};
|
|
804
806
|
this_1 = this;
|
|
805
|
-
|
|
807
|
+
idx = 0;
|
|
808
|
+
_g.label = 5;
|
|
806
809
|
case 5:
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
_h.label = 6;
|
|
810
|
+
if (!(idx !== toolCalls.length)) return [3 /*break*/, 8];
|
|
811
|
+
return [5 /*yield**/, _loop_1(idx)];
|
|
810
812
|
case 6:
|
|
811
|
-
|
|
812
|
-
tool = toolCalls_1_1.value;
|
|
813
|
-
return [5 /*yield**/, _loop_1(tool)];
|
|
814
|
-
case 7:
|
|
815
|
-
state_1 = _h.sent();
|
|
813
|
+
state_1 = _g.sent();
|
|
816
814
|
if (typeof state_1 === "object")
|
|
817
815
|
return [2 /*return*/, state_1.value];
|
|
818
|
-
|
|
816
|
+
_g.label = 7;
|
|
817
|
+
case 7:
|
|
818
|
+
idx++;
|
|
819
|
+
return [3 /*break*/, 5];
|
|
819
820
|
case 8:
|
|
820
|
-
|
|
821
|
-
return [3 /*break*/, 6];
|
|
822
|
-
case 9: return [3 /*break*/, 12];
|
|
823
|
-
case 10:
|
|
824
|
-
e_1_1 = _h.sent();
|
|
825
|
-
e_1 = { error: e_1_1 };
|
|
826
|
-
return [3 /*break*/, 12];
|
|
827
|
-
case 11:
|
|
828
|
-
try {
|
|
829
|
-
if (toolCalls_1_1 && !toolCalls_1_1.done && (_a = toolCalls_1.return)) _a.call(toolCalls_1);
|
|
830
|
-
}
|
|
831
|
-
finally { if (e_1) throw e_1.error; }
|
|
832
|
-
return [7 /*endfinally*/];
|
|
833
|
-
case 12:
|
|
834
|
-
((_g = this.params.callbacks) === null || _g === void 0 ? void 0 : _g.onAfterToolCalls) &&
|
|
821
|
+
((_f = this.params.callbacks) === null || _f === void 0 ? void 0 : _f.onAfterToolCalls) &&
|
|
835
822
|
this.params.callbacks.onAfterToolCalls(this.params.clientId, this.params.agentName, toolCalls);
|
|
836
823
|
return [2 /*return*/];
|
|
837
|
-
case
|
|
824
|
+
case 9:
|
|
838
825
|
if (!message.tool_calls) {
|
|
839
826
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute no tool calls detected"));
|
|
840
827
|
}
|
|
841
|
-
|
|
828
|
+
return [4 /*yield*/, this.params.transform(message.content, this.params.clientId, this.params.agentName)];
|
|
829
|
+
case 10:
|
|
830
|
+
result = _g.sent();
|
|
842
831
|
return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
|
|
843
|
-
case
|
|
844
|
-
|
|
832
|
+
case 11:
|
|
833
|
+
_g.sent();
|
|
845
834
|
validation = null;
|
|
846
835
|
return [4 /*yield*/, this.params.validate(result)];
|
|
847
|
-
case
|
|
848
|
-
if (!(validation =
|
|
836
|
+
case 12:
|
|
837
|
+
if (!(validation = _g.sent())) return [3 /*break*/, 15];
|
|
849
838
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute invalid tool call detected: ").concat(validation), { result: result });
|
|
850
839
|
return [4 /*yield*/, this._resurrectModel(mode, "Invalid model output: ".concat(result))];
|
|
851
|
-
case
|
|
852
|
-
result1 =
|
|
840
|
+
case 13:
|
|
841
|
+
result1 = _g.sent();
|
|
853
842
|
return [4 /*yield*/, this._emitOuput(mode, result1)];
|
|
854
|
-
case
|
|
855
|
-
|
|
843
|
+
case 14:
|
|
844
|
+
_g.sent();
|
|
856
845
|
return [2 /*return*/];
|
|
857
|
-
case
|
|
846
|
+
case 15:
|
|
858
847
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute end result=").concat(result));
|
|
859
848
|
return [4 /*yield*/, this._emitOuput(mode, result)];
|
|
860
|
-
case
|
|
861
|
-
|
|
849
|
+
case 16:
|
|
850
|
+
_g.sent();
|
|
862
851
|
return [2 /*return*/];
|
|
863
852
|
}
|
|
864
853
|
});
|
package/build/index.mjs
CHANGED
|
@@ -534,11 +534,13 @@ var ClientAgent = /** @class */ (function () {
|
|
|
534
534
|
return [4 /*yield*/, this.params.map(rawMessage, this.params.clientId, this.params.agentName)];
|
|
535
535
|
case 4:
|
|
536
536
|
message = _a.sent();
|
|
537
|
-
|
|
537
|
+
return [4 /*yield*/, this.params.transform(message.content, this.params.clientId, this.params.agentName)];
|
|
538
|
+
case 5:
|
|
539
|
+
result = _a.sent();
|
|
538
540
|
validation = null;
|
|
539
541
|
return [4 /*yield*/, this.params.validate(result)];
|
|
540
|
-
case
|
|
541
|
-
if (!(validation = _a.sent())) return [3 /*break*/,
|
|
542
|
+
case 6:
|
|
543
|
+
if (!(validation = _a.sent())) return [3 /*break*/, 8];
|
|
542
544
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel validation error: ").concat(validation));
|
|
543
545
|
content = getPlaceholder();
|
|
544
546
|
return [4 /*yield*/, this.params.history.push({
|
|
@@ -547,11 +549,11 @@ var ClientAgent = /** @class */ (function () {
|
|
|
547
549
|
mode: "tool",
|
|
548
550
|
content: content,
|
|
549
551
|
})];
|
|
550
|
-
case
|
|
552
|
+
case 7:
|
|
551
553
|
_a.sent();
|
|
552
554
|
return [2 /*return*/, content];
|
|
553
|
-
case
|
|
554
|
-
case
|
|
555
|
+
case 8: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
|
|
556
|
+
case 9:
|
|
555
557
|
_a.sent();
|
|
556
558
|
return [2 /*return*/, result];
|
|
557
559
|
}
|
|
@@ -708,12 +710,11 @@ var ClientAgent = /** @class */ (function () {
|
|
|
708
710
|
* @returns {Promise<void>}
|
|
709
711
|
*/
|
|
710
712
|
this.execute = queued(function (incoming, mode) { return __awaiter(_this, void 0, void 0, function () {
|
|
711
|
-
var rawMessage, message, toolCalls, _loop_1, this_1,
|
|
712
|
-
var e_1, _a;
|
|
713
|
+
var rawMessage, message, toolCalls, _loop_1, this_1, idx, state_1, result, validation, result1;
|
|
713
714
|
var _this = this;
|
|
714
|
-
var _b, _c, _d, _e, _f
|
|
715
|
-
return __generator(this, function (
|
|
716
|
-
switch (
|
|
715
|
+
var _a, _b, _c, _d, _e, _f;
|
|
716
|
+
return __generator(this, function (_g) {
|
|
717
|
+
switch (_g.label) {
|
|
717
718
|
case 0:
|
|
718
719
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute begin"), { incoming: incoming, mode: mode });
|
|
719
720
|
this.params.onExecute &&
|
|
@@ -725,14 +726,14 @@ var ClientAgent = /** @class */ (function () {
|
|
|
725
726
|
content: incoming.trim(),
|
|
726
727
|
})];
|
|
727
728
|
case 1:
|
|
728
|
-
|
|
729
|
+
_g.sent();
|
|
729
730
|
return [4 /*yield*/, this.getCompletion(mode)];
|
|
730
731
|
case 2:
|
|
731
|
-
rawMessage =
|
|
732
|
+
rawMessage = _g.sent();
|
|
732
733
|
return [4 /*yield*/, this.params.map(rawMessage, this.params.clientId, this.params.agentName)];
|
|
733
734
|
case 3:
|
|
734
|
-
message =
|
|
735
|
-
if (!message.tool_calls) return [3 /*break*/,
|
|
735
|
+
message = _g.sent();
|
|
736
|
+
if (!message.tool_calls) return [3 /*break*/, 9];
|
|
736
737
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " tool call begin"));
|
|
737
738
|
toolCalls = message.tool_calls.map(function (call) {
|
|
738
739
|
var _a, _b;
|
|
@@ -744,45 +745,46 @@ var ClientAgent = /** @class */ (function () {
|
|
|
744
745
|
});
|
|
745
746
|
return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
|
|
746
747
|
case 4:
|
|
747
|
-
|
|
748
|
-
_loop_1 = function (
|
|
749
|
-
var targetFn, result_2, result_3;
|
|
750
|
-
return __generator(this, function (
|
|
751
|
-
switch (
|
|
748
|
+
_g.sent();
|
|
749
|
+
_loop_1 = function (idx) {
|
|
750
|
+
var tool, targetFn, result_2, result_3;
|
|
751
|
+
return __generator(this, function (_h) {
|
|
752
|
+
switch (_h.label) {
|
|
752
753
|
case 0:
|
|
753
|
-
|
|
754
|
+
tool = toolCalls[idx];
|
|
755
|
+
targetFn = (_a = this_1.params.tools) === null || _a === void 0 ? void 0 : _a.find(function (t) { return t.function.name === tool.function.name; });
|
|
754
756
|
if (!!targetFn) return [3 /*break*/, 3];
|
|
755
757
|
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);
|
|
756
758
|
return [4 /*yield*/, this_1._resurrectModel(mode, "No target function for ".concat(tool.function.name))];
|
|
757
759
|
case 1:
|
|
758
|
-
result_2 =
|
|
760
|
+
result_2 = _h.sent();
|
|
759
761
|
this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_2));
|
|
760
762
|
return [4 /*yield*/, this_1._emitOuput(mode, result_2)];
|
|
761
763
|
case 2:
|
|
762
|
-
|
|
764
|
+
_h.sent();
|
|
763
765
|
return [2 /*return*/, { value: void 0 }];
|
|
764
766
|
case 3:
|
|
765
|
-
((
|
|
766
|
-
((
|
|
767
|
+
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onValidate) &&
|
|
768
|
+
((_c = targetFn.callbacks) === null || _c === void 0 ? void 0 : _c.onValidate(this_1.params.clientId, this_1.params.agentName, tool.function.arguments));
|
|
767
769
|
return [4 /*yield*/, not(targetFn.validate(this_1.params.clientId, this_1.params.agentName, tool.function.arguments))];
|
|
768
770
|
case 4:
|
|
769
|
-
if (!
|
|
771
|
+
if (!_h.sent()) return [3 /*break*/, 7];
|
|
770
772
|
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"));
|
|
771
773
|
return [4 /*yield*/, this_1._resurrectModel(mode, "Function validation failed: name=".concat(tool.function.name, " arguments=").concat(JSON.stringify(tool.function.arguments)))];
|
|
772
774
|
case 5:
|
|
773
|
-
result_3 =
|
|
775
|
+
result_3 = _h.sent();
|
|
774
776
|
this_1.params.logger.debug("ClientAgent agentName=".concat(this_1.params.agentName, " clientId=").concat(this_1.params.clientId, " execute end result=").concat(result_3));
|
|
775
777
|
return [4 /*yield*/, this_1._emitOuput(mode, result_3)];
|
|
776
778
|
case 6:
|
|
777
|
-
|
|
779
|
+
_h.sent();
|
|
778
780
|
return [2 /*return*/, { value: void 0 }];
|
|
779
781
|
case 7:
|
|
780
|
-
((
|
|
781
|
-
((
|
|
782
|
+
((_d = targetFn.callbacks) === null || _d === void 0 ? void 0 : _d.onBeforeCall) &&
|
|
783
|
+
((_e = targetFn.callbacks) === null || _e === void 0 ? void 0 : _e.onBeforeCall(tool.id, this_1.params.clientId, this_1.params.agentName, tool.function.arguments));
|
|
782
784
|
/**
|
|
783
785
|
* @description Do not await to avoid deadlock! The tool can send the message to other agents by emulating user messages
|
|
784
786
|
*/
|
|
785
|
-
Promise.resolve(targetFn.call(tool.id, this_1.params.clientId, this_1.params.agentName, tool.function.arguments)).then(function () {
|
|
787
|
+
Promise.resolve(targetFn.call(tool.id, this_1.params.clientId, this_1.params.agentName, tool.function.arguments, idx === toolCalls.length - 1)).then(function () {
|
|
786
788
|
var _a, _b;
|
|
787
789
|
((_a = targetFn.callbacks) === null || _a === void 0 ? void 0 : _a.onAfterCall) &&
|
|
788
790
|
((_b = targetFn.callbacks) === null || _b === void 0 ? void 0 : _b.onAfterCall(tool.id, _this.params.clientId, _this.params.agentName, tool.function.arguments));
|
|
@@ -793,70 +795,57 @@ var ClientAgent = /** @class */ (function () {
|
|
|
793
795
|
this_1._outputSubject.toPromise(),
|
|
794
796
|
])];
|
|
795
797
|
case 8:
|
|
796
|
-
|
|
798
|
+
_h.sent();
|
|
797
799
|
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"));
|
|
798
800
|
return [2 /*return*/];
|
|
799
801
|
}
|
|
800
802
|
});
|
|
801
803
|
};
|
|
802
804
|
this_1 = this;
|
|
803
|
-
|
|
805
|
+
idx = 0;
|
|
806
|
+
_g.label = 5;
|
|
804
807
|
case 5:
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
_h.label = 6;
|
|
808
|
+
if (!(idx !== toolCalls.length)) return [3 /*break*/, 8];
|
|
809
|
+
return [5 /*yield**/, _loop_1(idx)];
|
|
808
810
|
case 6:
|
|
809
|
-
|
|
810
|
-
tool = toolCalls_1_1.value;
|
|
811
|
-
return [5 /*yield**/, _loop_1(tool)];
|
|
812
|
-
case 7:
|
|
813
|
-
state_1 = _h.sent();
|
|
811
|
+
state_1 = _g.sent();
|
|
814
812
|
if (typeof state_1 === "object")
|
|
815
813
|
return [2 /*return*/, state_1.value];
|
|
816
|
-
|
|
814
|
+
_g.label = 7;
|
|
815
|
+
case 7:
|
|
816
|
+
idx++;
|
|
817
|
+
return [3 /*break*/, 5];
|
|
817
818
|
case 8:
|
|
818
|
-
|
|
819
|
-
return [3 /*break*/, 6];
|
|
820
|
-
case 9: return [3 /*break*/, 12];
|
|
821
|
-
case 10:
|
|
822
|
-
e_1_1 = _h.sent();
|
|
823
|
-
e_1 = { error: e_1_1 };
|
|
824
|
-
return [3 /*break*/, 12];
|
|
825
|
-
case 11:
|
|
826
|
-
try {
|
|
827
|
-
if (toolCalls_1_1 && !toolCalls_1_1.done && (_a = toolCalls_1.return)) _a.call(toolCalls_1);
|
|
828
|
-
}
|
|
829
|
-
finally { if (e_1) throw e_1.error; }
|
|
830
|
-
return [7 /*endfinally*/];
|
|
831
|
-
case 12:
|
|
832
|
-
((_g = this.params.callbacks) === null || _g === void 0 ? void 0 : _g.onAfterToolCalls) &&
|
|
819
|
+
((_f = this.params.callbacks) === null || _f === void 0 ? void 0 : _f.onAfterToolCalls) &&
|
|
833
820
|
this.params.callbacks.onAfterToolCalls(this.params.clientId, this.params.agentName, toolCalls);
|
|
834
821
|
return [2 /*return*/];
|
|
835
|
-
case
|
|
822
|
+
case 9:
|
|
836
823
|
if (!message.tool_calls) {
|
|
837
824
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute no tool calls detected"));
|
|
838
825
|
}
|
|
839
|
-
|
|
826
|
+
return [4 /*yield*/, this.params.transform(message.content, this.params.clientId, this.params.agentName)];
|
|
827
|
+
case 10:
|
|
828
|
+
result = _g.sent();
|
|
840
829
|
return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
|
|
841
|
-
case
|
|
842
|
-
|
|
830
|
+
case 11:
|
|
831
|
+
_g.sent();
|
|
843
832
|
validation = null;
|
|
844
833
|
return [4 /*yield*/, this.params.validate(result)];
|
|
845
|
-
case
|
|
846
|
-
if (!(validation =
|
|
834
|
+
case 12:
|
|
835
|
+
if (!(validation = _g.sent())) return [3 /*break*/, 15];
|
|
847
836
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute invalid tool call detected: ").concat(validation), { result: result });
|
|
848
837
|
return [4 /*yield*/, this._resurrectModel(mode, "Invalid model output: ".concat(result))];
|
|
849
|
-
case
|
|
850
|
-
result1 =
|
|
838
|
+
case 13:
|
|
839
|
+
result1 = _g.sent();
|
|
851
840
|
return [4 /*yield*/, this._emitOuput(mode, result1)];
|
|
852
|
-
case
|
|
853
|
-
|
|
841
|
+
case 14:
|
|
842
|
+
_g.sent();
|
|
854
843
|
return [2 /*return*/];
|
|
855
|
-
case
|
|
844
|
+
case 15:
|
|
856
845
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " execute end result=").concat(result));
|
|
857
846
|
return [4 /*yield*/, this._emitOuput(mode, result)];
|
|
858
|
-
case
|
|
859
|
-
|
|
847
|
+
case 16:
|
|
848
|
+
_g.sent();
|
|
860
849
|
return [2 /*return*/];
|
|
861
850
|
}
|
|
862
851
|
});
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -538,7 +538,7 @@ interface IAgentTool<T = Record<string, unknown>> extends ITool {
|
|
|
538
538
|
* @param params - The parameters for the tool.
|
|
539
539
|
* @returns A promise that resolves when the tool call is complete.
|
|
540
540
|
*/
|
|
541
|
-
call(toolId: string, clientId: string, agentName: AgentName, params: T): Promise<void>;
|
|
541
|
+
call(toolId: string, clientId: string, agentName: AgentName, params: T, isLast: boolean): Promise<void>;
|
|
542
542
|
/**
|
|
543
543
|
* Validates the parameters for the tool.
|
|
544
544
|
* @param clientId - The ID of the client.
|