agent-swarm-kit 1.0.231 → 1.0.233

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
@@ -22,7 +22,11 @@ Unleash the power of collaborative AI with `agent-swarm-kit`! This library empow
22
22
 
23
23
  ## 🚀 Getting Started
24
24
 
25
- **Want a real-world demo?** Check out our **[Binance Candle Chat](https://github.com/tripolskypetr/agent-swarm-kit/blob/master/demo/binance-candle-chat/src/lib/swarm.ts)**—a practical example of a sales agent in action!
25
+ > **Want a real-world demo?** Check out our **[Binance Candle Chat](https://github.com/tripolskypetr/agent-swarm-kit/blob/master/demo/binance-candle-chat/src/lib/swarm.ts)**—a practical example of a sales agent in action!
26
+
27
+ ### First Look
28
+
29
+ Read the [briefing article by the link](https://agent-swarm.github.io/documents/app_getting-started.html)
26
30
 
27
31
  ### Installation
28
32
 
package/build/index.cjs CHANGED
@@ -3339,7 +3339,7 @@ const RUN_FN = async (incoming, self) => {
3339
3339
  self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} run begin`, { incoming });
3340
3340
  self.params.onRun &&
3341
3341
  self.params.onRun(self.params.clientId, self.params.agentName, incoming);
3342
- const messages = await self.params.history.toArrayForAgent(self.params.prompt, self.params.system);
3342
+ const messages = await self.params.history.toArrayForAgent(self.params.prompt, await self._resolveSystemPrompt());
3343
3343
  messages.push({
3344
3344
  agentName: self.params.agentName,
3345
3345
  content: incoming,
@@ -3634,6 +3634,29 @@ class ClientAgent {
3634
3634
  });
3635
3635
  this.params.onInit && this.params.onInit(params.clientId, params.agentName);
3636
3636
  }
3637
+ /**
3638
+ * Resolves the system prompt by combining static and dynamic system messages.
3639
+ * Static messages are directly included from the `systemStatic` parameter, while dynamic messages
3640
+ * are fetched asynchronously using the `systemDynamic` function.
3641
+ *
3642
+ * This method is used to construct the system-level context for the agent, which can include
3643
+ * predefined static messages and dynamically generated messages based on the agent's state or configuration.
3644
+ *
3645
+ * @returns {Promise<string[]>} A promise that resolves to an array of system messages,
3646
+ * including both static and dynamically generated messages.
3647
+ */
3648
+ async _resolveSystemPrompt() {
3649
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
3650
+ this.params.logger.debug(`ClientAgent agentName=${this.params.agentName} clientId=${this.params.clientId} _resolveSystemPrompt`);
3651
+ const system = [];
3652
+ if (this.params.systemStatic) {
3653
+ system.push(...this.params.systemStatic);
3654
+ }
3655
+ if (this.params.systemDynamic) {
3656
+ system.push(...(await this.params.systemDynamic(this.params.clientId, this.params.agentName)));
3657
+ }
3658
+ return system;
3659
+ }
3637
3660
  /**
3638
3661
  * Emits the transformed output after validation, invoking callbacks and emitting events via BusService.
3639
3662
  * Attempts model resurrection via _resurrectModel if validation fails, throwing an error if unrecoverable.
@@ -3793,7 +3816,7 @@ class ClientAgent {
3793
3816
  async getCompletion(mode) {
3794
3817
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
3795
3818
  this.params.logger.debug(`ClientAgent agentName=${this.params.agentName} clientId=${this.params.clientId} getCompletion`);
3796
- const messages = await this.params.history.toArrayForAgent(this.params.prompt, this.params.system);
3819
+ const messages = await this.params.history.toArrayForAgent(this.params.prompt, await this._resolveSystemPrompt());
3797
3820
  const args = {
3798
3821
  clientId: this.params.clientId,
3799
3822
  agentName: this.params.agentName,
@@ -3837,7 +3860,7 @@ class ClientAgent {
3837
3860
  agentName: this.params.agentName,
3838
3861
  content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
3839
3862
  });
3840
- const messages = await this.params.history.toArrayForAgent(this.params.prompt, this.params.system);
3863
+ const messages = await this.params.history.toArrayForAgent(this.params.prompt, await this._resolveSystemPrompt());
3841
3864
  const args = {
3842
3865
  clientId: this.params.clientId,
3843
3866
  agentName: this.params.agentName,
@@ -4175,7 +4198,7 @@ class AgentConnectionService {
4175
4198
  * @returns {ClientAgent} The memoized ClientAgent instance configured for the client and agent.
4176
4199
  */
4177
4200
  this.getAgent = functoolsKit.memoize(([clientId, agentName]) => `${clientId}-${agentName}`, (clientId, agentName) => {
4178
- const { prompt, system, tools, transform = GLOBAL_CONFIG.CC_AGENT_OUTPUT_TRANSFORM, map = GLOBAL_CONFIG.CC_AGENT_OUTPUT_MAP, maxToolCalls = GLOBAL_CONFIG.CC_MAX_TOOL_CALLS, mapToolCalls = GLOBAL_CONFIG.CC_AGENT_MAP_TOOLS, callbacks, storages, states, completion: completionName, validate = validateDefault, } = this.agentSchemaService.get(agentName);
4201
+ const { prompt, system, systemStatic = system, systemDynamic, tools, transform = GLOBAL_CONFIG.CC_AGENT_OUTPUT_TRANSFORM, map = GLOBAL_CONFIG.CC_AGENT_OUTPUT_MAP, maxToolCalls = GLOBAL_CONFIG.CC_MAX_TOOL_CALLS, mapToolCalls = GLOBAL_CONFIG.CC_AGENT_MAP_TOOLS, callbacks, storages, states, completion: completionName, validate = validateDefault, } = this.agentSchemaService.get(agentName);
4179
4202
  const completion = this.completionSchemaService.get(completionName);
4180
4203
  this.sessionValidationService.addAgentUsage(clientId, agentName);
4181
4204
  storages?.forEach((storageName) => this.storageConnectionService
@@ -4194,7 +4217,8 @@ class AgentConnectionService {
4194
4217
  bus: this.busService,
4195
4218
  history: this.historyConnectionService.getHistory(clientId, agentName),
4196
4219
  prompt,
4197
- system,
4220
+ systemStatic,
4221
+ systemDynamic,
4198
4222
  transform,
4199
4223
  map,
4200
4224
  tools: tools?.map(this.toolSchemaService.get),
package/build/index.mjs CHANGED
@@ -3337,7 +3337,7 @@ const RUN_FN = async (incoming, self) => {
3337
3337
  self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} run begin`, { incoming });
3338
3338
  self.params.onRun &&
3339
3339
  self.params.onRun(self.params.clientId, self.params.agentName, incoming);
3340
- const messages = await self.params.history.toArrayForAgent(self.params.prompt, self.params.system);
3340
+ const messages = await self.params.history.toArrayForAgent(self.params.prompt, await self._resolveSystemPrompt());
3341
3341
  messages.push({
3342
3342
  agentName: self.params.agentName,
3343
3343
  content: incoming,
@@ -3632,6 +3632,29 @@ class ClientAgent {
3632
3632
  });
3633
3633
  this.params.onInit && this.params.onInit(params.clientId, params.agentName);
3634
3634
  }
3635
+ /**
3636
+ * Resolves the system prompt by combining static and dynamic system messages.
3637
+ * Static messages are directly included from the `systemStatic` parameter, while dynamic messages
3638
+ * are fetched asynchronously using the `systemDynamic` function.
3639
+ *
3640
+ * This method is used to construct the system-level context for the agent, which can include
3641
+ * predefined static messages and dynamically generated messages based on the agent's state or configuration.
3642
+ *
3643
+ * @returns {Promise<string[]>} A promise that resolves to an array of system messages,
3644
+ * including both static and dynamically generated messages.
3645
+ */
3646
+ async _resolveSystemPrompt() {
3647
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
3648
+ this.params.logger.debug(`ClientAgent agentName=${this.params.agentName} clientId=${this.params.clientId} _resolveSystemPrompt`);
3649
+ const system = [];
3650
+ if (this.params.systemStatic) {
3651
+ system.push(...this.params.systemStatic);
3652
+ }
3653
+ if (this.params.systemDynamic) {
3654
+ system.push(...(await this.params.systemDynamic(this.params.clientId, this.params.agentName)));
3655
+ }
3656
+ return system;
3657
+ }
3635
3658
  /**
3636
3659
  * Emits the transformed output after validation, invoking callbacks and emitting events via BusService.
3637
3660
  * Attempts model resurrection via _resurrectModel if validation fails, throwing an error if unrecoverable.
@@ -3791,7 +3814,7 @@ class ClientAgent {
3791
3814
  async getCompletion(mode) {
3792
3815
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
3793
3816
  this.params.logger.debug(`ClientAgent agentName=${this.params.agentName} clientId=${this.params.clientId} getCompletion`);
3794
- const messages = await this.params.history.toArrayForAgent(this.params.prompt, this.params.system);
3817
+ const messages = await this.params.history.toArrayForAgent(this.params.prompt, await this._resolveSystemPrompt());
3795
3818
  const args = {
3796
3819
  clientId: this.params.clientId,
3797
3820
  agentName: this.params.agentName,
@@ -3835,7 +3858,7 @@ class ClientAgent {
3835
3858
  agentName: this.params.agentName,
3836
3859
  content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
3837
3860
  });
3838
- const messages = await this.params.history.toArrayForAgent(this.params.prompt, this.params.system);
3861
+ const messages = await this.params.history.toArrayForAgent(this.params.prompt, await this._resolveSystemPrompt());
3839
3862
  const args = {
3840
3863
  clientId: this.params.clientId,
3841
3864
  agentName: this.params.agentName,
@@ -4173,7 +4196,7 @@ class AgentConnectionService {
4173
4196
  * @returns {ClientAgent} The memoized ClientAgent instance configured for the client and agent.
4174
4197
  */
4175
4198
  this.getAgent = memoize(([clientId, agentName]) => `${clientId}-${agentName}`, (clientId, agentName) => {
4176
- const { prompt, system, tools, transform = GLOBAL_CONFIG.CC_AGENT_OUTPUT_TRANSFORM, map = GLOBAL_CONFIG.CC_AGENT_OUTPUT_MAP, maxToolCalls = GLOBAL_CONFIG.CC_MAX_TOOL_CALLS, mapToolCalls = GLOBAL_CONFIG.CC_AGENT_MAP_TOOLS, callbacks, storages, states, completion: completionName, validate = validateDefault, } = this.agentSchemaService.get(agentName);
4199
+ const { prompt, system, systemStatic = system, systemDynamic, tools, transform = GLOBAL_CONFIG.CC_AGENT_OUTPUT_TRANSFORM, map = GLOBAL_CONFIG.CC_AGENT_OUTPUT_MAP, maxToolCalls = GLOBAL_CONFIG.CC_MAX_TOOL_CALLS, mapToolCalls = GLOBAL_CONFIG.CC_AGENT_MAP_TOOLS, callbacks, storages, states, completion: completionName, validate = validateDefault, } = this.agentSchemaService.get(agentName);
4177
4200
  const completion = this.completionSchemaService.get(completionName);
4178
4201
  this.sessionValidationService.addAgentUsage(clientId, agentName);
4179
4202
  storages?.forEach((storageName) => this.storageConnectionService
@@ -4192,7 +4215,8 @@ class AgentConnectionService {
4192
4215
  bus: this.busService,
4193
4216
  history: this.historyConnectionService.getHistory(clientId, agentName),
4194
4217
  prompt,
4195
- system,
4218
+ systemStatic,
4219
+ systemDynamic,
4196
4220
  transform,
4197
4221
  map,
4198
4222
  tools: tools?.map(this.toolSchemaService.get),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.231",
3
+ "version": "1.0.233",
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
@@ -3014,6 +3014,7 @@ interface IAgentTool<T = Record<string, ToolValue>> extends ITool {
3014
3014
  * @extends {IAgentSchemaCallbacks}
3015
3015
  */
3016
3016
  interface IAgentParams extends Omit<IAgentSchema, keyof {
3017
+ system: never;
3017
3018
  tools: never;
3018
3019
  completion: never;
3019
3020
  validate: never;
@@ -3153,6 +3154,10 @@ interface IAgentSchema {
3153
3154
  prompt: string;
3154
3155
  /** Optional array of system prompts, typically used for tool-calling protocols. */
3155
3156
  system?: string[];
3157
+ /** Optional array of system prompts, alias for `system` */
3158
+ systemStatic?: string[];
3159
+ /** Optional dynamic array of system prompts from the callback */
3160
+ systemDynamic?: (clientId: string, agentName: AgentName) => (Promise<string[]> | string[]);
3156
3161
  /** Optional array of tool names available to the agent. */
3157
3162
  tools?: ToolName[];
3158
3163
  /** Optional array of storage names utilized by the agent. */
@@ -3573,6 +3578,18 @@ declare class ClientAgent implements IAgent {
3573
3578
  * @param {IAgentParams} params - The parameters for agent initialization, including clientId, agentName, completion, tools, etc.
3574
3579
  */
3575
3580
  constructor(params: IAgentParams);
3581
+ /**
3582
+ * Resolves the system prompt by combining static and dynamic system messages.
3583
+ * Static messages are directly included from the `systemStatic` parameter, while dynamic messages
3584
+ * are fetched asynchronously using the `systemDynamic` function.
3585
+ *
3586
+ * This method is used to construct the system-level context for the agent, which can include
3587
+ * predefined static messages and dynamically generated messages based on the agent's state or configuration.
3588
+ *
3589
+ * @returns {Promise<string[]>} A promise that resolves to an array of system messages,
3590
+ * including both static and dynamically generated messages.
3591
+ */
3592
+ _resolveSystemPrompt(): Promise<string[]>;
3576
3593
  /**
3577
3594
  * Emits the transformed output after validation, invoking callbacks and emitting events via BusService.
3578
3595
  * Attempts model resurrection via _resurrectModel if validation fails, throwing an error if unrecoverable.