@@ -273,7 +273,7 @@ def __init__(
273273
274274 self ._setup_swarm (nodes )
275275 self ._inject_swarm_tools ()
276- self .hooks .invoke_callbacks (MultiAgentInitializedEvent (self ))
276+ run_async ( lambda : self .hooks .invoke_callbacks_async (MultiAgentInitializedEvent (self ) ))
277277
278278 def __call__ (
279279 self , task : str | list [ContentBlock ], invocation_state : dict [str , Any ] | None = None , ** kwargs : Any
@@ -336,7 +336,7 @@ async def stream_async(
336336 if invocation_state is None :
337337 invocation_state = {}
338338
339- self .hooks .invoke_callbacks (BeforeMultiAgentInvocationEvent (self , invocation_state ))
339+ await self .hooks .invoke_callbacks_async (BeforeMultiAgentInvocationEvent (self , invocation_state ))
340340
341341 logger .debug ("starting swarm execution" )
342342
@@ -375,7 +375,7 @@ async def stream_async(
375375 raise
376376 finally :
377377 self .state .execution_time = round ((time .time () - self .state .start_time ) * 1000 )
378- self .hooks .invoke_callbacks (AfterMultiAgentInvocationEvent (self , invocation_state ))
378+ await self .hooks .invoke_callbacks_async (AfterMultiAgentInvocationEvent (self , invocation_state ))
379379 self ._resume_from_session = False
380380
381381 # Yield final result after execution_time is set
@@ -687,7 +687,9 @@ async def _execute_swarm(self, invocation_state: dict[str, Any]) -> AsyncIterato
687687 # TODO: Implement cancellation token to stop _execute_node from continuing
688688 try :
689689 # Execute with timeout wrapper for async generator streaming
690- self .hooks .invoke_callbacks (BeforeNodeCallEvent (self , current_node .node_id , invocation_state ))
690+ await self .hooks .invoke_callbacks_async (
691+ BeforeNodeCallEvent (self , current_node .node_id , invocation_state )
692+ )
691693 node_stream = self ._stream_with_timeout (
692694 self ._execute_node (current_node , self .state .task , invocation_state ),
693695 self .node_timeout ,
@@ -699,7 +701,9 @@ async def _execute_swarm(self, invocation_state: dict[str, Any]) -> AsyncIterato
699701 self .state .node_history .append (current_node )
700702
701703 # After self.state add current node, swarm state finish updating, we persist here
702- self .hooks .invoke_callbacks (AfterNodeCallEvent (self , current_node .node_id , invocation_state ))
704+ await self .hooks .invoke_callbacks_async (
705+ AfterNodeCallEvent (self , current_node .node_id , invocation_state )
706+ )
703707
704708 logger .debug ("node=<%s> | node execution completed" , current_node .node_id )
705709
0 commit comments