From c78a9001927a14ae05e49f9b207e62db946659fd Mon Sep 17 00:00:00 2001 From: Ricardo-M-L Date: Fri, 17 Apr 2026 16:25:22 +0800 Subject: [PATCH] fix(examples): remove duplicate imports, Tools() instantiation, and __main__ block in browser-use-cua MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The browser-use-cua example had three duplicated sections at the top level: - Two sets of imports for \`asyncio\`, \`base64\`, \`os\`, and \`io.BytesIO\` - Two \`tools = Tools()\` instantiations (the second overwrote the first, discarding any action registrations that referenced the original binding — harmless here only because the registration occurs after the second line) - Two \`if __name__ == "__main__": asyncio.run(main())\` blocks at the bottom (the second runs main twice in a row) Removed the redundant copies. This is a pure cleanup; behavior is unchanged for normal happy-path runs, but the example no longer ships with the second main() call that would have executed after the first completed. Co-Authored-By: Claude Opus 4.7 (1M context) --- examples/browser-use-cua/main.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/examples/browser-use-cua/main.py b/examples/browser-use-cua/main.py index e71a0e86..24778487 100644 --- a/examples/browser-use-cua/main.py +++ b/examples/browser-use-cua/main.py @@ -1,5 +1,7 @@ import asyncio +import base64 import os +from io import BytesIO from typing import TYPE_CHECKING from dotenv import load_dotenv from browser_use import Agent, Tools @@ -7,11 +9,6 @@ from browser_use.llm import ChatOpenAI from browser_use.agent.views import ActionResult -import asyncio -import base64 -import os -from io import BytesIO - from agent_sandbox import Sandbox from agent_sandbox.browser.types.action import ( Action_Click, @@ -277,9 +274,6 @@ async def handle_cua_action(action: "ComputerAction") -> ActionResult: return ActionResult(error=f"{ERROR_MSG}: {e}") -tools = Tools() - - @tools.registry.action( "Use Sandbox GUI as a fallback when standard browser actions cannot achieve the desired goal. " "This action takes a screenshot and uses OpenAI CUA to determine the next GUI action, " @@ -437,6 +431,3 @@ async def main(): print() asyncio.run(main()) - -if __name__ == "__main__": - asyncio.run(main())