Skip to content

feat(tools): add use_browser tool to Strands tools repository #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Strands Agents Tools provides a powerful set of tools for your agents to use. It
- 🧠 **Advanced Reasoning** - Tools for complex thinking and reasoning capabilities
- 🐝 **Swarm Intelligence** - Coordinate multiple AI agents for parallel problem solving with shared memory
- 🔄 **Multiple tools in Parallel** - Call multiple other tools at the same time in parallel with Batch Tool

- 🔍 **Browser Tool** - Tool giving an agent access to perform automated actions on a browser (chromium)

## 📦 Installation

### Quick Install
Expand Down Expand Up @@ -121,6 +122,7 @@ Below is a comprehensive table of all available tools, how to use them with an a
| use_llm | `agent.tool.use_llm(prompt="Analyze this data", system_prompt="You are a data analyst")` | Create nested AI loops with customized system prompts for specialized tasks |
| workflow | `agent.tool.workflow(action="create", name="data_pipeline", steps=[{"tool": "file_read"}, {"tool": "python_repl"}])` | Define, execute, and manage multi-step automated workflows |
| batch| `agent.tool.batch(invocations=[{"name": "current_time", "arguments": {"timezone": "Europe/London"}}, {"name": "stop", "arguments": {}}])` | Call multiple other tools in parallel. |
| use_browser | `agent.tool.use_browser(action="navigate", url="https://www.example.com") ` | Web scraping, automated testing, form filling, web automation tasks |

\* *These tools do not work on windows*

Expand Down Expand Up @@ -301,6 +303,32 @@ result = agent.tool.batch(
)
```

### Use Browser
```python
from strands import Agent
from strands_tools import use_browser

agent = Agent(tools=[use_browser])

# Simple navigation
result = agent.tool.use_browser(action="navigate", url="https://example.com")

# Sequential actions for form filling
result = agent.tool.use_browser(actions=[
{"action": "navigate", "args": {"url": "https://example.com/login"}},
{"action": "type", "args": {"selector": "#username", "text": "[email protected]"}},
{"action": "click", "args": {"selector": "#submit"}}
])

# Web scraping with content extraction
result = agent.tool.use_browser(actions=[
{"action": "navigate", "args": {"url": "https://example.com/data"}},
{"action": "get_text", "args": {"selector": ".content"}},
{"action": "click", "args": {"selector": ".next-page"}},
{"action": "get_html", "args": {"selector": "main"}}
])
```

## 🌍 Environment Variables Configuration

Agents Tools provides extensive customization through environment variables. This allows you to configure tool behavior without modifying code, making it ideal for different environments (development, testing, production).
Expand Down Expand Up @@ -443,6 +471,20 @@ The Mem0 Memory Tool supports three different backend configurations:
| FILE_READ_USE_GIT_DEFAULT | Default setting for using git in time machine mode | true |
| FILE_READ_NUM_REVISIONS_DEFAULT | Default number of revisions to show in time machine mode | 5 |

#### Use Browser Tool

| Environment Variable | Description | Default |
|----------------------|-------------|---------|
| DEFAULT_WAIT_TIME | Default setting for wait time with actions | 1 |
| BROWSER_MAX_RETRIES | Default number of retries to perform when an action fails | 3 |
| BROWSER_SCREENSHOTS_DIR | Default directory where screenshots will be saved | screenshots |
| BROWSER_USER_DATA_DIR | Default directory where data for reloading a browser instance is stored | ~/.browser_automation |
| BROWSER_HEADLESS | Default headless setting for launching browsers | false |
| BROWSER_WIDTH | Default width of the browser | 1280 |
| BROWSER_HEIGHT | Default height of the browser | 800 |
| ENABLE_DEBUG_BROWSER_LOGS | Default enable of the browser's debug logs | false |


## Contributing ❤️

We welcome contributions! See our [Contributing Guide](CONTRIBUTING.md) for details on:
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ dependencies = [
"tenacity>=9.1.2,<10.0.0",
"watchdog>=6.0.0,<7.0.0",
"slack_bolt>=1.23.0,<2.0.0",
"nest-asyncio>=1.5.0,<2.0.0",
"playwright>=1.42.0,<2.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How heavy is this dependency?

I'm leaning towards this being an optional dependency as I don't want everyone to need to download playwright just to use memory for instance

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't too sure on the acceptable way to add these dependencies. As long as adding them as optional dependencies keeps the same functionality with the tool, I would rather do it that way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you can make it optional and then the installs are done via:

pip install strands-agents-tools[use-browser]

# Note: Always want the latest tzdata
"tzdata ; platform_system == 'Windows'",
]
Expand Down Expand Up @@ -112,7 +114,8 @@ extra-dependencies = [
"pytest>=8.0.0,<9.0.0",
"pytest-cov>=4.1.0,<5.0.0",
"pytest-xdist>=3.0.0,<4.0.0",
"responses>=0.6.1,<1.0.0"
"responses>=0.6.1,<1.0.0",
"pytest_asyncio>=0.23.0,<1.0.0"
]
extra-args = [
"-n",
Expand All @@ -134,7 +137,6 @@ run-cov = [
cov-combine = []
cov-report = []


[tool.hatch.envs.default.scripts]
list = [
"echo 'Scripts commands available for default env:'; hatch env show --json | jq --raw-output '.default.scripts | keys[]'"
Expand Down
2 changes: 1 addition & 1 deletion src/strands_tools/mem0_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"description": "Optional metadata to store with the memory",
},
},
"required": ["action"]
"required": ["action"],
}
},
}
Expand Down
Loading