agent-swarm-kit 1.1.64 → 1.1.66

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/README.md CHANGED
@@ -448,7 +448,7 @@ The **Agent Tune Dataset Constructor** is a React-based tool designed for crafti
448
448
 
449
449
  - ✅ **Validation**: Ensures tool consistency, message order, and data integrity. 🛡️
450
450
 
451
- - 🚀 **Ease of Use**: Navigate with breadcrumbs, save drafts, and export directly for fine-tuning with commands like openai api fine_tunes.create. 📤
451
+ - 🚀 **Ease of Use**: Navigate with breadcrumbs, save drafts, and export directly for fine-tuning with commands like openai api [fine_tunes.create](https://platform.openai.com/docs/api-reference/fine-tuning). 📤
452
452
 
453
453
  #### Use Case
454
454
  Perfect for preparing training data to fine-tune agents within `agent-swarm-kit`, Agent Tune lets you define precise behaviors—like how a sales agent responds or a triage agent routes requests—before integrating them into your swarm. Export your dataset and fine-tune your models to enhance performance across your agent network. 🌐
package/build/index.cjs CHANGED
@@ -3425,7 +3425,7 @@ class AgentSchemaService {
3425
3425
  if (!agentSchema.operator && typeof agentSchema.completion !== "string") {
3426
3426
  throw new Error(`agent-swarm agent schema validation failed: missing completion for agentName=${agentSchema.agentName}`);
3427
3427
  }
3428
- if (!agentSchema.operator && typeof agentSchema.prompt !== "string") {
3428
+ if (!agentSchema.operator && agentSchema.prompt === undefined) {
3429
3429
  throw new Error(`agent-swarm agent schema validation failed: missing prompt for agentName=${agentSchema.agentName}`);
3430
3430
  }
3431
3431
  if (agentSchema.system && !Array.isArray(agentSchema.system)) {
@@ -3801,7 +3801,10 @@ const RUN_FN = async (incoming, self) => {
3801
3801
  self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} run begin`, { incoming });
3802
3802
  self.params.onRun &&
3803
3803
  self.params.onRun(self.params.clientId, self.params.agentName, incoming);
3804
- const messages = await self.params.history.toArrayForAgent(self.params.prompt ?? "", await self._resolveSystemPrompt());
3804
+ const prompt = typeof self.params.prompt === "string"
3805
+ ? self.params.prompt
3806
+ : await self.params.prompt(self.params.clientId, self.params.agentName);
3807
+ const messages = await self.params.history.toArrayForAgent(prompt, await self._resolveSystemPrompt());
3805
3808
  messages.push({
3806
3809
  agentName: self.params.agentName,
3807
3810
  content: incoming,
@@ -4337,7 +4340,10 @@ class ClientAgent {
4337
4340
  async getCompletion(mode, tools) {
4338
4341
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4339
4342
  this.params.logger.debug(`ClientAgent agentName=${this.params.agentName} clientId=${this.params.clientId} getCompletion`);
4340
- const messages = await this.params.history.toArrayForAgent(this.params.prompt ?? "", await this._resolveSystemPrompt());
4343
+ const prompt = typeof this.params.prompt === "string"
4344
+ ? this.params.prompt
4345
+ : await this.params.prompt(this.params.clientId, this.params.agentName);
4346
+ const messages = await this.params.history.toArrayForAgent(prompt, await this._resolveSystemPrompt());
4341
4347
  const args = {
4342
4348
  clientId: this.params.clientId,
4343
4349
  agentName: this.params.agentName,
@@ -4381,7 +4387,10 @@ class ClientAgent {
4381
4387
  agentName: this.params.agentName,
4382
4388
  content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
4383
4389
  });
4384
- const messages = await this.params.history.toArrayForAgent(this.params.prompt ?? "", await this._resolveSystemPrompt());
4390
+ const prompt = typeof this.params.prompt === "string"
4391
+ ? this.params.prompt
4392
+ : await this.params.prompt(this.params.clientId, this.params.agentName);
4393
+ const messages = await this.params.history.toArrayForAgent(prompt, await this._resolveSystemPrompt());
4385
4394
  const args = {
4386
4395
  clientId: this.params.clientId,
4387
4396
  agentName: this.params.agentName,
@@ -6169,7 +6178,7 @@ class ToolSchemaService {
6169
6178
  if (toolSchema.validate && typeof toolSchema.validate !== "function") {
6170
6179
  throw new Error(`agent-swarm tool schema validation failed: missing validate for toolName=${toolSchema.toolName}`);
6171
6180
  }
6172
- if (!functoolsKit.isObject(toolSchema.function)) {
6181
+ if (!functoolsKit.isObject(toolSchema.function) && typeof toolSchema.function !== "function") {
6173
6182
  throw new Error(`agent-swarm tool schema validation failed: missing function for toolName=${toolSchema.toolName}`);
6174
6183
  }
6175
6184
  };
@@ -13325,7 +13334,7 @@ class DocService {
13325
13334
  result.push("");
13326
13335
  }
13327
13336
  }
13328
- if (agentSchema.prompt) {
13337
+ if (typeof agentSchema.prompt === "string") {
13329
13338
  result.push(`## Main prompt`);
13330
13339
  result.push("");
13331
13340
  result.push("```");
@@ -21575,7 +21584,10 @@ const getAgentHistoryInternal = beginContext(async (clientId, agentName) => {
21575
21584
  swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$b);
21576
21585
  swarm$1.agentValidationService.validate(agentName, METHOD_NAME$b);
21577
21586
  // Retrieve the agent's prompt configuration from the agent schema service
21578
- const { prompt } = swarm$1.agentSchemaService.get(agentName);
21587
+ const { prompt: upperPrompt } = swarm$1.agentSchemaService.get(agentName);
21588
+ const prompt = typeof upperPrompt === "string"
21589
+ ? upperPrompt
21590
+ : await upperPrompt(clientId, agentName);
21579
21591
  // Fetch the agent's history using the prompt and rescue tweaks via the history public service
21580
21592
  const history = await swarm$1.historyPublicService.toArrayForAgent(prompt, METHOD_NAME$b, clientId, agentName);
21581
21593
  // Return a shallow copy of the history array
@@ -23181,11 +23193,12 @@ const ChatInstance = functoolsKit.makeExtendable(class {
23181
23193
  * @param {Partial<IChatInstanceCallbacks>} callbacks - Event callbacks
23182
23194
  * @param {DisposeFn} onDispose - Dispose callback function
23183
23195
  */
23184
- constructor(clientId, swarmName, onDispose, callbacks) {
23196
+ constructor(clientId, swarmName, onDispose, callbacks, payload) {
23185
23197
  this.clientId = clientId;
23186
23198
  this.swarmName = swarmName;
23187
23199
  this.onDispose = onDispose;
23188
23200
  this.callbacks = callbacks;
23201
+ this.payload = payload;
23189
23202
  /** @private */
23190
23203
  this._disposeSubject = new functoolsKit.Subject();
23191
23204
  /** @private */
@@ -23302,7 +23315,7 @@ class ChatUtils {
23302
23315
  * @param {SwarmName} swarmName - Name of the swarm
23303
23316
  * @returns {IChatInstance} The chat instance for the given client
23304
23317
  */
23305
- this.getChatInstance = (clientId, swarmName) => {
23318
+ this.getChatInstance = (clientId, swarmName, payload = {}) => {
23306
23319
  return this._chats.has(clientId)
23307
23320
  ? this._chats.get(clientId)
23308
23321
  : this._chats
@@ -23311,6 +23324,7 @@ class ChatUtils {
23311
23324
  swarmName,
23312
23325
  () => this._chats.delete(clientId),
23313
23326
  this.ChatInstanceCallbacks,
23327
+ payload,
23314
23328
  ]))
23315
23329
  .get(clientId);
23316
23330
  };
@@ -23320,14 +23334,14 @@ class ChatUtils {
23320
23334
  * @param {SwarmName} swarmName - Name of the swarm
23321
23335
  * @returns {Promise<void>}
23322
23336
  */
23323
- this.beginChat = async (clientId, swarmName) => {
23337
+ this.beginChat = async (clientId, swarmName, payload = {}) => {
23324
23338
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
23325
23339
  swarm$1.loggerService.log("ChatUtils.beginChat", {
23326
23340
  clientId,
23327
23341
  swarmName,
23328
23342
  });
23329
23343
  this.initializeCleanup();
23330
- return await this.getChatInstance(clientId, swarmName).beginChat();
23344
+ return await this.getChatInstance(clientId, swarmName, payload).beginChat();
23331
23345
  };
23332
23346
  /**
23333
23347
  * Sends a message for a client
package/build/index.mjs CHANGED
@@ -3423,7 +3423,7 @@ class AgentSchemaService {
3423
3423
  if (!agentSchema.operator && typeof agentSchema.completion !== "string") {
3424
3424
  throw new Error(`agent-swarm agent schema validation failed: missing completion for agentName=${agentSchema.agentName}`);
3425
3425
  }
3426
- if (!agentSchema.operator && typeof agentSchema.prompt !== "string") {
3426
+ if (!agentSchema.operator && agentSchema.prompt === undefined) {
3427
3427
  throw new Error(`agent-swarm agent schema validation failed: missing prompt for agentName=${agentSchema.agentName}`);
3428
3428
  }
3429
3429
  if (agentSchema.system && !Array.isArray(agentSchema.system)) {
@@ -3799,7 +3799,10 @@ const RUN_FN = async (incoming, self) => {
3799
3799
  self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} run begin`, { incoming });
3800
3800
  self.params.onRun &&
3801
3801
  self.params.onRun(self.params.clientId, self.params.agentName, incoming);
3802
- const messages = await self.params.history.toArrayForAgent(self.params.prompt ?? "", await self._resolveSystemPrompt());
3802
+ const prompt = typeof self.params.prompt === "string"
3803
+ ? self.params.prompt
3804
+ : await self.params.prompt(self.params.clientId, self.params.agentName);
3805
+ const messages = await self.params.history.toArrayForAgent(prompt, await self._resolveSystemPrompt());
3803
3806
  messages.push({
3804
3807
  agentName: self.params.agentName,
3805
3808
  content: incoming,
@@ -4335,7 +4338,10 @@ class ClientAgent {
4335
4338
  async getCompletion(mode, tools) {
4336
4339
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4337
4340
  this.params.logger.debug(`ClientAgent agentName=${this.params.agentName} clientId=${this.params.clientId} getCompletion`);
4338
- const messages = await this.params.history.toArrayForAgent(this.params.prompt ?? "", await this._resolveSystemPrompt());
4341
+ const prompt = typeof this.params.prompt === "string"
4342
+ ? this.params.prompt
4343
+ : await this.params.prompt(this.params.clientId, this.params.agentName);
4344
+ const messages = await this.params.history.toArrayForAgent(prompt, await this._resolveSystemPrompt());
4339
4345
  const args = {
4340
4346
  clientId: this.params.clientId,
4341
4347
  agentName: this.params.agentName,
@@ -4379,7 +4385,10 @@ class ClientAgent {
4379
4385
  agentName: this.params.agentName,
4380
4386
  content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
4381
4387
  });
4382
- const messages = await this.params.history.toArrayForAgent(this.params.prompt ?? "", await this._resolveSystemPrompt());
4388
+ const prompt = typeof this.params.prompt === "string"
4389
+ ? this.params.prompt
4390
+ : await this.params.prompt(this.params.clientId, this.params.agentName);
4391
+ const messages = await this.params.history.toArrayForAgent(prompt, await this._resolveSystemPrompt());
4383
4392
  const args = {
4384
4393
  clientId: this.params.clientId,
4385
4394
  agentName: this.params.agentName,
@@ -6167,7 +6176,7 @@ class ToolSchemaService {
6167
6176
  if (toolSchema.validate && typeof toolSchema.validate !== "function") {
6168
6177
  throw new Error(`agent-swarm tool schema validation failed: missing validate for toolName=${toolSchema.toolName}`);
6169
6178
  }
6170
- if (!isObject$1(toolSchema.function)) {
6179
+ if (!isObject$1(toolSchema.function) && typeof toolSchema.function !== "function") {
6171
6180
  throw new Error(`agent-swarm tool schema validation failed: missing function for toolName=${toolSchema.toolName}`);
6172
6181
  }
6173
6182
  };
@@ -13323,7 +13332,7 @@ class DocService {
13323
13332
  result.push("");
13324
13333
  }
13325
13334
  }
13326
- if (agentSchema.prompt) {
13335
+ if (typeof agentSchema.prompt === "string") {
13327
13336
  result.push(`## Main prompt`);
13328
13337
  result.push("");
13329
13338
  result.push("```");
@@ -21573,7 +21582,10 @@ const getAgentHistoryInternal = beginContext(async (clientId, agentName) => {
21573
21582
  swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$b);
21574
21583
  swarm$1.agentValidationService.validate(agentName, METHOD_NAME$b);
21575
21584
  // Retrieve the agent's prompt configuration from the agent schema service
21576
- const { prompt } = swarm$1.agentSchemaService.get(agentName);
21585
+ const { prompt: upperPrompt } = swarm$1.agentSchemaService.get(agentName);
21586
+ const prompt = typeof upperPrompt === "string"
21587
+ ? upperPrompt
21588
+ : await upperPrompt(clientId, agentName);
21577
21589
  // Fetch the agent's history using the prompt and rescue tweaks via the history public service
21578
21590
  const history = await swarm$1.historyPublicService.toArrayForAgent(prompt, METHOD_NAME$b, clientId, agentName);
21579
21591
  // Return a shallow copy of the history array
@@ -23179,11 +23191,12 @@ const ChatInstance = makeExtendable(class {
23179
23191
  * @param {Partial<IChatInstanceCallbacks>} callbacks - Event callbacks
23180
23192
  * @param {DisposeFn} onDispose - Dispose callback function
23181
23193
  */
23182
- constructor(clientId, swarmName, onDispose, callbacks) {
23194
+ constructor(clientId, swarmName, onDispose, callbacks, payload) {
23183
23195
  this.clientId = clientId;
23184
23196
  this.swarmName = swarmName;
23185
23197
  this.onDispose = onDispose;
23186
23198
  this.callbacks = callbacks;
23199
+ this.payload = payload;
23187
23200
  /** @private */
23188
23201
  this._disposeSubject = new Subject();
23189
23202
  /** @private */
@@ -23300,7 +23313,7 @@ class ChatUtils {
23300
23313
  * @param {SwarmName} swarmName - Name of the swarm
23301
23314
  * @returns {IChatInstance} The chat instance for the given client
23302
23315
  */
23303
- this.getChatInstance = (clientId, swarmName) => {
23316
+ this.getChatInstance = (clientId, swarmName, payload = {}) => {
23304
23317
  return this._chats.has(clientId)
23305
23318
  ? this._chats.get(clientId)
23306
23319
  : this._chats
@@ -23309,6 +23322,7 @@ class ChatUtils {
23309
23322
  swarmName,
23310
23323
  () => this._chats.delete(clientId),
23311
23324
  this.ChatInstanceCallbacks,
23325
+ payload,
23312
23326
  ]))
23313
23327
  .get(clientId);
23314
23328
  };
@@ -23318,14 +23332,14 @@ class ChatUtils {
23318
23332
  * @param {SwarmName} swarmName - Name of the swarm
23319
23333
  * @returns {Promise<void>}
23320
23334
  */
23321
- this.beginChat = async (clientId, swarmName) => {
23335
+ this.beginChat = async (clientId, swarmName, payload = {}) => {
23322
23336
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
23323
23337
  swarm$1.loggerService.log("ChatUtils.beginChat", {
23324
23338
  clientId,
23325
23339
  swarmName,
23326
23340
  });
23327
23341
  this.initializeCleanup();
23328
- return await this.getChatInstance(clientId, swarmName).beginChat();
23342
+ return await this.getChatInstance(clientId, swarmName, payload).beginChat();
23329
23343
  };
23330
23344
  /**
23331
23345
  * Sends a message for a client
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.1.64",
3
+ "version": "1.1.66",
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
@@ -3572,7 +3572,7 @@ interface IAgentSchemaInternal {
3572
3572
  /** The name of the completion mechanism used by the agent. REQUIRED WHEN AGENT IS NOT OPERATOR */
3573
3573
  completion?: CompletionName;
3574
3574
  /** The primary prompt guiding the agent's behavior. REQUIRED WHEN AGENT IS NOT OPERATOR */
3575
- prompt?: string;
3575
+ prompt?: string | ((clientId: string, agentName: AgentName) => (Promise<string> | string));
3576
3576
  /** Optional array of system prompts, typically used for tool-calling protocols. */
3577
3577
  system?: string[];
3578
3578
  /** Optional array of system prompts, alias for `system` */
@@ -14323,14 +14323,14 @@ interface IChatControl {
14323
14323
  /**
14324
14324
  * @typedef {new (clientId: SessionId, swarmName: SwarmName, callbacks: IChatInstanceCallbacks, onDispose: DisposeFn) => IChatInstance} TChatInstanceCtor
14325
14325
  */
14326
- type TChatInstanceCtor = new (clientId: SessionId, swarmName: SwarmName, onDispose: DisposeFn, callbacks: IChatInstanceCallbacks) => IChatInstance;
14326
+ type TChatInstanceCtor = new <Payload extends any = any>(clientId: SessionId, swarmName: SwarmName, onDispose: DisposeFn, callbacks: IChatInstanceCallbacks, payload: Payload) => IChatInstance;
14327
14327
  /**
14328
14328
  * @class ChatInstance
14329
14329
  * @implements {IChatInstance}
14330
14330
  * @description Implementation of a single chat instance
14331
14331
  */
14332
14332
  declare const ChatInstance: {
14333
- new (clientId: SessionId, swarmName: SwarmName, onDispose: DisposeFn, callbacks: Partial<IChatInstanceCallbacks>): {
14333
+ new <Payload extends unknown = any>(clientId: SessionId, swarmName: SwarmName, onDispose: DisposeFn, callbacks: Partial<IChatInstanceCallbacks>, payload: Payload): {
14334
14334
  /** @private */
14335
14335
  _disposeSubject: Subject<string>;
14336
14336
  /** @private */
@@ -14341,6 +14341,7 @@ declare const ChatInstance: {
14341
14341
  readonly swarmName: SwarmName;
14342
14342
  readonly onDispose: DisposeFn;
14343
14343
  readonly callbacks: Partial<IChatInstanceCallbacks>;
14344
+ readonly payload: Payload;
14344
14345
  /**
14345
14346
  * Checks if the chat has been active within the timeout period
14346
14347
  * @param {number} now - Current timestamp
@@ -14408,7 +14409,7 @@ declare class ChatUtils implements IChatControl {
14408
14409
  * @param {SwarmName} swarmName - Name of the swarm
14409
14410
  * @returns {Promise<void>}
14410
14411
  */
14411
- beginChat: (clientId: SessionId, swarmName: SwarmName) => Promise<void>;
14412
+ beginChat: <Payload extends unknown = any>(clientId: SessionId, swarmName: SwarmName, payload?: Payload) => Promise<void>;
14412
14413
  /**
14413
14414
  * Sends a message for a client
14414
14415
  * @param {SessionId} clientId - Unique client identifier