diff --git a/agency_swarm/agents/BrowsingAgent/instructions.md b/agency_swarm/agents/BrowsingAgent/instructions.md index 9382c771..edab54b9 100644 --- a/agency_swarm/agents/BrowsingAgent/instructions.md +++ b/agency_swarm/agents/BrowsingAgent/instructions.md @@ -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. diff --git a/agency_swarm/agents/BrowsingAgent/tools/SearchWeb.py b/agency_swarm/agents/BrowsingAgent/tools/SearchWeb.py new file mode 100644 index 00000000..b19fe481 --- /dev/null +++ b/agency_swarm/agents/BrowsingAgent/tools/SearchWeb.py @@ -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()) diff --git a/agency_swarm/agents/BrowsingAgent/tools/__init__.py b/agency_swarm/agents/BrowsingAgent/tools/__init__.py index fc54dd73..4cf4d4ea 100644 --- a/agency_swarm/agents/BrowsingAgent/tools/__init__.py +++ b/agency_swarm/agents/BrowsingAgent/tools/__init__.py @@ -6,4 +6,5 @@ from .SelectDropdown import SelectDropdown from .SolveCaptcha import SolveCaptcha from .ExportFile import ExportFile -from .WebPageSummarizer import WebPageSummarizer \ No newline at end of file +from .WebPageSummarizer import WebPageSummarizer +from .SearchWeb import SearchWeb \ No newline at end of file