Skip to content
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

Browser agent fix #146

Open
wants to merge 2 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
4 changes: 2 additions & 2 deletions agency_swarm/agents/BrowsingAgent/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ As an advanced browsing agent, you are equipped with specialized tools to naviga

### Primary Instructions:

1. **Avoid Guessing URLs**: Never attempt to guess the direct URL. Always perform a Google search if applicable, or return to your previous search results.
1. **Avoid Guessing URLs**: Never attempt to guess the direct URL. Always perform a web search if applicable, or return to your previous search results.
2. **Navigating to New Pages**: Always use the `ClickElement` tool to open links when navigating to a new web page from the current source. Do not guess the direct URL.
3. **Single Page Interaction**: You can only open and interact with one web page at a time. The previous web page will be closed when you open a new one. To navigate back, use the `GoBack` tool.
4. **Requesting Screenshots**: Before using tools that interact with the web page, ask the user to send you the appropriate screenshot using one of the commands below.

### Commands to Request Screenshots:

- **'[send screenshot]'**: Sends the current browsing window as an image. Use this command if the user asks what is on the page.
- **'[send screenshot]'**: Sends the current browsing window as an image. Use this command if the user asks what is on the page. This must be done after using the `ReadURL` tool.
- **'[highlight clickable elements]'**: Highlights all clickable elements on the current web page. This must be done before using the `ClickElement` tool.
- **'[highlight text fields]'**: Highlights all text fields on the current web page. This must be done before using the `SendKeys` tool.
- **'[highlight dropdowns]'**: Highlights all dropdowns on the current web page. This must be done before using the `SelectDropdown` tool.
Expand Down
30 changes: 30 additions & 0 deletions agency_swarm/agents/BrowsingAgent/tools/SearchWeb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from duckduckgo_search import DDGS
from agency_swarm.tools import BaseTool
from pydantic import Field

class SearchWeb(BaseTool):
"""
A tool to search the web using DuckDuckGo and return the results.

This tool takes a search phrase and returns a list of URLs and titles of the search results.
"""
phrase: str = Field(
..., description="The search phrase you want to use. Optimize the search phrase for an internet search engine."
)

def run(self):
"""
Executes the web search using DuckDuckGo and returns a list of results.

Each result is a dictionary containing 'title' and 'href' keys.
"""
try:
with DDGS() as ddgs:
results = [{'title': r['title'], 'href': r['href']} for r in ddgs.text(self.phrase, max_results=10)]
return results
except Exception as e:
return {"error": str(e)}

# Example usage:
# tool = SearchWeb(phrase="OpenAI GPT-4")
# print(tool.run())
3 changes: 2 additions & 1 deletion agency_swarm/agents/BrowsingAgent/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
from .SelectDropdown import SelectDropdown
from .SolveCaptcha import SolveCaptcha
from .ExportFile import ExportFile
from .WebPageSummarizer import WebPageSummarizer
from .WebPageSummarizer import WebPageSummarizer
from .SearchWeb import SearchWeb