@@ -16,6 +16,8 @@ import { IToolRequest } from "../model/Tool.model";
1616const AGENT_NEED_FETCH = Symbol ( "agent-need-fetch" ) ;
1717const STACK_NEED_FETCH = Symbol ( "stack-need-fetch" ) ;
1818
19+ const SET_BUSY_FN = Symbol ( "set-busy-fn" ) ;
20+
1921/**
2022 * A no-operation (noop) agent that serves as a fallback when an agent is not found in the swarm.
2123 * Implements the {@link IAgent} interface and logs calls to its methods, indicating that the requested agent is unavailable,
@@ -219,6 +221,8 @@ const WAIT_FOR_OUTPUT_FN = async (self: ClientSwarm): Promise<string> => {
219221 `ClientSwarm swarmName=${ self . params . swarmName } clientId=${ self . params . clientId } waitForOutput`
220222 ) ;
221223
224+ self [ SET_BUSY_FN ] ( true ) ;
225+
222226 const [ awaiter , { resolve } ] = createAwaiter < {
223227 agentName : AgentName ;
224228 output : string ;
@@ -275,6 +279,8 @@ const WAIT_FOR_OUTPUT_FN = async (self: ClientSwarm): Promise<string> => {
275279 clientId : self . params . clientId ,
276280 } ) ;
277281
282+ self [ SET_BUSY_FN ] ( false ) ;
283+
278284 return output ;
279285} ;
280286
@@ -287,6 +293,37 @@ const WAIT_FOR_OUTPUT_FN = async (self: ClientSwarm): Promise<string> => {
287293 * @implements {ISwarm}
288294 */
289295export class ClientSwarm implements ISwarm {
296+ private _isBusy = false ;
297+
298+ /**
299+ * Returns the current busy state of the swarm.
300+ * Used to check if the swarm is currently processing an operation (e.g., waiting for output or switching agents).
301+ * Supports debugging and flow control in client applications.
302+ * @returns {Promise<boolean> } True if the swarm is busy, false otherwise.
303+ */
304+ public getCheckBusy ( ) {
305+ GLOBAL_CONFIG . CC_LOGGER_ENABLE_DEBUG &&
306+ this . params . logger . debug (
307+ `ClientSwarm swarmName=${ this . params . swarmName } clientId=${ this . params . clientId } getCheckBusy`
308+ ) ;
309+ return Promise . resolve ( this . _isBusy ) ;
310+ }
311+
312+ /**
313+ * Sets the busy state of the swarm.
314+ * Used internally to indicate when the swarm is processing an operation, such as waiting for output.
315+ * Enables coordinated state management and debugging.
316+ * @param {boolean } isBusy - True to mark the swarm as busy, false to mark it as idle.
317+ */
318+ public [ SET_BUSY_FN ] ( isBusy : boolean ) {
319+ GLOBAL_CONFIG . CC_LOGGER_ENABLE_DEBUG &&
320+ this . params . logger . debug (
321+ `ClientSwarm swarmName=${ this . params . swarmName } clientId=${ this . params . clientId } setCheckBusy` ,
322+ { isBusy }
323+ ) ;
324+ this . _isBusy = isBusy ;
325+ }
326+
290327 /**
291328 * Subject that emits when an agent reference changes, providing the agent name and instance.
292329 * Used by setAgentRef to notify subscribers (e.g., waitForOutput) of updates to agent instances.
@@ -424,8 +461,8 @@ export class ClientSwarm implements ISwarm {
424461 agentName : await this . getAgentName ( ) ,
425462 output : "" ,
426463 } ) ;
427- await Promise . all ( this . _agentList
428- . map ( async ( [ , agent ] ) => {
464+ await Promise . all (
465+ this . _agentList . map ( async ( [ , agent ] ) => {
429466 await agent . commitCancelOutput ( ) ;
430467 } )
431468 ) ;
0 commit comments