agent-swarm-kit 1.0.35 → 1.0.37
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 +32 -17
- package/build/index.mjs +32 -17
- package/package.json +1 -1
- package/types.d.ts +10 -1
package/build/index.cjs
CHANGED
|
@@ -355,6 +355,10 @@ var validateDefault = function (output) { return __awaiter(void 0, void 0, void
|
|
|
355
355
|
});
|
|
356
356
|
}); };
|
|
357
357
|
|
|
358
|
+
var removeXmlTags = function (input) {
|
|
359
|
+
return input.replace(/<[^>]*>.*?<\/[^>]*>/g, '');
|
|
360
|
+
};
|
|
361
|
+
|
|
358
362
|
/**
|
|
359
363
|
* @description `ask for agent function` in `llama3.1:8b` to troubleshoot (need CC_OLLAMA_EMIT_TOOL_PROTOCOL to be turned off)
|
|
360
364
|
*/
|
|
@@ -396,8 +400,20 @@ var CC_AGENT_DISALLOWED_SYMBOLS = [
|
|
|
396
400
|
"{",
|
|
397
401
|
"}",
|
|
398
402
|
];
|
|
403
|
+
var CC_AGENT_HISTORY_FILTER = function (agentName) { return function (message) {
|
|
404
|
+
var isOk = true;
|
|
405
|
+
if (message.role === "tool") {
|
|
406
|
+
isOk = isOk && message.agentName === agentName;
|
|
407
|
+
}
|
|
408
|
+
if (message.tool_calls) {
|
|
409
|
+
isOk = isOk && message.agentName === agentName;
|
|
410
|
+
}
|
|
411
|
+
return isOk;
|
|
412
|
+
}; };
|
|
413
|
+
var CC_AGENT_OUTPUT_TRANSFORM = removeXmlTags;
|
|
399
414
|
var CC_KEEP_MESSAGES = 5;
|
|
400
415
|
var CC_GET_AGENT_HISTORY = function () { return new functoolsKit.PubsubArrayAdapter(); };
|
|
416
|
+
var CC_AGENT_SEPARATE_HISTORY = false;
|
|
401
417
|
var GLOBAL_CONFIG = {
|
|
402
418
|
CC_TOOL_CALL_EXCEPTION_PROMPT: CC_TOOL_CALL_EXCEPTION_PROMPT,
|
|
403
419
|
CC_EMPTY_OUTPUT_PLACEHOLDERS: CC_EMPTY_OUTPUT_PLACEHOLDERS,
|
|
@@ -406,6 +422,9 @@ var GLOBAL_CONFIG = {
|
|
|
406
422
|
CC_SWARM_AGENT_CHANGED: CC_SWARM_AGENT_CHANGED,
|
|
407
423
|
CC_SWARM_DEFAULT_AGENT: CC_SWARM_DEFAULT_AGENT,
|
|
408
424
|
CC_AGENT_DEFAULT_VALIDATION: CC_AGENT_DEFAULT_VALIDATION,
|
|
425
|
+
CC_AGENT_HISTORY_FILTER: CC_AGENT_HISTORY_FILTER,
|
|
426
|
+
CC_AGENT_OUTPUT_TRANSFORM: CC_AGENT_OUTPUT_TRANSFORM,
|
|
427
|
+
CC_AGENT_SEPARATE_HISTORY: CC_AGENT_SEPARATE_HISTORY,
|
|
409
428
|
CC_AGENT_DISALLOWED_TAGS: CC_AGENT_DISALLOWED_TAGS,
|
|
410
429
|
CC_AGENT_DISALLOWED_SYMBOLS: CC_AGENT_DISALLOWED_SYMBOLS,
|
|
411
430
|
};
|
|
@@ -436,19 +455,21 @@ var ClientAgent = /** @class */ (function () {
|
|
|
436
455
|
* @returns {Promise<void>}
|
|
437
456
|
* @private
|
|
438
457
|
*/
|
|
439
|
-
this._emitOuput = function (mode,
|
|
440
|
-
var validation, result_1;
|
|
458
|
+
this._emitOuput = function (mode, rawResult) { return __awaiter(_this, void 0, void 0, function () {
|
|
459
|
+
var result, validation, rawResult_1, result_1;
|
|
441
460
|
return __generator(this, function (_a) {
|
|
442
461
|
switch (_a.label) {
|
|
443
462
|
case 0:
|
|
444
|
-
|
|
463
|
+
result = this.params.transform(rawResult);
|
|
464
|
+
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _emitOuput"), { mode: mode, result: result, rawResult: rawResult });
|
|
445
465
|
validation = null;
|
|
446
466
|
return [4 /*yield*/, this.params.validate(result)];
|
|
447
467
|
case 1:
|
|
448
468
|
if (!(validation = _a.sent())) return [3 /*break*/, 5];
|
|
449
469
|
return [4 /*yield*/, this._resurrectModel(mode, validation)];
|
|
450
470
|
case 2:
|
|
451
|
-
|
|
471
|
+
rawResult_1 = _a.sent();
|
|
472
|
+
result_1 = this.params.transform(rawResult_1);
|
|
452
473
|
return [4 /*yield*/, this.params.validate(result_1)];
|
|
453
474
|
case 3:
|
|
454
475
|
if ((validation = _a.sent())) {
|
|
@@ -854,10 +875,10 @@ var AgentConnectionService = /** @class */ (function () {
|
|
|
854
875
|
var _b = __read(_a, 2), clientId = _b[0], agentName = _b[1];
|
|
855
876
|
return "".concat(clientId, "-").concat(agentName);
|
|
856
877
|
}, function (clientId, agentName) {
|
|
857
|
-
var _a = _this.agentSchemaService.get(agentName), prompt = _a.prompt, system = _a.system, tools = _a.tools, callbacks = _a.callbacks, completionName = _a.completion,
|
|
878
|
+
var _a = _this.agentSchemaService.get(agentName), prompt = _a.prompt, system = _a.system, tools = _a.tools, _b = _a.transform, transform = _b === void 0 ? GLOBAL_CONFIG.CC_AGENT_OUTPUT_TRANSFORM : _b, callbacks = _a.callbacks, completionName = _a.completion, _c = _a.validate, validate = _c === void 0 ? validateDefault : _c;
|
|
858
879
|
var completion = _this.completionSchemaService.get(completionName);
|
|
859
880
|
_this.sessionValidationService.addAgentUsage(clientId, agentName);
|
|
860
|
-
return new ClientAgent(__assign({ clientId: clientId, agentName: agentName, validate: validate, logger: _this.loggerService, history: _this.historyConnectionService.getHistory(clientId, agentName), prompt: prompt, system: system, tools: tools === null || tools === void 0 ? void 0 : tools.map(_this.toolSchemaService.get), completion: completion }, callbacks));
|
|
881
|
+
return new ClientAgent(__assign({ clientId: clientId, agentName: agentName, validate: validate, logger: _this.loggerService, history: _this.historyConnectionService.getHistory(clientId, agentName), prompt: prompt, system: system, transform: transform, tools: tools === null || tools === void 0 ? void 0 : tools.map(_this.toolSchemaService.get), completion: completion }, callbacks));
|
|
861
882
|
});
|
|
862
883
|
/**
|
|
863
884
|
* Executes an input command.
|
|
@@ -1137,17 +1158,7 @@ var ClientHistory = /** @class */ (function () {
|
|
|
1137
1158
|
return agentName === _this.params.agentName;
|
|
1138
1159
|
});
|
|
1139
1160
|
commonMessages = commonMessagesRaw
|
|
1140
|
-
.filter(
|
|
1141
|
-
var role = _a.role, agentName = _a.agentName, tool_calls = _a.tool_calls;
|
|
1142
|
-
var isOk = true;
|
|
1143
|
-
if (role === "tool") {
|
|
1144
|
-
isOk = isOk && agentName === _this.params.agentName;
|
|
1145
|
-
}
|
|
1146
|
-
if (tool_calls) {
|
|
1147
|
-
isOk = isOk && agentName === _this.params.agentName;
|
|
1148
|
-
}
|
|
1149
|
-
return isOk;
|
|
1150
|
-
})
|
|
1161
|
+
.filter(this._filterCondition)
|
|
1151
1162
|
.slice(-GLOBAL_CONFIG.CC_KEEP_MESSAGES);
|
|
1152
1163
|
promptMessages = [];
|
|
1153
1164
|
{
|
|
@@ -1174,6 +1185,7 @@ var ClientHistory = /** @class */ (function () {
|
|
|
1174
1185
|
this.params.logger.debug("ClientHistory agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR"), {
|
|
1175
1186
|
params: params,
|
|
1176
1187
|
});
|
|
1188
|
+
this._filterCondition = GLOBAL_CONFIG.CC_AGENT_HISTORY_FILTER(this.params.agentName);
|
|
1177
1189
|
}
|
|
1178
1190
|
return ClientHistory;
|
|
1179
1191
|
}());
|
|
@@ -1279,10 +1291,13 @@ var HistoryConnectionService = /** @class */ (function () {
|
|
|
1279
1291
|
this.loggerService.log("historyConnectionService dispose", {
|
|
1280
1292
|
context: this.contextService.context,
|
|
1281
1293
|
});
|
|
1294
|
+
if (!GLOBAL_CONFIG.CC_AGENT_SEPARATE_HISTORY) return [3 /*break*/, 2];
|
|
1282
1295
|
return [4 /*yield*/, this.getItems(this.contextService.context.clientId, this.contextService.context.agentName).clear()];
|
|
1283
1296
|
case 1:
|
|
1284
1297
|
_a.sent();
|
|
1285
1298
|
this.getItems.clear(this.contextService.context.clientId);
|
|
1299
|
+
_a.label = 2;
|
|
1300
|
+
case 2:
|
|
1286
1301
|
this.getHistory.clear("".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.agentName));
|
|
1287
1302
|
this.sessionValidationService.removeHistoryUsage(this.contextService.context.clientId, this.contextService.context.agentName);
|
|
1288
1303
|
return [2 /*return*/];
|
package/build/index.mjs
CHANGED
|
@@ -353,6 +353,10 @@ var validateDefault = function (output) { return __awaiter(void 0, void 0, void
|
|
|
353
353
|
});
|
|
354
354
|
}); };
|
|
355
355
|
|
|
356
|
+
var removeXmlTags = function (input) {
|
|
357
|
+
return input.replace(/<[^>]*>.*?<\/[^>]*>/g, '');
|
|
358
|
+
};
|
|
359
|
+
|
|
356
360
|
/**
|
|
357
361
|
* @description `ask for agent function` in `llama3.1:8b` to troubleshoot (need CC_OLLAMA_EMIT_TOOL_PROTOCOL to be turned off)
|
|
358
362
|
*/
|
|
@@ -394,8 +398,20 @@ var CC_AGENT_DISALLOWED_SYMBOLS = [
|
|
|
394
398
|
"{",
|
|
395
399
|
"}",
|
|
396
400
|
];
|
|
401
|
+
var CC_AGENT_HISTORY_FILTER = function (agentName) { return function (message) {
|
|
402
|
+
var isOk = true;
|
|
403
|
+
if (message.role === "tool") {
|
|
404
|
+
isOk = isOk && message.agentName === agentName;
|
|
405
|
+
}
|
|
406
|
+
if (message.tool_calls) {
|
|
407
|
+
isOk = isOk && message.agentName === agentName;
|
|
408
|
+
}
|
|
409
|
+
return isOk;
|
|
410
|
+
}; };
|
|
411
|
+
var CC_AGENT_OUTPUT_TRANSFORM = removeXmlTags;
|
|
397
412
|
var CC_KEEP_MESSAGES = 5;
|
|
398
413
|
var CC_GET_AGENT_HISTORY = function () { return new PubsubArrayAdapter(); };
|
|
414
|
+
var CC_AGENT_SEPARATE_HISTORY = false;
|
|
399
415
|
var GLOBAL_CONFIG = {
|
|
400
416
|
CC_TOOL_CALL_EXCEPTION_PROMPT: CC_TOOL_CALL_EXCEPTION_PROMPT,
|
|
401
417
|
CC_EMPTY_OUTPUT_PLACEHOLDERS: CC_EMPTY_OUTPUT_PLACEHOLDERS,
|
|
@@ -404,6 +420,9 @@ var GLOBAL_CONFIG = {
|
|
|
404
420
|
CC_SWARM_AGENT_CHANGED: CC_SWARM_AGENT_CHANGED,
|
|
405
421
|
CC_SWARM_DEFAULT_AGENT: CC_SWARM_DEFAULT_AGENT,
|
|
406
422
|
CC_AGENT_DEFAULT_VALIDATION: CC_AGENT_DEFAULT_VALIDATION,
|
|
423
|
+
CC_AGENT_HISTORY_FILTER: CC_AGENT_HISTORY_FILTER,
|
|
424
|
+
CC_AGENT_OUTPUT_TRANSFORM: CC_AGENT_OUTPUT_TRANSFORM,
|
|
425
|
+
CC_AGENT_SEPARATE_HISTORY: CC_AGENT_SEPARATE_HISTORY,
|
|
407
426
|
CC_AGENT_DISALLOWED_TAGS: CC_AGENT_DISALLOWED_TAGS,
|
|
408
427
|
CC_AGENT_DISALLOWED_SYMBOLS: CC_AGENT_DISALLOWED_SYMBOLS,
|
|
409
428
|
};
|
|
@@ -434,19 +453,21 @@ var ClientAgent = /** @class */ (function () {
|
|
|
434
453
|
* @returns {Promise<void>}
|
|
435
454
|
* @private
|
|
436
455
|
*/
|
|
437
|
-
this._emitOuput = function (mode,
|
|
438
|
-
var validation, result_1;
|
|
456
|
+
this._emitOuput = function (mode, rawResult) { return __awaiter(_this, void 0, void 0, function () {
|
|
457
|
+
var result, validation, rawResult_1, result_1;
|
|
439
458
|
return __generator(this, function (_a) {
|
|
440
459
|
switch (_a.label) {
|
|
441
460
|
case 0:
|
|
442
|
-
|
|
461
|
+
result = this.params.transform(rawResult);
|
|
462
|
+
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _emitOuput"), { mode: mode, result: result, rawResult: rawResult });
|
|
443
463
|
validation = null;
|
|
444
464
|
return [4 /*yield*/, this.params.validate(result)];
|
|
445
465
|
case 1:
|
|
446
466
|
if (!(validation = _a.sent())) return [3 /*break*/, 5];
|
|
447
467
|
return [4 /*yield*/, this._resurrectModel(mode, validation)];
|
|
448
468
|
case 2:
|
|
449
|
-
|
|
469
|
+
rawResult_1 = _a.sent();
|
|
470
|
+
result_1 = this.params.transform(rawResult_1);
|
|
450
471
|
return [4 /*yield*/, this.params.validate(result_1)];
|
|
451
472
|
case 3:
|
|
452
473
|
if ((validation = _a.sent())) {
|
|
@@ -852,10 +873,10 @@ var AgentConnectionService = /** @class */ (function () {
|
|
|
852
873
|
var _b = __read(_a, 2), clientId = _b[0], agentName = _b[1];
|
|
853
874
|
return "".concat(clientId, "-").concat(agentName);
|
|
854
875
|
}, function (clientId, agentName) {
|
|
855
|
-
var _a = _this.agentSchemaService.get(agentName), prompt = _a.prompt, system = _a.system, tools = _a.tools, callbacks = _a.callbacks, completionName = _a.completion,
|
|
876
|
+
var _a = _this.agentSchemaService.get(agentName), prompt = _a.prompt, system = _a.system, tools = _a.tools, _b = _a.transform, transform = _b === void 0 ? GLOBAL_CONFIG.CC_AGENT_OUTPUT_TRANSFORM : _b, callbacks = _a.callbacks, completionName = _a.completion, _c = _a.validate, validate = _c === void 0 ? validateDefault : _c;
|
|
856
877
|
var completion = _this.completionSchemaService.get(completionName);
|
|
857
878
|
_this.sessionValidationService.addAgentUsage(clientId, agentName);
|
|
858
|
-
return new ClientAgent(__assign({ clientId: clientId, agentName: agentName, validate: validate, logger: _this.loggerService, history: _this.historyConnectionService.getHistory(clientId, agentName), prompt: prompt, system: system, tools: tools === null || tools === void 0 ? void 0 : tools.map(_this.toolSchemaService.get), completion: completion }, callbacks));
|
|
879
|
+
return new ClientAgent(__assign({ clientId: clientId, agentName: agentName, validate: validate, logger: _this.loggerService, history: _this.historyConnectionService.getHistory(clientId, agentName), prompt: prompt, system: system, transform: transform, tools: tools === null || tools === void 0 ? void 0 : tools.map(_this.toolSchemaService.get), completion: completion }, callbacks));
|
|
859
880
|
});
|
|
860
881
|
/**
|
|
861
882
|
* Executes an input command.
|
|
@@ -1135,17 +1156,7 @@ var ClientHistory = /** @class */ (function () {
|
|
|
1135
1156
|
return agentName === _this.params.agentName;
|
|
1136
1157
|
});
|
|
1137
1158
|
commonMessages = commonMessagesRaw
|
|
1138
|
-
.filter(
|
|
1139
|
-
var role = _a.role, agentName = _a.agentName, tool_calls = _a.tool_calls;
|
|
1140
|
-
var isOk = true;
|
|
1141
|
-
if (role === "tool") {
|
|
1142
|
-
isOk = isOk && agentName === _this.params.agentName;
|
|
1143
|
-
}
|
|
1144
|
-
if (tool_calls) {
|
|
1145
|
-
isOk = isOk && agentName === _this.params.agentName;
|
|
1146
|
-
}
|
|
1147
|
-
return isOk;
|
|
1148
|
-
})
|
|
1159
|
+
.filter(this._filterCondition)
|
|
1149
1160
|
.slice(-GLOBAL_CONFIG.CC_KEEP_MESSAGES);
|
|
1150
1161
|
promptMessages = [];
|
|
1151
1162
|
{
|
|
@@ -1172,6 +1183,7 @@ var ClientHistory = /** @class */ (function () {
|
|
|
1172
1183
|
this.params.logger.debug("ClientHistory agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR"), {
|
|
1173
1184
|
params: params,
|
|
1174
1185
|
});
|
|
1186
|
+
this._filterCondition = GLOBAL_CONFIG.CC_AGENT_HISTORY_FILTER(this.params.agentName);
|
|
1175
1187
|
}
|
|
1176
1188
|
return ClientHistory;
|
|
1177
1189
|
}());
|
|
@@ -1277,10 +1289,13 @@ var HistoryConnectionService = /** @class */ (function () {
|
|
|
1277
1289
|
this.loggerService.log("historyConnectionService dispose", {
|
|
1278
1290
|
context: this.contextService.context,
|
|
1279
1291
|
});
|
|
1292
|
+
if (!GLOBAL_CONFIG.CC_AGENT_SEPARATE_HISTORY) return [3 /*break*/, 2];
|
|
1280
1293
|
return [4 /*yield*/, this.getItems(this.contextService.context.clientId, this.contextService.context.agentName).clear()];
|
|
1281
1294
|
case 1:
|
|
1282
1295
|
_a.sent();
|
|
1283
1296
|
this.getItems.clear(this.contextService.context.clientId);
|
|
1297
|
+
_a.label = 2;
|
|
1298
|
+
case 2:
|
|
1284
1299
|
this.getHistory.clear("".concat(this.contextService.context.clientId, "-").concat(this.contextService.context.agentName));
|
|
1285
1300
|
this.sessionValidationService.removeHistoryUsage(this.contextService.context.clientId, this.contextService.context.agentName);
|
|
1286
1301
|
return [2 /*return*/];
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -642,6 +642,8 @@ interface IAgentSchema {
|
|
|
642
642
|
* @returns A promise that resolves to a string or null.
|
|
643
643
|
*/
|
|
644
644
|
validate?: (output: string) => Promise<string | null>;
|
|
645
|
+
/** The transform function for model output */
|
|
646
|
+
transform?: (input: string) => string;
|
|
645
647
|
/** The lifecycle calbacks of the agent. */
|
|
646
648
|
callbacks?: Partial<IAgentSchemaCallbacks>;
|
|
647
649
|
}
|
|
@@ -751,7 +753,7 @@ declare class ClientAgent implements IAgent {
|
|
|
751
753
|
* @returns {Promise<void>}
|
|
752
754
|
* @private
|
|
753
755
|
*/
|
|
754
|
-
_emitOuput: (mode: ExecutionMode,
|
|
756
|
+
_emitOuput: (mode: ExecutionMode, rawResult: string) => Promise<void>;
|
|
755
757
|
/**
|
|
756
758
|
* Resurrects the model based on the given reason.
|
|
757
759
|
* @param {string} [reason] - The reason for resurrecting the model.
|
|
@@ -871,6 +873,10 @@ declare class AgentConnectionService implements IAgent {
|
|
|
871
873
|
*/
|
|
872
874
|
declare class ClientHistory implements IHistory {
|
|
873
875
|
readonly params: IHistoryParams;
|
|
876
|
+
/**
|
|
877
|
+
* Filter condition for `toArrayForAgent`
|
|
878
|
+
*/
|
|
879
|
+
_filterCondition: (message: IModelMessage) => boolean;
|
|
874
880
|
/**
|
|
875
881
|
* Creates an instance of ClientHistory.
|
|
876
882
|
* @param {IHistoryParams} params - The parameters for the history.
|
|
@@ -2044,6 +2050,9 @@ declare const GLOBAL_CONFIG: {
|
|
|
2044
2050
|
CC_SWARM_AGENT_CHANGED: (clientId: string, agentName: AgentName, swarmName: SwarmName) => Promise<void>;
|
|
2045
2051
|
CC_SWARM_DEFAULT_AGENT: (clientId: string, swarmName: SwarmName, defaultAgent: AgentName) => Promise<AgentName>;
|
|
2046
2052
|
CC_AGENT_DEFAULT_VALIDATION: (output: string) => Promise<string | null>;
|
|
2053
|
+
CC_AGENT_HISTORY_FILTER: (agentName: AgentName) => (message: IModelMessage) => boolean;
|
|
2054
|
+
CC_AGENT_OUTPUT_TRANSFORM: (input: string) => string;
|
|
2055
|
+
CC_AGENT_SEPARATE_HISTORY: boolean;
|
|
2047
2056
|
CC_AGENT_DISALLOWED_TAGS: string[];
|
|
2048
2057
|
CC_AGENT_DISALLOWED_SYMBOLS: string[];
|
|
2049
2058
|
};
|