@@ -424,6 +424,8 @@ def __init__(
424424 self .cloud_sync = cloud_sync or CloudSync ()
425425 # Register cloud sync handler
426426 self .eventbus .on ('*' , self .cloud_sync .handle_event )
427+ else :
428+ self .cloud_sync = None
427429
428430 if self .settings .save_conversation_path :
429431 self .settings .save_conversation_path = Path (self .settings .save_conversation_path ).expanduser ().resolve ()
@@ -835,15 +837,16 @@ async def _finalize(self, browser_state_summary: BrowserStateSummary | None) ->
835837 action_dict = action .model_dump () if hasattr (action , 'model_dump' ) else {}
836838 actions_data .append (action_dict )
837839
838- # Emit CreateAgentStepEvent
839- step_event = CreateAgentStepEvent .from_agent_step (
840- self ,
841- self .state .last_model_output ,
842- self .state .last_result ,
843- actions_data ,
844- browser_state_summary ,
845- )
846- self .eventbus .dispatch (step_event )
840+ # Emit CreateAgentStepEvent only if cloud sync is enabled
841+ if self .enable_cloud_sync :
842+ step_event = CreateAgentStepEvent .from_agent_step (
843+ self ,
844+ self .state .last_model_output ,
845+ self .state .last_result ,
846+ actions_data ,
847+ browser_state_summary ,
848+ )
849+ self .eventbus .dispatch (step_event )
847850
848851 # Increment step counter after step is fully completed
849852 self .state .n_steps += 1
@@ -1415,18 +1418,20 @@ def on_force_exit_log_telemetry():
14151418
14161419 # Only dispatch session events if this is the first run
14171420 if not self .state .session_initialized :
1418- self .logger .debug ('📡 Dispatching CreateAgentSessionEvent...' )
1419- # Emit CreateAgentSessionEvent at the START of run()
1420- self .eventbus .dispatch (CreateAgentSessionEvent .from_agent (self ))
1421+ if self .enable_cloud_sync :
1422+ self .logger .debug ('📡 Dispatching CreateAgentSessionEvent...' )
1423+ # Emit CreateAgentSessionEvent at the START of run()
1424+ self .eventbus .dispatch (CreateAgentSessionEvent .from_agent (self ))
14211425
1422- self .state .session_initialized = True
1426+ # Brief delay to ensure session is created in backend before sending task
1427+ await asyncio .sleep (0.2 )
14231428
1424- # Brief delay to ensure session is created in backend before sending task
1425- await asyncio .sleep (0.2 )
1429+ self .state .session_initialized = True
14261430
1427- self .logger .debug ('📡 Dispatching CreateAgentTaskEvent...' )
1428- # Emit CreateAgentTaskEvent at the START of run()
1429- self .eventbus .dispatch (CreateAgentTaskEvent .from_agent (self ))
1431+ if self .enable_cloud_sync :
1432+ self .logger .debug ('📡 Dispatching CreateAgentTaskEvent...' )
1433+ # Emit CreateAgentTaskEvent at the START of run()
1434+ self .eventbus .dispatch (CreateAgentTaskEvent .from_agent (self ))
14301435
14311436 # Start browser session and attach watchdogs
14321437 assert self .browser_session is not None , 'Browser session must be initialized before starting'
@@ -1572,7 +1577,8 @@ def on_force_exit_log_telemetry():
15721577 # not when they are completed
15731578
15741579 # Emit UpdateAgentTaskEvent at the END of run() with final task state
1575- self .eventbus .dispatch (UpdateAgentTaskEvent .from_agent (self ))
1580+ if self .enable_cloud_sync :
1581+ self .eventbus .dispatch (UpdateAgentTaskEvent .from_agent (self ))
15761582
15771583 # Generate GIF if needed before stopping event bus
15781584 if self .settings .generate_gif :
@@ -1591,7 +1597,7 @@ def on_force_exit_log_telemetry():
15911597 self .eventbus .dispatch (output_event )
15921598
15931599 # Wait briefly for cloud auth to start and print the URL, but don't block for completion
1594- if self .enable_cloud_sync and hasattr (self , 'cloud_sync' ):
1600+ if self .enable_cloud_sync and hasattr (self , 'cloud_sync' ) and self . cloud_sync is not None :
15951601 if self .cloud_sync .auth_task and not self .cloud_sync .auth_task .done ():
15961602 try :
15971603 # Wait up to 1 second for auth to start and print URL
0 commit comments