> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2-docs-scavio-google-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Browserbase Tools

> Navigate quotes.toscrape.com and extract paginated quotes and authors with BrowserbaseTools.

```python browserbase_tools.py theme={null}
"""
Browserbase Tools
=============================

Demonstrates browserbase tools.
"""

from agno.agent import Agent
from agno.tools.browserbase import BrowserbaseTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


# Browserbase Configuration
# -------------------------------
# These environment variables are required for the BrowserbaseTools to function properly.
# You can set them in your .env file or export them directly in your terminal.

# BROWSERBASE_API_KEY: Your API key from Browserbase dashboard
#   - Required for authentication
#   - Format: Starts with "bb_live_" or "bb_test_" followed by a unique string

# BROWSERBASE_PROJECT_ID: The project ID from your Browserbase dashboard
#   - Required to identify which project to use for browser sessions
#   - Format: UUID string (8-4-4-4-12 format)

# BROWSERBASE_BASE_URL: The Browserbase API endpoint
#   - Optional: Defaults to https://api.browserbase.com if not specified
#   - Only change this if you're using a custom API endpoint or proxy

# ==================== Usage ====================
# BrowserbaseTools automatically uses the correct implementation based on context:
# - Sync tools when using agent.run() or agent.print_response()
# - Async tools when using agent.arun() or agent.aprint_response()

agent = Agent(
    name="Web Automation Assistant",
    tools=[BrowserbaseTools()],
    instructions=[
        "You are a web automation assistant that can help with:",
        "1. Capturing screenshots of websites",
        "2. Extracting content from web pages",
        "3. Monitoring website changes",
        "4. Taking visual snapshots of responsive layouts",
        "5. Automated web testing and verification",
    ],
    markdown=True,
)

# ==================== Sync Usage ====================
# Use this for regular scripts and synchronous execution

# Content Extraction and SS
# agent.print_response("""
#     Go to https://news.ycombinator.com and extract:
#     1. The page title
#     2. Take a screenshot of the top stories section
# """)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response("""
        Visit https://quotes.toscrape.com and:
        1. Extract the first 5 quotes and their authors
        2. Navigate to page 2
        3. Extract the first 5 quotes from page 2
    """)

    # ==================== Async Usage ====================
    # Use this for FastAPI, async frameworks, or when using agent.arun()
    # The same agent instance works for both sync and async - just use arun/aprint_response!

    # import asyncio
    #
    #
    # async def main():
    #     # Same agent, just use async methods - it will automatically use async tools
    #     await agent.aprint_response("""
    #         Visit https://quotes.toscrape.com and:
    #         1. Extract the first 5 quotes and their authors
    #         2. Navigate to page 2
    #         3. Extract the first 5 quotes from page 2
    #     """)
    #
    #
    # if __name__ == "__main__":
    #     asyncio.run(main())
```

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno browserbase openai playwright
    ```
  </Step>

  <Step title="Export environment variables">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export BROWSERBASE_API_KEY="your_browserbase_api_key_here"
      export BROWSERBASE_PROJECT_ID="your_browserbase_project_id_here"
      export OPENAI_API_KEY="your_openai_api_key_here"
      ```

      ```bash Windows theme={null}
      $Env:BROWSERBASE_API_KEY="your_browserbase_api_key_here"
      $Env:BROWSERBASE_PROJECT_ID="your_browserbase_project_id_here"
      $Env:OPENAI_API_KEY="your_openai_api_key_here"
      ```
    </CodeGroup>
  </Step>

  <Step title="Run the example">
    Save the code above as `browserbase_tools.py`, then run:

    ```bash theme={null}
    python browserbase_tools.py
    ```
  </Step>
</Steps>

Full source: [cookbook/91\_tools/browserbase\_tools.py](https://github.com/agno-agi/agno/blob/main/cookbook/91_tools/browserbase_tools.py)
