Skip to content

Commit a116c01

Browse files
committed
patch
1 parent 7cb9ad4 commit a116c01

8 files changed

Lines changed: 108 additions & 13 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "agent-swarm-kit",
3-
"version": "1.1.136",
3+
"version": "1.1.137",
44
"description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
55
"author": {
66
"name": "Petr Tripolsky",

src/client/ClientSession.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,15 @@ export class ClientSession implements ISession {
185185
mode
186186
);
187187
const agent = await this.params.swarm.getAgent();
188+
this.params.swarm.setBusy(true);
188189
const outputAwaiter = this.params.swarm.waitForOutput();
189190
agent.execute(message, mode);
190191
const output = await outputAwaiter;
191192
await swarm.executionValidationService.flushCount(
192193
this.params.clientId,
193194
this.params.swarmName,
194195
);
196+
this.params.swarm.setBusy(false);
195197
if (
196198
await not(
197199
this.params.policy.validateOutput(

src/client/ClientSwarm.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import { IToolRequest } from "../model/Tool.model";
1616
const AGENT_NEED_FETCH = Symbol("agent-need-fetch");
1717
const STACK_NEED_FETCH = Symbol("stack-need-fetch");
1818

19-
const SET_BUSY_FN = Symbol("set-busy-fn");
20-
2119
/**
2220
* A no-operation (noop) agent that serves as a fallback when an agent is not found in the swarm.
2321
* Implements the {@link IAgent} interface and logs calls to its methods, indicating that the requested agent is unavailable,
@@ -235,8 +233,6 @@ const WAIT_FOR_OUTPUT_FN = async (self: ClientSwarm): Promise<string> => {
235233
`ClientSwarm swarmName=${self.params.swarmName} clientId=${self.params.clientId} waitForOutput`
236234
);
237235

238-
self[SET_BUSY_FN](true);
239-
240236
const [awaiter, { resolve }] = createAwaiter<{
241237
agentName: AgentName;
242238
output: string;
@@ -293,8 +289,6 @@ const WAIT_FOR_OUTPUT_FN = async (self: ClientSwarm): Promise<string> => {
293289
clientId: self.params.clientId,
294290
});
295291

296-
self[SET_BUSY_FN](false);
297-
298292
return output;
299293
};
300294

@@ -329,10 +323,10 @@ export class ClientSwarm implements ISwarm {
329323
* Enables coordinated state management and debugging.
330324
* @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
331325
*/
332-
public [SET_BUSY_FN](isBusy: boolean) {
326+
public setBusy(isBusy: boolean) {
333327
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
334328
this.params.logger.debug(
335-
`ClientSwarm swarmName=${this.params.swarmName} clientId=${this.params.clientId} setCheckBusy`,
329+
`ClientSwarm swarmName=${this.params.swarmName} clientId=${this.params.clientId} setBusy`,
336330
{ isBusy }
337331
);
338332
this._isBusy = isBusy;

src/interfaces/Swarm.interface.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,15 @@ export interface ISwarm {
261261
* @returns {Promise<boolean>} True if the swarm is busy, false otherwise.
262262
*/
263263
getCheckBusy(): Promise<boolean>;
264+
265+
/**
266+
* Sets the busy state of the swarm.
267+
* This method is used to indicate whether the swarm is currently processing an operation.
268+
* It helps manage flow control and debugging by signaling when the swarm is occupied.
269+
* @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
270+
* @throws {Error} If setting the busy state fails (e.g., due to internal errors).
271+
*/
272+
setBusy(isBusy: boolean): void;
264273
}
265274

266275
/**

src/lib/services/connection/SwarmConnectionService.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,23 @@ export class SwarmConnectionService implements ISwarm {
166166
).getCheckBusy();
167167
};
168168

169+
/**
170+
* Sets the busy state of the swarm.
171+
* Used to indicate whether the swarm is currently processing an operation, helping manage flow control and debugging.
172+
* Delegates to ClientSwarm.setBusy, using context from MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
173+
* Mirrors SwarmPublicService’s setBusy, supporting ClientAgent’s busy state management.
174+
* @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
175+
* @returns {Promise<void>} A promise resolving when the busy state is set.
176+
*/
177+
public setBusy = async (isBusy: boolean) => {
178+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
179+
this.loggerService.info(`swarmConnectionService setBusy`, { isBusy });
180+
return await this.getSwarm(
181+
this.methodContextService.context.clientId,
182+
this.methodContextService.context.swarmName
183+
).setBusy(isBusy);
184+
};
185+
169186
/**
170187
* Cancels the pending output by emitting an empty string, interrupting waitForOutput.
171188
* Delegates to ClientSwarm.cancelOutput, using context from MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.

src/lib/services/public/SwarmPublicService.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,46 @@ export class SwarmPublicService implements TSwarmConnectionService {
172172
);
173173
};
174174

175+
/**
176+
* Sets the busy state of the swarm, indicating whether it is currently processing an operation.
177+
* Wraps SwarmConnectionService.setBusy with MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
178+
* Used in ClientAgent (e.g., marking swarm busy during EXECUTE_FN) and SessionPublicService (e.g., managing swarm state in connect).
179+
* @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
180+
* @param {string} methodName - The method name for context and logging.
181+
* @param {string} clientId - The client ID, scoping the operation to a specific client.
182+
* @param {SwarmName} swarmName - The name of the swarm, used in SwarmMetaService context.
183+
* @returns {Promise<void>} A promise resolving when the busy state is set.
184+
*/
185+
public setBusy = async (
186+
isBusy: boolean,
187+
methodName: string,
188+
clientId: string,
189+
swarmName: SwarmName
190+
) => {
191+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
192+
this.loggerService.info("swarmPublicService setBusy", {
193+
isBusy,
194+
clientId,
195+
swarmName,
196+
});
197+
return await MethodContextService.runInContext(
198+
async () => {
199+
return await this.swarmConnectionService.setBusy(isBusy);
200+
},
201+
{
202+
methodName,
203+
clientId,
204+
swarmName,
205+
policyName: "",
206+
agentName: "",
207+
storageName: "",
208+
stateName: "",
209+
mcpName: "",
210+
computeName: "",
211+
}
212+
);
213+
}
214+
175215
/**
176216
* Cancels the await of output in the swarm by emitting an empty string, scoped to a client.
177217
* Wraps SwarmConnectionService.cancelOutput with MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.

types.d.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,14 @@ interface ISwarm {
13301330
* @returns {Promise<boolean>} True if the swarm is busy, false otherwise.
13311331
*/
13321332
getCheckBusy(): Promise<boolean>;
1333+
/**
1334+
* Sets the busy state of the swarm.
1335+
* This method is used to indicate whether the swarm is currently processing an operation.
1336+
* It helps manage flow control and debugging by signaling when the swarm is occupied.
1337+
* @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
1338+
* @throws {Error} If setting the busy state fails (e.g., due to internal errors).
1339+
*/
1340+
setBusy(isBusy: boolean): void;
13331341
}
13341342
/**
13351343
* Type representing the unique name of a swarm within the system.
@@ -4576,6 +4584,12 @@ declare class ClientAgent implements IAgent {
45764584
* @returns {Promise<void>} Resolves when the message is committed and the event is emitted.
45774585
*/
45784586
commitSystemMessage(message: string): Promise<void>;
4587+
/**
4588+
* Commits a developer message to the history, notifying the system via BusService without triggering execution.
4589+
* Useful for logging developer notes or debugging information, coordinated with SessionConnectionService.
4590+
* @param {string} message - The developer message to commit, trimmed before storage.
4591+
* @returns {Promise<void>} Resolves when the message is committed and the event is emitted.
4592+
*/
45794593
commitDeveloperMessage(message: string): Promise<void>;
45804594
/**
45814595
* Commits a tool request to the agent's history and emits an event via BusService.
@@ -5428,7 +5442,6 @@ declare class ToolSchemaService {
54285442

54295443
declare const AGENT_NEED_FETCH: unique symbol;
54305444
declare const STACK_NEED_FETCH: unique symbol;
5431-
declare const SET_BUSY_FN: unique symbol;
54325445
/**
54335446
* Manages a collection of agents within a swarm in the swarm system, implementing the ISwarm interface.
54345447
* Handles agent switching, output waiting, and navigation stack management, with queued operations and event-driven updates via BusService.
@@ -5453,7 +5466,7 @@ declare class ClientSwarm implements ISwarm {
54535466
* Enables coordinated state management and debugging.
54545467
* @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
54555468
*/
5456-
[SET_BUSY_FN](isBusy: boolean): void;
5469+
setBusy(isBusy: boolean): void;
54575470
/**
54585471
* Subject that emits when an agent reference changes, providing the agent name and instance.
54595472
* Used by setAgentRef to notify subscribers (e.g., waitForOutput) of updates to agent instances.
@@ -5643,6 +5656,15 @@ declare class SwarmConnectionService implements ISwarm {
56435656
* @returns {Promise<boolean>} True if the swarm is busy, false otherwise.
56445657
*/
56455658
getCheckBusy: () => Promise<boolean>;
5659+
/**
5660+
* Sets the busy state of the swarm.
5661+
* Used to indicate whether the swarm is currently processing an operation, helping manage flow control and debugging.
5662+
* Delegates to ClientSwarm.setBusy, using context from MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
5663+
* Mirrors SwarmPublicService’s setBusy, supporting ClientAgent’s busy state management.
5664+
* @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
5665+
* @returns {Promise<void>} A promise resolving when the busy state is set.
5666+
*/
5667+
setBusy: (isBusy: boolean) => Promise<void>;
56465668
/**
56475669
* Cancels the pending output by emitting an empty string, interrupting waitForOutput.
56485670
* Delegates to ClientSwarm.cancelOutput, using context from MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
@@ -6777,6 +6799,17 @@ declare class SwarmPublicService implements TSwarmConnectionService {
67776799
* @returns {Promise<boolean>} True if the swarm is busy, false otherwise.
67786800
*/
67796801
getCheckBusy: (methodName: string, clientId: string, swarmName: SwarmName) => Promise<boolean>;
6802+
/**
6803+
* Sets the busy state of the swarm, indicating whether it is currently processing an operation.
6804+
* Wraps SwarmConnectionService.setBusy with MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.
6805+
* Used in ClientAgent (e.g., marking swarm busy during EXECUTE_FN) and SessionPublicService (e.g., managing swarm state in connect).
6806+
* @param {boolean} isBusy - True to mark the swarm as busy, false to mark it as idle.
6807+
* @param {string} methodName - The method name for context and logging.
6808+
* @param {string} clientId - The client ID, scoping the operation to a specific client.
6809+
* @param {SwarmName} swarmName - The name of the swarm, used in SwarmMetaService context.
6810+
* @returns {Promise<void>} A promise resolving when the busy state is set.
6811+
*/
6812+
setBusy: (isBusy: boolean, methodName: string, clientId: string, swarmName: SwarmName) => Promise<void>;
67806813
/**
67816814
* Cancels the await of output in the swarm by emitting an empty string, scoped to a client.
67826815
* Wraps SwarmConnectionService.cancelOutput with MethodContextService, logging via LoggerService if GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO is true.

0 commit comments

Comments
 (0)