agent-swarm-kit 1.0.241 → 1.1.0
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 +190 -6
- package/build/index.mjs +190 -6
- package/package.json +1 -1
- package/types.d.ts +12 -4
package/build/index.cjs
CHANGED
|
@@ -5249,6 +5249,159 @@ class ToolSchemaService {
|
|
|
5249
5249
|
|
|
5250
5250
|
const AGENT_NEED_FETCH = Symbol("agent-need-fetch");
|
|
5251
5251
|
const STACK_NEED_FETCH = Symbol("stack-need-fetch");
|
|
5252
|
+
/**
|
|
5253
|
+
* A no-operation (noop) agent that serves as a fallback when an agent is not found in the swarm.
|
|
5254
|
+
* Implements the {@link IAgent} interface and logs calls to its methods, indicating that the requested agent is unavailable,
|
|
5255
|
+
* before delegating execution to a provided default agent. Used within the swarm system to handle invalid or missing agent references gracefully.
|
|
5256
|
+
* @implements {IAgent}
|
|
5257
|
+
*/
|
|
5258
|
+
class NoopAgent {
|
|
5259
|
+
/**
|
|
5260
|
+
* Creates a new NoopAgent instance.
|
|
5261
|
+
* @param {string} clientId - The unique identifier of the client associated with the swarm.
|
|
5262
|
+
* @param {SwarmName} swarmName - The name of the swarm this agent is associated with.
|
|
5263
|
+
* @param {AgentName} agentName - The name of the agent that was not found, used for logging.
|
|
5264
|
+
* @param {IAgent} defaultAgent - The default agent to delegate method calls to.
|
|
5265
|
+
* @param {ILogger} logger - The logger instance for recording method calls and errors.
|
|
5266
|
+
*/
|
|
5267
|
+
constructor(clientId, swarmName, agentName, defaultAgent, logger) {
|
|
5268
|
+
this.clientId = clientId;
|
|
5269
|
+
this.swarmName = swarmName;
|
|
5270
|
+
this.agentName = agentName;
|
|
5271
|
+
this.defaultAgent = defaultAgent;
|
|
5272
|
+
this.logger = logger;
|
|
5273
|
+
}
|
|
5274
|
+
/**
|
|
5275
|
+
* Logs an attempt to run the missing agent and delegates to the default agent's run method.
|
|
5276
|
+
* @param {string} input - The input string to process.
|
|
5277
|
+
* @returns {Promise<unknown>} The result from the default agent's run method.
|
|
5278
|
+
* @async
|
|
5279
|
+
*/
|
|
5280
|
+
async run(input) {
|
|
5281
|
+
const message = `called run on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5282
|
+
const context = {
|
|
5283
|
+
input,
|
|
5284
|
+
};
|
|
5285
|
+
this.logger.log(message, context);
|
|
5286
|
+
console.error(message, context);
|
|
5287
|
+
return await this.defaultAgent.run(input);
|
|
5288
|
+
}
|
|
5289
|
+
/**
|
|
5290
|
+
* Logs an attempt to execute the missing agent and delegates to the default agent's execute method.
|
|
5291
|
+
* @param {string} input - The input string to process.
|
|
5292
|
+
* @param {ExecutionMode} mode - The execution mode (e.g., synchronous or asynchronous).
|
|
5293
|
+
* @returns {Promise<unknown>} The result from the default agent's execute method.
|
|
5294
|
+
* @async
|
|
5295
|
+
*/
|
|
5296
|
+
async execute(input, mode) {
|
|
5297
|
+
const message = `called execute on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5298
|
+
const context = {
|
|
5299
|
+
input,
|
|
5300
|
+
mode,
|
|
5301
|
+
};
|
|
5302
|
+
this.logger.log(message, context);
|
|
5303
|
+
console.error(message, context);
|
|
5304
|
+
return await this.defaultAgent.execute(input, mode);
|
|
5305
|
+
}
|
|
5306
|
+
/**
|
|
5307
|
+
* Logs an attempt to wait for output from the missing agent and delegates to the default agent's waitForOutput method.
|
|
5308
|
+
* @returns {Promise<string>} The output from the default agent's waitForOutput method.
|
|
5309
|
+
* @async
|
|
5310
|
+
*/
|
|
5311
|
+
async waitForOutput() {
|
|
5312
|
+
const message = `called waitForOutput on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5313
|
+
this.logger.log(message);
|
|
5314
|
+
console.error(message);
|
|
5315
|
+
return await this.defaultAgent.waitForOutput();
|
|
5316
|
+
}
|
|
5317
|
+
/**
|
|
5318
|
+
* Logs an attempt to commit tool output for the missing agent and delegates to the default agent's commitToolOutput method.
|
|
5319
|
+
* @param {string} toolId - The identifier of the tool whose output is being committed.
|
|
5320
|
+
* @param {string} content - The content to commit as tool output.
|
|
5321
|
+
* @returns {Promise<void>} Resolves when the default agent's commitToolOutput method completes.
|
|
5322
|
+
* @async
|
|
5323
|
+
*/
|
|
5324
|
+
async commitToolOutput(toolId, content) {
|
|
5325
|
+
const message = `called commitToolOutput on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5326
|
+
const context = { toolId, content };
|
|
5327
|
+
this.logger.log(message, context);
|
|
5328
|
+
console.error(message, context);
|
|
5329
|
+
return await this.defaultAgent.commitToolOutput(toolId, content);
|
|
5330
|
+
}
|
|
5331
|
+
/**
|
|
5332
|
+
* Logs an attempt to commit a system message for the missing agent and delegates to the default agent's commitSystemMessage method.
|
|
5333
|
+
* @param {string} content - The system message content to commit.
|
|
5334
|
+
* @returns {Promise<void>} Resolves when the default agent's commitSystemMessage method completes.
|
|
5335
|
+
* @async
|
|
5336
|
+
*/
|
|
5337
|
+
async commitSystemMessage(content) {
|
|
5338
|
+
const message = `called commitToolOutput on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5339
|
+
const context = { content };
|
|
5340
|
+
this.logger.log(message, context);
|
|
5341
|
+
console.error(message, context);
|
|
5342
|
+
return await this.defaultAgent.commitSystemMessage(content);
|
|
5343
|
+
}
|
|
5344
|
+
/**
|
|
5345
|
+
* Logs an attempt to commit a user message for the missing agent and delegates to the default agent's commitUserMessage method.
|
|
5346
|
+
* @param {string} content - The user message content to commit.
|
|
5347
|
+
* @param {ExecutionMode} mode - The execution mode for the message.
|
|
5348
|
+
* @returns {Promise<void>} Resolves when the default agent's commitUserMessage method completes.
|
|
5349
|
+
* @async
|
|
5350
|
+
*/
|
|
5351
|
+
async commitUserMessage(content, mode) {
|
|
5352
|
+
const message = `called commitUserMessage on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5353
|
+
const context = { content, mode };
|
|
5354
|
+
this.logger.log(message, context);
|
|
5355
|
+
console.error(message, context);
|
|
5356
|
+
return await this.defaultAgent.commitUserMessage(content, mode);
|
|
5357
|
+
}
|
|
5358
|
+
/**
|
|
5359
|
+
* Logs an attempt to commit an assistant message for the missing agent and delegates to the default agent's commitAssistantMessage method.
|
|
5360
|
+
* @param {string} content - The assistant message content to commit.
|
|
5361
|
+
* @returns {Promise<void>} Resolves when the default agent's commitAssistantMessage method completes.
|
|
5362
|
+
* @async
|
|
5363
|
+
*/
|
|
5364
|
+
async commitAssistantMessage(content) {
|
|
5365
|
+
const message = `called commitAssistantMessage on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5366
|
+
const context = { content };
|
|
5367
|
+
this.logger.log(message, context);
|
|
5368
|
+
console.error(message, context);
|
|
5369
|
+
return await this.defaultAgent.commitAssistantMessage(content);
|
|
5370
|
+
}
|
|
5371
|
+
/**
|
|
5372
|
+
* Logs an attempt to commit a flush operation for the missing agent and delegates to the default agent's commitFlush method.
|
|
5373
|
+
* @returns {Promise<void>} Resolves when the default agent's commitFlush method completes.
|
|
5374
|
+
* @async
|
|
5375
|
+
*/
|
|
5376
|
+
async commitFlush() {
|
|
5377
|
+
const message = `called commitAssistantMessage on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5378
|
+
this.logger.log(message);
|
|
5379
|
+
console.error(message);
|
|
5380
|
+
return await this.defaultAgent.commitFlush();
|
|
5381
|
+
}
|
|
5382
|
+
/**
|
|
5383
|
+
* Logs an attempt to stop tools for the missing agent and delegates to the default agent's commitStopTools method.
|
|
5384
|
+
* @returns {Promise<void>} Resolves when the default agent's commitStopTools method completes.
|
|
5385
|
+
* @async
|
|
5386
|
+
*/
|
|
5387
|
+
async commitStopTools() {
|
|
5388
|
+
const message = `called commitStopTools on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5389
|
+
this.logger.log(message);
|
|
5390
|
+
console.error(message);
|
|
5391
|
+
return await this.defaultAgent.commitStopTools();
|
|
5392
|
+
}
|
|
5393
|
+
/**
|
|
5394
|
+
* Logs an attempt to commit an agent change for the missing agent and delegates to the default agent's commitAgentChange method.
|
|
5395
|
+
* @returns {Promise<void>} Resolves when the default agent's commitAgentChange method completes.
|
|
5396
|
+
* @async
|
|
5397
|
+
*/
|
|
5398
|
+
async commitAgentChange() {
|
|
5399
|
+
const message = `called commitAgentChange on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5400
|
+
this.logger.log(message);
|
|
5401
|
+
console.error(message);
|
|
5402
|
+
return await this.defaultAgent.commitAgentChange();
|
|
5403
|
+
}
|
|
5404
|
+
}
|
|
5252
5405
|
/**
|
|
5253
5406
|
* Waits for output from an agent in the swarm, handling cancellation and agent changes with queued execution.
|
|
5254
5407
|
* Resolves with the output from the active agent or an empty string if canceled, using Subjects for state management.
|
|
@@ -5470,15 +5623,20 @@ class ClientSwarm {
|
|
|
5470
5623
|
await this.params.bus.emit(this.params.clientId, {
|
|
5471
5624
|
type: "get-agent",
|
|
5472
5625
|
source: "swarm-bus",
|
|
5473
|
-
input: {
|
|
5626
|
+
input: {},
|
|
5627
|
+
output: {
|
|
5628
|
+
agentName,
|
|
5474
5629
|
result,
|
|
5475
5630
|
},
|
|
5476
|
-
output: {},
|
|
5477
5631
|
context: {
|
|
5478
5632
|
swarmName: this.params.swarmName,
|
|
5479
5633
|
},
|
|
5480
5634
|
clientId: this.params.clientId,
|
|
5481
5635
|
});
|
|
5636
|
+
if (!result) {
|
|
5637
|
+
console.error(`agent-swarm ClientSwarm getAgent current agent is not in the swarm agentName=${agentName} clientId=${this.params.clientId} swarmName=${this.params.swarmName}`);
|
|
5638
|
+
return new NoopAgent(this.params.clientId, this.params.swarmName, agentName, this.params.agentMap[this.params.defaultAgent], this.params.logger);
|
|
5639
|
+
}
|
|
5482
5640
|
return result;
|
|
5483
5641
|
}
|
|
5484
5642
|
/**
|
|
@@ -5544,10 +5702,10 @@ class ClientSwarm {
|
|
|
5544
5702
|
});
|
|
5545
5703
|
}
|
|
5546
5704
|
/**
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5705
|
+
* Disposes of the swarm, performing cleanup
|
|
5706
|
+
* Called when the swarm is no longer needed, ensuring proper resource release.
|
|
5707
|
+
* @returns {Promise<void>} Resolves when disposal is complete and logged.
|
|
5708
|
+
*/
|
|
5551
5709
|
async dispose() {
|
|
5552
5710
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
5553
5711
|
this.params.logger.debug(`ClientSession clientId=${this.params.clientId} dispose`);
|
|
@@ -8919,6 +9077,24 @@ class SwarmValidationService {
|
|
|
8919
9077
|
}
|
|
8920
9078
|
return swarm.agentList;
|
|
8921
9079
|
};
|
|
9080
|
+
/**
|
|
9081
|
+
* Retrieves the set of agent names associated with a given swarm.
|
|
9082
|
+
* Logs the operation and validates swarm existence, supporting ClientSwarm’s agent management.
|
|
9083
|
+
* @param {SwarmName} swarmName - The name of the swarm to query, sourced from Swarm.interface.
|
|
9084
|
+
* @returns {string[]} An array of agent names from the swarm’s schema.
|
|
9085
|
+
* @throws {Error} If the swarm is not found in _swarmMap.
|
|
9086
|
+
*/
|
|
9087
|
+
this.getAgentSet = functoolsKit.memoize(([swarmName]) => `${swarmName}`, (swarmName) => {
|
|
9088
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
|
|
9089
|
+
this.loggerService.info("swarmValidationService getAgentSet", {
|
|
9090
|
+
swarmName,
|
|
9091
|
+
});
|
|
9092
|
+
const swarm = this._swarmMap.get(swarmName);
|
|
9093
|
+
if (!swarm) {
|
|
9094
|
+
throw new Error(`agent-swarm swarm ${swarmName} not found`);
|
|
9095
|
+
}
|
|
9096
|
+
return new Set(swarm.agentList);
|
|
9097
|
+
});
|
|
8922
9098
|
/**
|
|
8923
9099
|
* Retrieves the list of policy names associated with a given swarm.
|
|
8924
9100
|
* Logs the operation and validates swarm existence, supporting ClientSwarm’s policy enforcement.
|
|
@@ -17116,6 +17292,14 @@ const changeToAgent = beginContext(async (agentName, clientId) => {
|
|
|
17116
17292
|
console.error(`agent-swarm missing dependency detected for activeAgent=${activeAgent} dependencyAgent=${agentName}`);
|
|
17117
17293
|
}
|
|
17118
17294
|
}
|
|
17295
|
+
if (!swarm$1.swarmValidationService.getAgentSet(swarmName).has(agentName)) {
|
|
17296
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17297
|
+
swarm$1.loggerService.log('function "changeToAgent" skipped due to the agent is not in the swarm', {
|
|
17298
|
+
agentName,
|
|
17299
|
+
clientId,
|
|
17300
|
+
});
|
|
17301
|
+
return false;
|
|
17302
|
+
}
|
|
17119
17303
|
// Execute the agent change with TTL and queuing
|
|
17120
17304
|
const run = await createChangeToAgent(clientId);
|
|
17121
17305
|
createGc$2();
|
package/build/index.mjs
CHANGED
|
@@ -5247,6 +5247,159 @@ class ToolSchemaService {
|
|
|
5247
5247
|
|
|
5248
5248
|
const AGENT_NEED_FETCH = Symbol("agent-need-fetch");
|
|
5249
5249
|
const STACK_NEED_FETCH = Symbol("stack-need-fetch");
|
|
5250
|
+
/**
|
|
5251
|
+
* A no-operation (noop) agent that serves as a fallback when an agent is not found in the swarm.
|
|
5252
|
+
* Implements the {@link IAgent} interface and logs calls to its methods, indicating that the requested agent is unavailable,
|
|
5253
|
+
* before delegating execution to a provided default agent. Used within the swarm system to handle invalid or missing agent references gracefully.
|
|
5254
|
+
* @implements {IAgent}
|
|
5255
|
+
*/
|
|
5256
|
+
class NoopAgent {
|
|
5257
|
+
/**
|
|
5258
|
+
* Creates a new NoopAgent instance.
|
|
5259
|
+
* @param {string} clientId - The unique identifier of the client associated with the swarm.
|
|
5260
|
+
* @param {SwarmName} swarmName - The name of the swarm this agent is associated with.
|
|
5261
|
+
* @param {AgentName} agentName - The name of the agent that was not found, used for logging.
|
|
5262
|
+
* @param {IAgent} defaultAgent - The default agent to delegate method calls to.
|
|
5263
|
+
* @param {ILogger} logger - The logger instance for recording method calls and errors.
|
|
5264
|
+
*/
|
|
5265
|
+
constructor(clientId, swarmName, agentName, defaultAgent, logger) {
|
|
5266
|
+
this.clientId = clientId;
|
|
5267
|
+
this.swarmName = swarmName;
|
|
5268
|
+
this.agentName = agentName;
|
|
5269
|
+
this.defaultAgent = defaultAgent;
|
|
5270
|
+
this.logger = logger;
|
|
5271
|
+
}
|
|
5272
|
+
/**
|
|
5273
|
+
* Logs an attempt to run the missing agent and delegates to the default agent's run method.
|
|
5274
|
+
* @param {string} input - The input string to process.
|
|
5275
|
+
* @returns {Promise<unknown>} The result from the default agent's run method.
|
|
5276
|
+
* @async
|
|
5277
|
+
*/
|
|
5278
|
+
async run(input) {
|
|
5279
|
+
const message = `called run on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5280
|
+
const context = {
|
|
5281
|
+
input,
|
|
5282
|
+
};
|
|
5283
|
+
this.logger.log(message, context);
|
|
5284
|
+
console.error(message, context);
|
|
5285
|
+
return await this.defaultAgent.run(input);
|
|
5286
|
+
}
|
|
5287
|
+
/**
|
|
5288
|
+
* Logs an attempt to execute the missing agent and delegates to the default agent's execute method.
|
|
5289
|
+
* @param {string} input - The input string to process.
|
|
5290
|
+
* @param {ExecutionMode} mode - The execution mode (e.g., synchronous or asynchronous).
|
|
5291
|
+
* @returns {Promise<unknown>} The result from the default agent's execute method.
|
|
5292
|
+
* @async
|
|
5293
|
+
*/
|
|
5294
|
+
async execute(input, mode) {
|
|
5295
|
+
const message = `called execute on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5296
|
+
const context = {
|
|
5297
|
+
input,
|
|
5298
|
+
mode,
|
|
5299
|
+
};
|
|
5300
|
+
this.logger.log(message, context);
|
|
5301
|
+
console.error(message, context);
|
|
5302
|
+
return await this.defaultAgent.execute(input, mode);
|
|
5303
|
+
}
|
|
5304
|
+
/**
|
|
5305
|
+
* Logs an attempt to wait for output from the missing agent and delegates to the default agent's waitForOutput method.
|
|
5306
|
+
* @returns {Promise<string>} The output from the default agent's waitForOutput method.
|
|
5307
|
+
* @async
|
|
5308
|
+
*/
|
|
5309
|
+
async waitForOutput() {
|
|
5310
|
+
const message = `called waitForOutput on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5311
|
+
this.logger.log(message);
|
|
5312
|
+
console.error(message);
|
|
5313
|
+
return await this.defaultAgent.waitForOutput();
|
|
5314
|
+
}
|
|
5315
|
+
/**
|
|
5316
|
+
* Logs an attempt to commit tool output for the missing agent and delegates to the default agent's commitToolOutput method.
|
|
5317
|
+
* @param {string} toolId - The identifier of the tool whose output is being committed.
|
|
5318
|
+
* @param {string} content - The content to commit as tool output.
|
|
5319
|
+
* @returns {Promise<void>} Resolves when the default agent's commitToolOutput method completes.
|
|
5320
|
+
* @async
|
|
5321
|
+
*/
|
|
5322
|
+
async commitToolOutput(toolId, content) {
|
|
5323
|
+
const message = `called commitToolOutput on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5324
|
+
const context = { toolId, content };
|
|
5325
|
+
this.logger.log(message, context);
|
|
5326
|
+
console.error(message, context);
|
|
5327
|
+
return await this.defaultAgent.commitToolOutput(toolId, content);
|
|
5328
|
+
}
|
|
5329
|
+
/**
|
|
5330
|
+
* Logs an attempt to commit a system message for the missing agent and delegates to the default agent's commitSystemMessage method.
|
|
5331
|
+
* @param {string} content - The system message content to commit.
|
|
5332
|
+
* @returns {Promise<void>} Resolves when the default agent's commitSystemMessage method completes.
|
|
5333
|
+
* @async
|
|
5334
|
+
*/
|
|
5335
|
+
async commitSystemMessage(content) {
|
|
5336
|
+
const message = `called commitToolOutput on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5337
|
+
const context = { content };
|
|
5338
|
+
this.logger.log(message, context);
|
|
5339
|
+
console.error(message, context);
|
|
5340
|
+
return await this.defaultAgent.commitSystemMessage(content);
|
|
5341
|
+
}
|
|
5342
|
+
/**
|
|
5343
|
+
* Logs an attempt to commit a user message for the missing agent and delegates to the default agent's commitUserMessage method.
|
|
5344
|
+
* @param {string} content - The user message content to commit.
|
|
5345
|
+
* @param {ExecutionMode} mode - The execution mode for the message.
|
|
5346
|
+
* @returns {Promise<void>} Resolves when the default agent's commitUserMessage method completes.
|
|
5347
|
+
* @async
|
|
5348
|
+
*/
|
|
5349
|
+
async commitUserMessage(content, mode) {
|
|
5350
|
+
const message = `called commitUserMessage on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5351
|
+
const context = { content, mode };
|
|
5352
|
+
this.logger.log(message, context);
|
|
5353
|
+
console.error(message, context);
|
|
5354
|
+
return await this.defaultAgent.commitUserMessage(content, mode);
|
|
5355
|
+
}
|
|
5356
|
+
/**
|
|
5357
|
+
* Logs an attempt to commit an assistant message for the missing agent and delegates to the default agent's commitAssistantMessage method.
|
|
5358
|
+
* @param {string} content - The assistant message content to commit.
|
|
5359
|
+
* @returns {Promise<void>} Resolves when the default agent's commitAssistantMessage method completes.
|
|
5360
|
+
* @async
|
|
5361
|
+
*/
|
|
5362
|
+
async commitAssistantMessage(content) {
|
|
5363
|
+
const message = `called commitAssistantMessage on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5364
|
+
const context = { content };
|
|
5365
|
+
this.logger.log(message, context);
|
|
5366
|
+
console.error(message, context);
|
|
5367
|
+
return await this.defaultAgent.commitAssistantMessage(content);
|
|
5368
|
+
}
|
|
5369
|
+
/**
|
|
5370
|
+
* Logs an attempt to commit a flush operation for the missing agent and delegates to the default agent's commitFlush method.
|
|
5371
|
+
* @returns {Promise<void>} Resolves when the default agent's commitFlush method completes.
|
|
5372
|
+
* @async
|
|
5373
|
+
*/
|
|
5374
|
+
async commitFlush() {
|
|
5375
|
+
const message = `called commitAssistantMessage on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5376
|
+
this.logger.log(message);
|
|
5377
|
+
console.error(message);
|
|
5378
|
+
return await this.defaultAgent.commitFlush();
|
|
5379
|
+
}
|
|
5380
|
+
/**
|
|
5381
|
+
* Logs an attempt to stop tools for the missing agent and delegates to the default agent's commitStopTools method.
|
|
5382
|
+
* @returns {Promise<void>} Resolves when the default agent's commitStopTools method completes.
|
|
5383
|
+
* @async
|
|
5384
|
+
*/
|
|
5385
|
+
async commitStopTools() {
|
|
5386
|
+
const message = `called commitStopTools on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5387
|
+
this.logger.log(message);
|
|
5388
|
+
console.error(message);
|
|
5389
|
+
return await this.defaultAgent.commitStopTools();
|
|
5390
|
+
}
|
|
5391
|
+
/**
|
|
5392
|
+
* Logs an attempt to commit an agent change for the missing agent and delegates to the default agent's commitAgentChange method.
|
|
5393
|
+
* @returns {Promise<void>} Resolves when the default agent's commitAgentChange method completes.
|
|
5394
|
+
* @async
|
|
5395
|
+
*/
|
|
5396
|
+
async commitAgentChange() {
|
|
5397
|
+
const message = `called commitAgentChange on agent which not in the swarm clientId=${this.clientId} agentName=${this.agentName} swarmName=${this.swarmName}`;
|
|
5398
|
+
this.logger.log(message);
|
|
5399
|
+
console.error(message);
|
|
5400
|
+
return await this.defaultAgent.commitAgentChange();
|
|
5401
|
+
}
|
|
5402
|
+
}
|
|
5250
5403
|
/**
|
|
5251
5404
|
* Waits for output from an agent in the swarm, handling cancellation and agent changes with queued execution.
|
|
5252
5405
|
* Resolves with the output from the active agent or an empty string if canceled, using Subjects for state management.
|
|
@@ -5468,15 +5621,20 @@ class ClientSwarm {
|
|
|
5468
5621
|
await this.params.bus.emit(this.params.clientId, {
|
|
5469
5622
|
type: "get-agent",
|
|
5470
5623
|
source: "swarm-bus",
|
|
5471
|
-
input: {
|
|
5624
|
+
input: {},
|
|
5625
|
+
output: {
|
|
5626
|
+
agentName,
|
|
5472
5627
|
result,
|
|
5473
5628
|
},
|
|
5474
|
-
output: {},
|
|
5475
5629
|
context: {
|
|
5476
5630
|
swarmName: this.params.swarmName,
|
|
5477
5631
|
},
|
|
5478
5632
|
clientId: this.params.clientId,
|
|
5479
5633
|
});
|
|
5634
|
+
if (!result) {
|
|
5635
|
+
console.error(`agent-swarm ClientSwarm getAgent current agent is not in the swarm agentName=${agentName} clientId=${this.params.clientId} swarmName=${this.params.swarmName}`);
|
|
5636
|
+
return new NoopAgent(this.params.clientId, this.params.swarmName, agentName, this.params.agentMap[this.params.defaultAgent], this.params.logger);
|
|
5637
|
+
}
|
|
5480
5638
|
return result;
|
|
5481
5639
|
}
|
|
5482
5640
|
/**
|
|
@@ -5542,10 +5700,10 @@ class ClientSwarm {
|
|
|
5542
5700
|
});
|
|
5543
5701
|
}
|
|
5544
5702
|
/**
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5703
|
+
* Disposes of the swarm, performing cleanup
|
|
5704
|
+
* Called when the swarm is no longer needed, ensuring proper resource release.
|
|
5705
|
+
* @returns {Promise<void>} Resolves when disposal is complete and logged.
|
|
5706
|
+
*/
|
|
5549
5707
|
async dispose() {
|
|
5550
5708
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
5551
5709
|
this.params.logger.debug(`ClientSession clientId=${this.params.clientId} dispose`);
|
|
@@ -8917,6 +9075,24 @@ class SwarmValidationService {
|
|
|
8917
9075
|
}
|
|
8918
9076
|
return swarm.agentList;
|
|
8919
9077
|
};
|
|
9078
|
+
/**
|
|
9079
|
+
* Retrieves the set of agent names associated with a given swarm.
|
|
9080
|
+
* Logs the operation and validates swarm existence, supporting ClientSwarm’s agent management.
|
|
9081
|
+
* @param {SwarmName} swarmName - The name of the swarm to query, sourced from Swarm.interface.
|
|
9082
|
+
* @returns {string[]} An array of agent names from the swarm’s schema.
|
|
9083
|
+
* @throws {Error} If the swarm is not found in _swarmMap.
|
|
9084
|
+
*/
|
|
9085
|
+
this.getAgentSet = memoize(([swarmName]) => `${swarmName}`, (swarmName) => {
|
|
9086
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
|
|
9087
|
+
this.loggerService.info("swarmValidationService getAgentSet", {
|
|
9088
|
+
swarmName,
|
|
9089
|
+
});
|
|
9090
|
+
const swarm = this._swarmMap.get(swarmName);
|
|
9091
|
+
if (!swarm) {
|
|
9092
|
+
throw new Error(`agent-swarm swarm ${swarmName} not found`);
|
|
9093
|
+
}
|
|
9094
|
+
return new Set(swarm.agentList);
|
|
9095
|
+
});
|
|
8920
9096
|
/**
|
|
8921
9097
|
* Retrieves the list of policy names associated with a given swarm.
|
|
8922
9098
|
* Logs the operation and validates swarm existence, supporting ClientSwarm’s policy enforcement.
|
|
@@ -17114,6 +17290,14 @@ const changeToAgent = beginContext(async (agentName, clientId) => {
|
|
|
17114
17290
|
console.error(`agent-swarm missing dependency detected for activeAgent=${activeAgent} dependencyAgent=${agentName}`);
|
|
17115
17291
|
}
|
|
17116
17292
|
}
|
|
17293
|
+
if (!swarm$1.swarmValidationService.getAgentSet(swarmName).has(agentName)) {
|
|
17294
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17295
|
+
swarm$1.loggerService.log('function "changeToAgent" skipped due to the agent is not in the swarm', {
|
|
17296
|
+
agentName,
|
|
17297
|
+
clientId,
|
|
17298
|
+
});
|
|
17299
|
+
return false;
|
|
17300
|
+
}
|
|
17117
17301
|
// Execute the agent change with TTL and queuing
|
|
17118
17302
|
const run = await createChangeToAgent(clientId);
|
|
17119
17303
|
createGc$2();
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -4336,10 +4336,10 @@ declare class ClientSwarm implements ISwarm {
|
|
|
4336
4336
|
*/
|
|
4337
4337
|
setAgentName(agentName: AgentName): Promise<void>;
|
|
4338
4338
|
/**
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4339
|
+
* Disposes of the swarm, performing cleanup
|
|
4340
|
+
* Called when the swarm is no longer needed, ensuring proper resource release.
|
|
4341
|
+
* @returns {Promise<void>} Resolves when disposal is complete and logged.
|
|
4342
|
+
*/
|
|
4343
4343
|
dispose(): Promise<void>;
|
|
4344
4344
|
}
|
|
4345
4345
|
|
|
@@ -5887,6 +5887,14 @@ declare class SwarmValidationService {
|
|
|
5887
5887
|
* @throws {Error} If the swarm is not found in _swarmMap.
|
|
5888
5888
|
*/
|
|
5889
5889
|
getAgentList: (swarmName: SwarmName) => string[];
|
|
5890
|
+
/**
|
|
5891
|
+
* Retrieves the set of agent names associated with a given swarm.
|
|
5892
|
+
* Logs the operation and validates swarm existence, supporting ClientSwarm’s agent management.
|
|
5893
|
+
* @param {SwarmName} swarmName - The name of the swarm to query, sourced from Swarm.interface.
|
|
5894
|
+
* @returns {string[]} An array of agent names from the swarm’s schema.
|
|
5895
|
+
* @throws {Error} If the swarm is not found in _swarmMap.
|
|
5896
|
+
*/
|
|
5897
|
+
getAgentSet: ((swarmName: SwarmName) => Set<string>) & functools_kit.IClearableMemoize<string> & functools_kit.IControlMemoize<string, Set<string>>;
|
|
5890
5898
|
/**
|
|
5891
5899
|
* Retrieves the list of policy names associated with a given swarm.
|
|
5892
5900
|
* Logs the operation and validates swarm existence, supporting ClientSwarm’s policy enforcement.
|