add multion tool

This commit is contained in:
Naman Garg
2024-06-21 14:48:24 -07:00
parent bd13b55afd
commit c97678bb11
5 changed files with 154 additions and 32 deletions

View File

@@ -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