🤖AI Agents Guide
TutorialsComparisonsReviewsExamplesIntegrationsUse CasesTemplatesGlossary
Get Started
🤖AI Agents Guide

Your comprehensive resource for understanding, building, and implementing AI Agents.

Learn

  • Tutorials
  • Glossary
  • Use Cases
  • Examples

Compare

  • Tool Comparisons
  • Reviews
  • Integrations
  • Templates

Company

  • About
  • Contact
  • Privacy Policy

© 2026 AI Agents Guide. All rights reserved.

Home/Examples/Browser Use Agent Examples: Web + AI
ExampleWeb Automation16 min read min read

Browser Use Agent Examples: Web + AI

Practical browser-use Python library examples for building AI-powered web automation agents. From lead generation to price comparison, learn how to control browsers with natural language instructions and LLM reasoning.

a view of a city at night from the top of a building
Photo by Tuan P. on Unsplash
By AI Agents Guide•May 18, 2025

Table of Contents

  1. Example 1: Browser-Use Library Quickstart
  2. Example 2: Lead Generation Agent
  3. Example 3: Social Media Monitoring Agent
  4. Example 4: Price Comparison Agent
  5. Example 5: Job Application Agent
  6. Example 6: Research Aggregation Agent
  7. Choosing the Right Pattern
  8. Related Resources
a large building with a clock on the side of it
Photo by Finn J on Unsplash

The browser-use ↗ Python library turns any LLM into a browser-controlling agent. Instead of hand-writing Playwright selectors, you describe what you want in natural language and the agent figures out how to accomplish it on the live page.

This guide covers six practical examples that progress from a simple quickstart to a full multi-step research aggregation agent. Each example uses the real browser-use API so you can run them directly after installing the library.

pip install browser-use
playwright install chromium

You will also need an LLM API key. Most examples below use OpenAI, but any LangChain-compatible model works.

For desktop application automation beyond the browser, see Computer Use Agent Examples. For building tool-using agents without a browser, see LangChain Agent Examples.


Example 1: Browser-Use Library Quickstart#

The fastest way to verify your installation is a single-task agent that opens a website and extracts a piece of information. This establishes the core Agent + run() pattern used in every browser-use workflow.

import asyncio
from browser_use import Agent
from langchain_openai import ChatOpenAI

async def main():
    agent = Agent(
        task="Go to https://news.ycombinator.com and return the title of the top story.",
        llm=ChatOpenAI(model="gpt-4o-mini"),
    )
    result = await agent.run()
    print(result.final_result())

asyncio.run(main())

The Agent class accepts a plain-English task string. Under the hood it launches a Chromium browser via Playwright, navigates to the URL, inspects the DOM, and uses the LLM to identify the correct element. The run() coroutine returns a history object; .final_result() extracts the last assistant message as a string.

Key parameters:

  • task — natural language instruction for the agent
  • llm — any LangChain BaseChatModel instance
  • browser — optional custom Browser config for headless/headful mode
  • max_steps — safety limit on the number of browser actions (default 100)

This pattern scales to arbitrarily complex instructions without changing the calling code. The agent handles page load timing, JavaScript rendering, and element location automatically.


Example 2: Lead Generation Agent#

This agent visits a target company website, extracts the names and LinkedIn URLs of team members from the About page, and writes them to a CSV. It demonstrates multi-step navigation and structured data extraction.

import asyncio
import csv
import json
from browser_use import Agent
from browser_use.browser.browser import Browser, BrowserConfig
from langchain_openai import ChatOpenAI

COMPANIES = [
    "https://www.anthropic.com/company",
    "https://mistral.ai/company/",
]

async def extract_team(url: str) -> list[dict]:
    agent = Agent(
        task=(
            f"Visit {url}. Find the team or about page. "
            "Extract each person's full name and LinkedIn profile URL. "
            "Return a JSON array: [{\"name\": \"...\", \"linkedin\": \"...\"}]. "
            "If LinkedIn is not listed, set linkedin to null."
        ),
        llm=ChatOpenAI(model="gpt-4o"),
        browser=Browser(config=BrowserConfig(headless=True)),
    )
    result = await agent.run()
    text = result.final_result() or "[]"
    # Strip markdown code fences if present
    text = text.strip().removeprefix("```json").removesuffix("```").strip()
    return json.loads(text)

async def main():
    rows = []
    for url in COMPANIES:
        print(f"Scraping {url}")
        people = await extract_team(url)
        for p in people:
            rows.append({"company": url, **p})

    with open("leads.csv", "w", newline="") as f:
        writer = csv.DictWriter(f, fieldnames=["company", "name", "linkedin"])
        writer.writeheader()
        writer.writerows(rows)

    print(f"Wrote {len(rows)} leads to leads.csv")

asyncio.run(main())

The agent navigates through multi-level site structures, identifies relevant sections without pre-defined selectors, and returns structured JSON that is trivially parsed into CSV rows. Running agents for multiple companies in parallel with asyncio.gather() reduces total runtime proportionally to the number of concurrent browser instances your machine supports.

This pattern powers sales prospecting pipelines where the target company list changes weekly and maintaining fixed scrapers would be impractical.


Example 3: Social Media Monitoring Agent#

This agent checks a brand's mentions on a public social platform, filters for negative sentiment posts, and returns a summary report. It shows how to pass dynamic context and chain multiple browser actions.

import asyncio
from browser_use import Agent
from langchain_anthropic import ChatAnthropic

BRAND = "LangChain"

async def monitor_mentions(brand: str, hours: int = 24) -> str:
    task = (
        f"Go to https://twitter.com/search?q={brand}&src=typed_query&f=live "
        f"and load recent posts visible on the page. "
        f"Identify posts expressing frustration, bugs, or negative experiences. "
        "Return a markdown report with: "
        "1) Count of total visible posts "
        "2) Count of negative posts "
        "3) A bullet list of up to 5 negative post summaries with approximate timestamps. "
        "Do not log in. Only read publicly visible content."
    )

    agent = Agent(
        task=task,
        llm=ChatAnthropic(model="claude-3-5-sonnet-20241022"),
        max_steps=30,
    )
    result = await agent.run()
    return result.final_result()

async def main():
    report = await monitor_mentions(BRAND, hours=12)
    print(report)

asyncio.run(main())

The max_steps=30 guard prevents runaway agents that scroll indefinitely. For production monitoring, schedule this agent with APScheduler or a cron job and pipe results to Slack via a webhook. The agent adapts automatically when the platform changes its layout — no selector maintenance required.

Brand teams use this pattern to catch support issues early, track competitor sentiment, and monitor announcement reactions without dedicated social listening subscriptions.

AI browser agent monitoring social media mentions in real time


Example 4: Price Comparison Agent#

This agent visits multiple e-commerce pages for the same product and returns a ranked price table. It demonstrates parallel agent execution and result aggregation.

import asyncio
import json
import re
from browser_use import Agent
from browser_use.browser.browser import Browser, BrowserConfig
from langchain_openai import ChatOpenAI

PRODUCT = 'Sony WH-1000XM5 headphones'
STORES = [
    "https://www.amazon.com",
    "https://www.bestbuy.com",
    "https://www.walmart.com",
]

async def get_price(store_url: str, product: str) -> dict:
    agent = Agent(
        task=(
            f"Go to {store_url} and search for '{product}'. "
            "Find the lowest listed price for the exact product (not accessories). "
            "Return JSON: {\"store\": \"<domain>\", \"price\": \"<USD price string>\", "
            "\"url\": \"<product page URL>\"}. "
            "If the product is not found, set price to null."
        ),
        llm=ChatOpenAI(model="gpt-4o-mini"),
        browser=Browser(config=BrowserConfig(headless=True)),
        max_steps=20,
    )
    result = await agent.run()
    text = result.final_result() or "{}"
    match = re.search(r'\{.*\}', text, re.DOTALL)
    if match:
        return json.loads(match.group())
    return {"store": store_url, "price": None, "url": None}

async def main():
    tasks = [get_price(store, PRODUCT) for store in STORES]
    results = await asyncio.gather(*tasks)

    found = [r for r in results if r.get("price")]
    found.sort(key=lambda x: float(
        x["price"].replace("$", "").replace(",", "").split()[0]
    ))

    print(f"\nPrice comparison for: {PRODUCT}\n")
    print(f"{'Store':<30} {'Price':<15} URL")
    print("-" * 80)
    for r in found:
        print(f"{r['store']:<30} {r['price']:<15} {r['url']}")

asyncio.run(main())

asyncio.gather() runs all store agents concurrently — each agent gets its own Browser instance so they do not share state or cookies. The regex extraction step handles cases where the LLM wraps the JSON output in a markdown code block.

Connect this pattern to an AI Agent E-Commerce pricing pipeline to trigger automatic price adjustments when competitors undercut your listed price.


Example 5: Job Application Agent#

This agent fills out a job application form on a careers page using candidate details stored in a dictionary. It shows how to pass structured data into natural language tasks and handle multi-step form flows.

import asyncio
from browser_use import Agent
from browser_use.browser.browser import Browser, BrowserConfig
from langchain_openai import ChatOpenAI

CANDIDATE = {
    "name": "Alex Rivera",
    "email": "alex.rivera@example.com",
    "phone": "555-0192",
    "linkedin": "https://linkedin.com/in/alexrivera",
    "cover_letter": (
        "I am excited to apply for this role. "
        "My five years of Python experience and background in distributed systems "
        "make me a strong fit for your engineering team."
    ),
}

JOB_URL = "https://jobs.lever.co/examplecorp/software-engineer"

async def apply_to_job(job_url: str, candidate: dict) -> str:
    task = (
        f"Go to {job_url}. Fill in the application form using these details:\n"
        f"Full name: {candidate['name']}\n"
        f"Email: {candidate['email']}\n"
        f"Phone: {candidate['phone']}\n"
        f"LinkedIn: {candidate['linkedin']}\n"
        f"Cover letter: {candidate['cover_letter']}\n"
        "Do NOT submit the form. When all fields are filled, stop and report which "
        "fields were completed and which were skipped."
    )

    agent = Agent(
        task=task,
        llm=ChatOpenAI(model="gpt-4o"),
        browser=Browser(config=BrowserConfig(headless=False)),  # headful for review
        max_steps=40,
    )
    result = await agent.run()
    return result.final_result()

async def main():
    report = await apply_to_job(JOB_URL, CANDIDATE)
    print(report)

asyncio.run(main())

Setting headless=False opens a visible browser window so you can review the filled form before submission. The Do NOT submit instruction is a critical safety guard — always test with this guard in place before enabling auto-submission in any pipeline.

For high-volume outreach, combine this with a Human-in-the-Loop approval gate so a recruiter can review each filled form before it is submitted.


Example 6: Research Aggregation Agent#

This agent accepts a research question, visits multiple authoritative sources, and synthesises findings into a structured markdown report. It demonstrates multi-hop navigation and long-context reasoning across sources.

import asyncio
from browser_use import Agent
from browser_use.browser.browser import Browser, BrowserConfig
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage

RESEARCH_QUESTION = (
    "What are the three most cited limitations of transformer architecture "
    "for long-context tasks, according to recent AI research?"
)

SOURCES = [
    "https://arxiv.org",
    "https://paperswithcode.com",
    "https://scholar.google.com",
]

async def research_source(source_url: str, question: str) -> str:
    agent = Agent(
        task=(
            f"Go to {source_url} and search for: {question}\n"
            "Read the most relevant result in full. "
            "Return a 200-word summary of what you found, including the paper title "
            "and URL if available. If no relevant content is found, say so."
        ),
        llm=ChatOpenAI(model="gpt-4o"),
        browser=Browser(config=BrowserConfig(headless=True)),
        max_steps=25,
    )
    result = await agent.run()
    return result.final_result() or "No relevant content found."

async def synthesise(findings: list[str], question: str) -> str:
    """Use a direct LLM call (no browser) to merge the findings."""
    llm = ChatOpenAI(model="gpt-4o")
    prompt = (
        f"Research question: {question}\n\n"
        "Below are findings from three independent sources:\n\n"
        + "\n\n---\n\n".join(findings)
        + "\n\nSynthesize these into a structured markdown report with: "
        "1) Executive summary (3 sentences) "
        "2) Key findings with citations "
        "3) Areas of consensus across sources "
        "4) Gaps or contradictions identified."
    )
    response = await llm.ainvoke([HumanMessage(content=prompt)])
    return response.content

async def main():
    print(f"Researching: {RESEARCH_QUESTION}\n")
    source_tasks = [research_source(url, RESEARCH_QUESTION) for url in SOURCES]
    findings = await asyncio.gather(*source_tasks)

    report = await synthesise(list(findings), RESEARCH_QUESTION)
    print(report)

    with open("research_report.md", "w") as f:
        f.write(f"# Research Report\n\n**Question**: {RESEARCH_QUESTION}\n\n")
        f.write(report)
    print("\nReport saved to research_report.md")

asyncio.run(main())

The synthesis step uses a direct LLM call rather than another browser agent since no further navigation is needed. This two-phase pattern — parallel browser research followed by offline synthesis — is efficient and keeps per-task LLM costs low. For a deeper retrieval pipeline, combine this with Agentic RAG Examples to add vector search over previously collected documents.


Choosing the Right Pattern#

Use CasePatternModel Tier
Single-page extractionBasic Agent.run()Mini/Haiku
Multi-step form fillingSingle agent, max_steps=40Standard (GPT-4o)
Multi-site comparisonasyncio.gather() with per-site agentsMini
Authenticated flowsSingle agent + env var credentialsStandard
Research aggregationParallel agents + offline synthesisStandard

For latency-sensitive pipelines, run browser agents in a task queue (Celery, RQ) and cache results with Redis. For sites that block headless browsers, use BrowserConfig(headless=False) with realistic user-agent strings.


Related Resources#

  • Computer Use Agent Examples — Playwright-based browser automation with structured selectors
  • Agentic RAG Examples — Combine browser retrieval with vector search
  • AI Agent E-Commerce Examples — Apply browser agents to shopping workflows
  • LangChain Agent Examples — Build tool-using agents with the LangChain framework
  • Human-in-the-Loop Examples — Add approval gates to browser agent pipelines
  • AI Agents for Web Scraping — Production scraping patterns with agents
  • Integrations Overview — Connect browser agents to downstream tools

The FAQ section renders from the frontmatter faq array above.

Related Examples

Agentic RAG Examples: 5 Real Workflows

Six agentic RAG examples with working Python code covering query routing, self-correcting retrieval with hallucination detection, multi-document reranking, iterative retrieval with web fallback, conversational RAG with memory, and corrective RAG with grade-and-retry loops.

7 AI Agent Coding Examples (Real Projects)

Discover 7 real-world AI coding agent examples covering code review, PR generation, test writing, bug diagnosis, documentation generation, and refactoring automation. Each example includes architecture details and working code for engineering teams.

AI Data Analyst Examples: 6 Real Setups

Explore 6 AI data analyst agent examples covering natural language SQL generation, automated chart creation, anomaly detection, report generation, and business intelligence workflows. Includes Python code for building production-ready data analysis agents.

← Back to All Examples