agent-swarm-kit 1.0.35 → 1.0.36

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
@@ -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,6 +400,17 @@ 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(); };
401
416
  var GLOBAL_CONFIG = {
@@ -406,6 +421,8 @@ var GLOBAL_CONFIG = {
406
421
  CC_SWARM_AGENT_CHANGED: CC_SWARM_AGENT_CHANGED,
407
422
  CC_SWARM_DEFAULT_AGENT: CC_SWARM_DEFAULT_AGENT,
408
423
  CC_AGENT_DEFAULT_VALIDATION: CC_AGENT_DEFAULT_VALIDATION,
424
+ CC_AGENT_HISTORY_FILTER: CC_AGENT_HISTORY_FILTER,
425
+ CC_AGENT_OUTPUT_TRANSFORM: CC_AGENT_OUTPUT_TRANSFORM,
409
426
  CC_AGENT_DISALLOWED_TAGS: CC_AGENT_DISALLOWED_TAGS,
410
427
  CC_AGENT_DISALLOWED_SYMBOLS: CC_AGENT_DISALLOWED_SYMBOLS,
411
428
  };
@@ -436,19 +453,21 @@ var ClientAgent = /** @class */ (function () {
436
453
  * @returns {Promise<void>}
437
454
  * @private
438
455
  */
439
- this._emitOuput = function (mode, result) { return __awaiter(_this, void 0, void 0, function () {
440
- 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;
441
458
  return __generator(this, function (_a) {
442
459
  switch (_a.label) {
443
460
  case 0:
444
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _emitOuput"));
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 });
445
463
  validation = null;
446
464
  return [4 /*yield*/, this.params.validate(result)];
447
465
  case 1:
448
466
  if (!(validation = _a.sent())) return [3 /*break*/, 5];
449
467
  return [4 /*yield*/, this._resurrectModel(mode, validation)];
450
468
  case 2:
451
- result_1 = _a.sent();
469
+ rawResult_1 = _a.sent();
470
+ result_1 = this.params.transform(rawResult_1);
452
471
  return [4 /*yield*/, this.params.validate(result_1)];
453
472
  case 3:
454
473
  if ((validation = _a.sent())) {
@@ -854,10 +873,10 @@ var AgentConnectionService = /** @class */ (function () {
854
873
  var _b = __read(_a, 2), clientId = _b[0], agentName = _b[1];
855
874
  return "".concat(clientId, "-").concat(agentName);
856
875
  }, 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, _b = _a.validate, validate = _b === void 0 ? validateDefault : _b;
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;
858
877
  var completion = _this.completionSchemaService.get(completionName);
859
878
  _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));
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));
861
880
  });
862
881
  /**
863
882
  * Executes an input command.
@@ -1137,17 +1156,7 @@ var ClientHistory = /** @class */ (function () {
1137
1156
  return agentName === _this.params.agentName;
1138
1157
  });
1139
1158
  commonMessages = commonMessagesRaw
1140
- .filter(function (_a) {
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
- })
1159
+ .filter(this._filterCondition)
1151
1160
  .slice(-GLOBAL_CONFIG.CC_KEEP_MESSAGES);
1152
1161
  promptMessages = [];
1153
1162
  {
@@ -1174,6 +1183,7 @@ var ClientHistory = /** @class */ (function () {
1174
1183
  this.params.logger.debug("ClientHistory agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR"), {
1175
1184
  params: params,
1176
1185
  });
1186
+ this._filterCondition = GLOBAL_CONFIG.CC_AGENT_HISTORY_FILTER(this.params.agentName);
1177
1187
  }
1178
1188
  return ClientHistory;
1179
1189
  }());
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,6 +398,17 @@ 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(); };
399
414
  var GLOBAL_CONFIG = {
@@ -404,6 +419,8 @@ var GLOBAL_CONFIG = {
404
419
  CC_SWARM_AGENT_CHANGED: CC_SWARM_AGENT_CHANGED,
405
420
  CC_SWARM_DEFAULT_AGENT: CC_SWARM_DEFAULT_AGENT,
406
421
  CC_AGENT_DEFAULT_VALIDATION: CC_AGENT_DEFAULT_VALIDATION,
422
+ CC_AGENT_HISTORY_FILTER: CC_AGENT_HISTORY_FILTER,
423
+ CC_AGENT_OUTPUT_TRANSFORM: CC_AGENT_OUTPUT_TRANSFORM,
407
424
  CC_AGENT_DISALLOWED_TAGS: CC_AGENT_DISALLOWED_TAGS,
408
425
  CC_AGENT_DISALLOWED_SYMBOLS: CC_AGENT_DISALLOWED_SYMBOLS,
409
426
  };
@@ -434,19 +451,21 @@ var ClientAgent = /** @class */ (function () {
434
451
  * @returns {Promise<void>}
435
452
  * @private
436
453
  */
437
- this._emitOuput = function (mode, result) { return __awaiter(_this, void 0, void 0, function () {
438
- var validation, result_1;
454
+ this._emitOuput = function (mode, rawResult) { return __awaiter(_this, void 0, void 0, function () {
455
+ var result, validation, rawResult_1, result_1;
439
456
  return __generator(this, function (_a) {
440
457
  switch (_a.label) {
441
458
  case 0:
442
- this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _emitOuput"));
459
+ result = this.params.transform(rawResult);
460
+ this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _emitOuput"), { mode: mode, result: result, rawResult: rawResult });
443
461
  validation = null;
444
462
  return [4 /*yield*/, this.params.validate(result)];
445
463
  case 1:
446
464
  if (!(validation = _a.sent())) return [3 /*break*/, 5];
447
465
  return [4 /*yield*/, this._resurrectModel(mode, validation)];
448
466
  case 2:
449
- result_1 = _a.sent();
467
+ rawResult_1 = _a.sent();
468
+ result_1 = this.params.transform(rawResult_1);
450
469
  return [4 /*yield*/, this.params.validate(result_1)];
451
470
  case 3:
452
471
  if ((validation = _a.sent())) {
@@ -852,10 +871,10 @@ var AgentConnectionService = /** @class */ (function () {
852
871
  var _b = __read(_a, 2), clientId = _b[0], agentName = _b[1];
853
872
  return "".concat(clientId, "-").concat(agentName);
854
873
  }, 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, _b = _a.validate, validate = _b === void 0 ? validateDefault : _b;
874
+ 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
875
  var completion = _this.completionSchemaService.get(completionName);
857
876
  _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));
877
+ 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
878
  });
860
879
  /**
861
880
  * Executes an input command.
@@ -1135,17 +1154,7 @@ var ClientHistory = /** @class */ (function () {
1135
1154
  return agentName === _this.params.agentName;
1136
1155
  });
1137
1156
  commonMessages = commonMessagesRaw
1138
- .filter(function (_a) {
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
- })
1157
+ .filter(this._filterCondition)
1149
1158
  .slice(-GLOBAL_CONFIG.CC_KEEP_MESSAGES);
1150
1159
  promptMessages = [];
1151
1160
  {
@@ -1172,6 +1181,7 @@ var ClientHistory = /** @class */ (function () {
1172
1181
  this.params.logger.debug("ClientHistory agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " CTOR"), {
1173
1182
  params: params,
1174
1183
  });
1184
+ this._filterCondition = GLOBAL_CONFIG.CC_AGENT_HISTORY_FILTER(this.params.agentName);
1175
1185
  }
1176
1186
  return ClientHistory;
1177
1187
  }());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.35",
3
+ "version": "1.0.36",
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
@@ -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, result: string) => Promise<void>;
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,8 @@ 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;
2047
2055
  CC_AGENT_DISALLOWED_TAGS: string[];
2048
2056
  CC_AGENT_DISALLOWED_SYMBOLS: string[];
2049
2057
  };