Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

EventBus names now generate valid Python identifiers, preventing the AssertionError completely

naaa760bfbe1a8e8361
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 051a016e8..ba41b3287 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -604,8 +604,9 @@ class Agent(Generic[Context, AgentStructuredOutput]):
self._message_manager.add_new_task(new_task)
# Mark as follow-up task and recreate eventbus (gets shut down after each run)
self.state.follow_up_task = True
-
- agent_id_suffix = str(self.id)[-self.state.n_steps :].replace('-', '_')
+ agent_id_suffix = str(self.id)[-4:].replace('-', '_')
+ if agent_id_suffix and agent_id_suffix[0].isdigit():
+ agent_id_suffix = 'a' + agent_id_suffix
self.eventbus = EventBus(name=f'Agent_{agent_id_suffix}')
# Re-register cloud sync handler if it exists (if not disabled)