agent = Agent( task=""" 1. Go to https://quotes.toscrape.com/ 2. Use extract action with query "first 3 quotes with their authors" 3. Save results to quotes.csv using write_file action 4. Search Google for the first quote's author """, llm=ChatBrowserUse(),)
When you know what action to use, name it explicitly:
agent = Agent( task=""" 1. Use search action to find "Python tutorials" on Google 2. Use click action to open first result in new tab 3. Use scroll action to scroll down 2 pages 4. Use extract action to get the main headings 5. Use send_keys action with "Tab Tab Enter" if needed """, llm=ChatBrowserUse(),)
task="""1. Navigate to example.com/products2. Filter by category "Electronics"3. Sort by price (low to high)4. Extract the first 10 products with: - Product name - Price - Rating - URL5. Save to products.csv"""
# Explicit URL navigationtask="Navigate to https://news.ycombinator.com"# Search-based navigationtask="Use search action to search DuckDuckGo for 'browser automation'"# Multi-tab workflowtask="""1. Navigate to github.com in new tab2. Navigate to reddit.com in new tab3. Switch to the reddit tab4. Search for 'programming'"""
# Detailed form fillingtask="""1. Find the email input field and enter 'user@example.com'2. Find the password field and enter password3. Click the 'Sign In' button4. Wait 2 seconds for page to load"""# With error recoverytask="""1. Fill in username field with 'myuser'2. Fill in password field with password3. Click submit button4. If error message appears, read it and try again5. If successful, confirm you see the dashboard"""
# Structured extractiontask="""1. Go to news.ycombinator.com2. Use extract action with query: "Get the top 5 posts with: - Post title - Number of points - Number of comments - Post URL (set extract_links=True)""""# Paginated extractiontask="""1. Go to products page2. Extract all products on current page3. Click 'Next' button if it exists4. Repeat steps 2-3 until no more pages5. Combine all results"""
# Page scrollingtask="""1. Go to long article page2. Use scroll action with down=True and pages=33. Extract visible content"""# Element scrollingtask="""1. Find the comments section2. Use scroll action on that element to load more comments3. Repeat 5 times"""# Infinite scrolltask="""1. Scroll down 10 pages to load content2. Wait 1 second between scrolls3. Extract all loaded items"""
task="""1. Try to navigate to example.com/api/data2. If page not found (404), go to example.com/products instead3. If that also fails, use search action to find the products page4. Extract data from whichever page loads successfully"""
task="""1. Try to click the submit button2. If it doesn't work, wait 2 seconds and try again3. If still failing, use send_keys action with "Enter" instead4. Verify submission was successful"""
task="""1. Navigate to protected-site.com2. If you see a CAPTCHA or anti-bot message: - Wait 5 seconds - Try refreshing the page3. If still blocked, report the issue"""
For production, use cloud browsers with automatic captcha bypass.
When you have custom tools, be explicit about when to use them:
from browser_use import Tools, ActionResulttools = Tools()@tools.action('Get approval from human before making changes')async def get_approval(action: str) -> ActionResult: response = input(f"Approve '{action}'? (yes/no) > ") if response.lower() == 'yes': return ActionResult(extracted_content="Approved") return ActionResult(error="Rejected", is_done=True)agent = Agent( task=""" IMPORTANT RULES: 1. Before editing ANY data, ALWAYS use get_approval action 2. NEVER make changes without approval 3. If approval is denied, stop immediately Task: 1. Go to admin panel 2. Find the user settings 3. Get approval to update user role 4. Only if approved, change role to 'admin' """, llm=ChatBrowserUse(), tools=tools,)
@tools.action('Generate 2FA code')async def get_2fa() -> ActionResult: # Your 2FA logic passtask="""1. Login with username and password2. When prompted for 2FA: - ALWAYS use get_2fa action - NEVER try to read codes from the page - NEVER make up codes3. Enter the generated code"""
task="""1. Try to click the submit button2. If click fails: - Use send_keys action with "Tab Tab Enter" to navigate and submit - OR use send_keys with "ArrowDown ArrowDown Enter" for dropdowns3. Verify the form was submitted"""
# Explicit vision requestagent = Agent( task=""" 1. Go to design.com 2. Use screenshot action to capture the page 3. Analyze the layout and color scheme in the screenshot 4. Describe the visual design elements """, llm=ChatBrowserUse(), use_vision=True,)# Visual verificationtask="""1. Fill out the form2. Take a screenshot3. Verify all fields are filled correctly by examining the screenshot4. If any field is wrong, correct it5. Submit the form"""
task="""1. Go to e-commerce site2. Search for "laptop"3. If results show "No products found": - Try searching for "notebook" instead4. If results found: - Extract first 5 products5. If price is over $1000: - Look for discount codes6. Otherwise: - Proceed to checkout"""
task="""Research task:1. Go to research-site.com2. Search for papers about "machine learning"3. Filter by: - Year: 2023-2024 - Peer-reviewed only4. For each of the first 10 results: - Extract title, authors, abstract, publication date - Download PDF if available5. Save all data to research_papers.csv"""
task="""Social media monitoring:1. Go to twitter.com (must be logged in)2. Search for "#browser-automation"3. Filter by "Latest" tweets4. Scroll down to load 50 tweets5. Extract: - Tweet text - Author username - Timestamp - Likes count - Retweets count6. Save to tweets.json"""
# Use search_page instead of extracttask="""1. Go to documentation page2. Use search_page action with pattern='API key' to find all mentions3. Report the count and locations"""# Use find_elements instead of extracttask="""1. Go to products page2. Use find_elements with selector='.product-card' 3. Use find_elements again with attributes=['href'] to get all links4. Report total product count"""
extend_system_message="ALWAYS ask for approval before making purchases"agent = Agent( task="Buy laptop from store", llm=ChatBrowserUse(), extend_system_message=extend_system_message,)
# Step 1: Test basic navigationagent = Agent( task="Go to example.com and tell me the page title", llm=ChatBrowserUse(),)# Step 2: Add interactionagent = Agent( task="Go to example.com, click 'About', tell me what you see", llm=ChatBrowserUse(),)# Step 3: Add extractionagent = Agent( task=""" 1. Go to example.com 2. Click 'About' 3. Extract the company description and contact email """, llm=ChatBrowserUse(),)
# Initial versiontask="Login and extract data"# After testing, add error handlingtask="""1. Login (if fails, try refreshing and retry)2. Navigate to data page (if 404, search for it instead)3. Extract data (if page empty, wait 5 seconds and retry)"""
task="""Multi-step workflow with state tracking:1. Phase 1 - Authentication: - Login to site - Verify successful login - Remember you are now authenticated2. Phase 2 - Data Collection: - Go to each of these pages: /page1, /page2, /page3 - Extract data from each - Keep track of which pages you've visited3. Phase 3 - Cleanup: - Logout - Confirm logout successful"""
# Agent 1: Researchagent1 = Agent( task="Find top 10 AI companies and save their URLs to companies.json", llm=ChatBrowserUse(),)result1 = await agent1.run()# Agent 2: Analysis (uses results from agent1)import jsonwith open('companies.json') as f: companies = json.load(f)agent2 = Agent( task=f""" Visit each of these companies and extract: - Founded year - Number of employees - Main product Companies: {companies} """, llm=ChatBrowserUse(),)result2 = await agent2.run()