From c97678bb1106ba8e7c0a9837736f89a5df5f2cd1 Mon Sep 17 00:00:00 2001 From: Naman Garg Date: Fri, 21 Jun 2024 14:48:24 -0700 Subject: [PATCH 1/3] add multion tool --- src/crewai_tools/__init__.py | 53 +++++++++--------- src/crewai_tools/tools/__init__.py | 17 ++++-- src/crewai_tools/tools/multion_tool/README.md | 31 ++++++++++ .../tools/multion_tool/example.py | 29 ++++++++++ .../tools/multion_tool/multion_tool.py | 56 +++++++++++++++++++ 5 files changed, 154 insertions(+), 32 deletions(-) create mode 100644 src/crewai_tools/tools/multion_tool/README.md create mode 100644 src/crewai_tools/tools/multion_tool/example.py create mode 100644 src/crewai_tools/tools/multion_tool/multion_tool.py diff --git a/src/crewai_tools/__init__.py b/src/crewai_tools/__init__.py index a51d70449..d0c4746df 100644 --- a/src/crewai_tools/__init__.py +++ b/src/crewai_tools/__init__.py @@ -1,27 +1,28 @@ -from .tools.base_tool import BaseTool, Tool, tool from .tools import ( - BrowserbaseLoadTool, - CodeDocsSearchTool, - CSVSearchTool, - DirectorySearchTool, - DOCXSearchTool, - DirectoryReadTool, - EXASearchTool, - FileReadTool, - GithubSearchTool, - SerperDevTool, - TXTSearchTool, - JSONSearchTool, - MDXSearchTool, - PDFSearchTool, - PGSearchTool, - RagTool, - ScrapeElementFromWebsiteTool, - ScrapeWebsiteTool, - SeleniumScrapingTool, - WebsiteSearchTool, - XMLSearchTool, - YoutubeChannelSearchTool, - YoutubeVideoSearchTool, - LlamaIndexTool -) \ No newline at end of file + BrowserbaseLoadTool, + CodeDocsSearchTool, + CSVSearchTool, + DirectoryReadTool, + DirectorySearchTool, + DOCXSearchTool, + EXASearchTool, + FileReadTool, + GithubSearchTool, + JSONSearchTool, + LlamaIndexTool, + MDXSearchTool, + MultiOnTool, + PDFSearchTool, + PGSearchTool, + RagTool, + ScrapeElementFromWebsiteTool, + ScrapeWebsiteTool, + SeleniumScrapingTool, + SerperDevTool, + TXTSearchTool, + WebsiteSearchTool, + XMLSearchTool, + YoutubeChannelSearchTool, + YoutubeVideoSearchTool, +) +from .tools.base_tool import BaseTool, Tool, tool diff --git a/src/crewai_tools/tools/__init__.py b/src/crewai_tools/tools/__init__.py index 4da0c0337..11074bbe3 100644 --- a/src/crewai_tools/tools/__init__.py +++ b/src/crewai_tools/tools/__init__.py @@ -1,24 +1,29 @@ from .browserbase_load_tool.browserbase_load_tool import BrowserbaseLoadTool from .code_docs_search_tool.code_docs_search_tool import CodeDocsSearchTool from .csv_search_tool.csv_search_tool import CSVSearchTool -from .directory_search_tool.directory_search_tool import DirectorySearchTool from .directory_read_tool.directory_read_tool import DirectoryReadTool +from .directory_search_tool.directory_search_tool import DirectorySearchTool from .docx_search_tool.docx_search_tool import DOCXSearchTool from .exa_tools.exa_search_tool import EXASearchTool from .file_read_tool.file_read_tool import FileReadTool from .github_search_tool.github_search_tool import GithubSearchTool -from .serper_dev_tool.serper_dev_tool import SerperDevTool -from .txt_search_tool.txt_search_tool import TXTSearchTool from .json_search_tool.json_search_tool import JSONSearchTool +from .llamaindex_tool.llamaindex_tool import LlamaIndexTool from .mdx_seach_tool.mdx_search_tool import MDXSearchTool +from .multion_tool.multion_tool import MultiOnTool from .pdf_search_tool.pdf_search_tool import PDFSearchTool from .pg_seach_tool.pg_search_tool import PGSearchTool from .rag.rag_tool import RagTool -from .scrape_element_from_website.scrape_element_from_website import ScrapeElementFromWebsiteTool +from .scrape_element_from_website.scrape_element_from_website import ( + ScrapeElementFromWebsiteTool, +) from .scrape_website_tool.scrape_website_tool import ScrapeWebsiteTool from .selenium_scraping_tool.selenium_scraping_tool import SeleniumScrapingTool +from .serper_dev_tool.serper_dev_tool import SerperDevTool +from .txt_search_tool.txt_search_tool import TXTSearchTool from .website_search.website_search_tool import WebsiteSearchTool from .xml_search_tool.xml_search_tool import XMLSearchTool -from .youtube_channel_search_tool.youtube_channel_search_tool import YoutubeChannelSearchTool +from .youtube_channel_search_tool.youtube_channel_search_tool import ( + YoutubeChannelSearchTool, +) from .youtube_video_search_tool.youtube_video_search_tool import YoutubeVideoSearchTool -from .llamaindex_tool.llamaindex_tool import LlamaIndexTool diff --git a/src/crewai_tools/tools/multion_tool/README.md b/src/crewai_tools/tools/multion_tool/README.md new file mode 100644 index 000000000..0cbbbb2cd --- /dev/null +++ b/src/crewai_tools/tools/multion_tool/README.md @@ -0,0 +1,31 @@ +# MultiOnTool Documentation + +## Description +The MultiOnTool, integrated within the crewai_tools package, empowers CrewAI agents with the capability to navigate and interact with the web through natural language instructions. Leveraging the Multion API, this tool facilitates seamless web browsing, making it an essential asset for projects requiring dynamic web data interaction. + +## Installation +Ensure the `crewai[tools]` package is installed in your environment to use the MultiOnTool. If it's not already installed, you can add it using the command below: + +## Example +The following example demonstrates how to initialize the tool and execute a search with a given query: + +```python +from crewai_tools import MultiOnTool + +# Initialize the tool from a MultiOn Tool +multion_tool = MultiOnTool(api_key= "YOUR_MULTION_API_KEY", local=False) + +``` + +## Arguments + +- `api_key`: Specifies Browserbase API key. Defaults is the `BROWSERBASE_API_KEY` environment variable. +- `local`: Optional. Use the local flag to run the agent locally on your browser. + +## Steps to Get Started +To effectively use the `MultiOnTool`, follow these steps: + +1. **Install CrewAI**: Confirm that the `crewai[tools]` package is installed in your Python environment. +2. **Install and use MultiOn**: Follow MultiOn documentation (https://docs.multion.ai/). + + diff --git a/src/crewai_tools/tools/multion_tool/example.py b/src/crewai_tools/tools/multion_tool/example.py new file mode 100644 index 000000000..ec69e5cdf --- /dev/null +++ b/src/crewai_tools/tools/multion_tool/example.py @@ -0,0 +1,29 @@ +import os + +from crewai import Agent, Crew, Task +from multion_tool import MultiOnTool + +os.environ["OPENAI_API_KEY"] = "Your Key" + +multion_browse_tool = MultiOnTool(api_key="Your Key") + +# Create a new agent +Browser = Agent( + role="Browser Agent", + goal="control web browsers using natural language ", + backstory="An expert browsing agent.", + tools=[multion_browse_tool], + verbose=True, +) + +# Define tasks +browse = Task( + description="Summarize the top 3 trending AI News headlines", + expected_output="A summary of the top 3 trending AI News headlines", + agent=Browser, +) + + +crew = Crew(agents=[Browser], tasks=[browse]) + +crew.kickoff() diff --git a/src/crewai_tools/tools/multion_tool/multion_tool.py b/src/crewai_tools/tools/multion_tool/multion_tool.py new file mode 100644 index 000000000..1253627a2 --- /dev/null +++ b/src/crewai_tools/tools/multion_tool/multion_tool.py @@ -0,0 +1,56 @@ +"""Multion tool spec.""" + +from typing import Any, Optional + +from crewai_tools.tools.base_tool import BaseTool + + +class MultiOnTool(BaseTool): + """Tool to wrap MultiOn Browse Capabilities.""" + + name: str = "Multion Browse Tool" + description: str = """Multion gives the ability for LLMs to control web browsers using natural language instructions. + If the status is 'CONTINUE', reissue the same instruction to continue execution + """ + multion: Optional[Any] = None + session_id: Optional[str] = None + local: bool = False + + def __init__(self, api_key: Optional[str] = None, local: bool = False, **kwargs): + super().__init__(**kwargs) + try: + from multion.client import MultiOn # type: ignore + except ImportError: + raise ImportError( + "`multion` package not found, please run `pip install multion`" + ) + self.session_id = None + self.local = local + self.multion = MultiOn(api_key=api_key) + + def _run( + self, + cmd: str, + *args: Any, + **kwargs: Any, + ) -> str: + """ + Run the Multion client with the given command. + + Args: + cmd (str): The detailed and specific natural language instructrion for web browsing + + *args (Any): Additional arguments to pass to the Multion client + **kwargs (Any): Additional keyword arguments to pass to the Multion client + """ + + browse = self.multion.browse( + cmd=cmd, + session_id=self.session_id, + local=self.local, + *args, + **kwargs, + ) + self.session_id = browse.session_id + + return browse.message + "\n\n STATUS: " + browse.status From d84a61657274f925d43e7b0f9807d47589393904 Mon Sep 17 00:00:00 2001 From: Naman Garg Date: Fri, 21 Jun 2024 15:01:08 -0700 Subject: [PATCH 2/3] update local option description in readme --- src/crewai_tools/tools/multion_tool/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crewai_tools/tools/multion_tool/README.md b/src/crewai_tools/tools/multion_tool/README.md index 0cbbbb2cd..608931166 100644 --- a/src/crewai_tools/tools/multion_tool/README.md +++ b/src/crewai_tools/tools/multion_tool/README.md @@ -20,7 +20,7 @@ multion_tool = MultiOnTool(api_key= "YOUR_MULTION_API_KEY", local=False) ## Arguments - `api_key`: Specifies Browserbase API key. Defaults is the `BROWSERBASE_API_KEY` environment variable. -- `local`: Optional. Use the local flag to run the agent locally on your browser. +- `local`: Optional. Use the local flag set as "true" to run the agent locally on your browser. Make sure the multion browser extension is installed and API Enabled is checked. ## Steps to Get Started To effectively use the `MultiOnTool`, follow these steps: From 6f45c6ed0949fece97b48ecf29df22336ec365e8 Mon Sep 17 00:00:00 2001 From: Naman Garg Date: Mon, 8 Jul 2024 15:11:04 -0700 Subject: [PATCH 3/3] Updated Readme --- src/crewai_tools/tools/multion_tool/README.md | 29 +++++++++++++++++-- .../tools/multion_tool/multion_tool.py | 11 ++++++- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/crewai_tools/tools/multion_tool/README.md b/src/crewai_tools/tools/multion_tool/README.md index 608931166..ea530037f 100644 --- a/src/crewai_tools/tools/multion_tool/README.md +++ b/src/crewai_tools/tools/multion_tool/README.md @@ -5,27 +5,50 @@ The MultiOnTool, integrated within the crewai_tools package, empowers CrewAI age ## Installation Ensure the `crewai[tools]` package is installed in your environment to use the MultiOnTool. If it's not already installed, you can add it using the command below: +```shell +pip install 'crewai[tools]' +``` ## Example The following example demonstrates how to initialize the tool and execute a search with a given query: ```python +from crewai import Agent, Task, Crew from crewai_tools import MultiOnTool # Initialize the tool from a MultiOn Tool multion_tool = MultiOnTool(api_key= "YOUR_MULTION_API_KEY", local=False) +Browser = Agent( + role="Browser Agent", + goal="control web browsers using natural language ", + backstory="An expert browsing agent.", + tools=[multion_remote_tool], + verbose=True, +) + +# example task to search and summarize news +browse = Task( + description="Summarize the top 3 trending AI News headlines", + expected_output="A summary of the top 3 trending AI News headlines", + agent=Browser, +) + +crew = Crew(agents=[Browser], tasks=[browse]) + +crew.kickoff() ``` ## Arguments - `api_key`: Specifies Browserbase API key. Defaults is the `BROWSERBASE_API_KEY` environment variable. -- `local`: Optional. Use the local flag set as "true" to run the agent locally on your browser. Make sure the multion browser extension is installed and API Enabled is checked. +- `local`: Use the local flag set as "true" to run the agent locally on your browser. Make sure the multion browser extension is installed and API Enabled is checked. +- `max_steps`: Optional. Set the max_steps the multion agent can take for a command ## Steps to Get Started To effectively use the `MultiOnTool`, follow these steps: 1. **Install CrewAI**: Confirm that the `crewai[tools]` package is installed in your Python environment. -2. **Install and use MultiOn**: Follow MultiOn documentation (https://docs.multion.ai/). - +2. **Install and use MultiOn**: Follow MultiOn documentation for installing the MultiOn Browser Extension (https://docs.multion.ai/learn/browser-extension). +3. **Enable API Usage**: Click on the MultiOn extension in the extensions folder of your browser (not the hovering MultiOn icon on the web page) to open the extension configurations. Click the API Enabled toggle to enable the API diff --git a/src/crewai_tools/tools/multion_tool/multion_tool.py b/src/crewai_tools/tools/multion_tool/multion_tool.py index 1253627a2..2dc944f23 100644 --- a/src/crewai_tools/tools/multion_tool/multion_tool.py +++ b/src/crewai_tools/tools/multion_tool/multion_tool.py @@ -15,8 +15,15 @@ class MultiOnTool(BaseTool): multion: Optional[Any] = None session_id: Optional[str] = None local: bool = False + max_steps: int = 3 - def __init__(self, api_key: Optional[str] = None, local: bool = False, **kwargs): + def __init__( + self, + api_key: Optional[str] = None, + local: bool = False, + max_steps: int = 3, + **kwargs, + ): super().__init__(**kwargs) try: from multion.client import MultiOn # type: ignore @@ -27,6 +34,7 @@ class MultiOnTool(BaseTool): self.session_id = None self.local = local self.multion = MultiOn(api_key=api_key) + self.max_steps = max_steps def _run( self, @@ -48,6 +56,7 @@ class MultiOnTool(BaseTool): cmd=cmd, session_id=self.session_id, local=self.local, + max_steps=self.max_steps, *args, **kwargs, )