Skip to content

Commit 3d69fa2

Browse files
authored
feat(tools): add use_browser tool to Strands tools repository (#102)
* feat(tools): add use_browser tool to Strands tools repository * test(use_browser): add more unit testing for use_browser tool * feat(tools): add retry and multi-tab support to use_browser tool Adding functionality so use_browser tool has some retry functionality and supports multiple tabs and switching between them. * feat: add more retry logic and environment variables * fix(use_browser): fix screenshot error and using Playwright specific errors for better error handling * fix(use_browser): fix logs and fix how actions are being called, now actions are only called with their required arguments * fix(use_browser): fix merge conflicts in README file * Delete src/strands_tools/use_computer.py * test(use_browser): add more unit testing for use_browser tool * Update use_browser.py * test(use_browser): add more unit testing for use_browser tool * fix(use_browser): fix merge conflicts in README file * feat(use_browser): Added BrowserApiMethods class which has all the browser actions as methods * feat: Updating readme and pyproject.toml * feat: Adding use_browser tool * fix: fixing README file * fix: fixing dependencies for testing * fix: cleaning logs and updating README file * fix: fixing log statements to pass all checks
1 parent 6fd3590 commit 3d69fa2

File tree

4 files changed

+1299
-3
lines changed

4 files changed

+1299
-3
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ Strands Agents Tools provides a powerful set of tools for your agents to use. It
5353
- 🧠 **Advanced Reasoning** - Tools for complex thinking and reasoning capabilities
5454
- 🐝 **Swarm Intelligence** - Coordinate multiple AI agents for parallel problem solving with shared memory
5555
- 🔄 **Multiple tools in Parallel** - Call multiple other tools at the same time in parallel with Batch Tool
56-
56+
- 🔍 **Browser Tool** - Tool giving an agent access to perform automated actions on a browser (chromium)
57+
5758
## 📦 Installation
5859

5960
### Quick Install
@@ -121,6 +122,7 @@ Below is a comprehensive table of all available tools, how to use them with an a
121122
| 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 |
122123
| workflow | `agent.tool.workflow(action="create", name="data_pipeline", steps=[{"tool": "file_read"}, {"tool": "python_repl"}])` | Define, execute, and manage multi-step automated workflows |
123124
| batch| `agent.tool.batch(invocations=[{"name": "current_time", "arguments": {"timezone": "Europe/London"}}, {"name": "stop", "arguments": {}}])` | Call multiple other tools in parallel. |
125+
| use_browser | `agent.tool.use_browser(action="navigate", url="https://www.example.com") ` | Web scraping, automated testing, form filling, web automation tasks |
124126

125127
\* *These tools do not work on windows*
126128

@@ -301,6 +303,32 @@ result = agent.tool.batch(
301303
)
302304
```
303305

306+
### Use Browser
307+
```python
308+
from strands import Agent
309+
from strands_tools import use_browser
310+
311+
agent = Agent(tools=[use_browser])
312+
313+
# Simple navigation
314+
result = agent.tool.use_browser(action="navigate", url="https://example.com")
315+
316+
# Sequential actions for form filling
317+
result = agent.tool.use_browser(actions=[
318+
{"action": "navigate", "args": {"url": "https://example.com/login"}},
319+
{"action": "type", "args": {"selector": "#username", "text": "[email protected]"}},
320+
{"action": "click", "args": {"selector": "#submit"}}
321+
])
322+
323+
# Web scraping with content extraction
324+
result = agent.tool.use_browser(actions=[
325+
{"action": "navigate", "args": {"url": "https://example.com/data"}},
326+
{"action": "get_text", "args": {"selector": ".content"}},
327+
{"action": "click", "args": {"selector": ".next-page"}},
328+
{"action": "get_html", "args": {"selector": "main"}}
329+
])
330+
```
331+
304332
## 🌍 Environment Variables Configuration
305333

306334
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).
@@ -443,6 +471,20 @@ The Mem0 Memory Tool supports three different backend configurations:
443471
| FILE_READ_USE_GIT_DEFAULT | Default setting for using git in time machine mode | true |
444472
| FILE_READ_NUM_REVISIONS_DEFAULT | Default number of revisions to show in time machine mode | 5 |
445473

474+
#### Use Browser Tool
475+
476+
| Environment Variable | Description | Default |
477+
|----------------------|-------------|---------|
478+
| STRANDS_DEFAULT_WAIT_TIME | Default setting for wait time with actions | 1 |
479+
| STRANDS_BROWSER_MAX_RETRIES | Default number of retries to perform when an action fails | 3 |
480+
| STRANDS_BROWSER_RETRY_DELAY | Default retry delay time for retry mechanisms | 1 |
481+
| STRANDS_BROWSER_SCREENSHOTS_DIR | Default directory where screenshots will be saved | screenshots |
482+
| STRANDS_BROWSER_USER_DATA_DIR | Default directory where data for reloading a browser instance is stored | ~/.browser_automation |
483+
| STRANDS_BROWSER_HEADLESS | Default headless setting for launching browsers | false |
484+
| STRANDS_BROWSER_WIDTH | Default width of the browser | 1280 |
485+
| STRANDS_BROWSER_HEIGHT | Default height of the browser | 800 |
486+
487+
446488
## Contributing ❤️
447489

448490
We welcome contributions! See our [Contributing Guide](CONTRIBUTING.md) for details on:

pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ dev = [
6868
"responses>=0.6.1,<1.0.0",
6969
"mem0ai>=0.1.104,<1.0.0",
7070
"opensearch-py>=2.8.0,<3.0.0",
71+
"nest-asyncio>=1.5.0,<2.0.0",
72+
"playwright>=1.42.0,<2.0.0",
7173
]
7274
docs = [
7375
"sphinx>=5.0.0,<6.0.0",
@@ -112,7 +114,10 @@ extra-dependencies = [
112114
"pytest>=8.0.0,<9.0.0",
113115
"pytest-cov>=4.1.0,<5.0.0",
114116
"pytest-xdist>=3.0.0,<4.0.0",
115-
"responses>=0.6.1,<1.0.0"
117+
"responses>=0.6.1,<1.0.0",
118+
"pytest_asyncio>=0.23.0,<1.0.0",
119+
"nest-asyncio>=1.5.0,<2.0.0",
120+
"playwright>=1.42.0,<2.0.0"
116121
]
117122
extra-args = [
118123
"-n",
@@ -134,7 +139,6 @@ run-cov = [
134139
cov-combine = []
135140
cov-report = []
136141

137-
138142
[tool.hatch.envs.default.scripts]
139143
list = [
140144
"echo 'Scripts commands available for default env:'; hatch env show --json | jq --raw-output '.default.scripts | keys[]'"

0 commit comments

Comments
 (0)