MultiOn Tool
MultiOnTool 用于封装 MultiOn 的网页浏览能力,使 CrewAI agents 可以通过自然语言指令控制浏览器。
这个工具让网页浏览更顺畅,对于需要动态网页数据交互和网页任务自动化的项目尤其重要。
要使用这个工具,你需要安装 MultiOn 包:
uv add multion你还需要安装 MultiOn 浏览器扩展并启用 API 使用。
要有效使用 MultiOnTool,请按以下步骤操作:
- 安装 CrewAI:确保你的 Python 环境中已安装
crewai[tools]包。 - 安装并使用 MultiOn:按照 MultiOn 文档 安装 MultiOn 浏览器扩展。
- 启用 API 使用:点击浏览器扩展栏中的 MultiOn 扩展图标(不是网页上悬浮的 MultiOn 图标)打开扩展配置,然后点击 API Enabled 开关以启用 API。
下面的示例展示了如何初始化工具并执行网页浏览任务:
from crewai import Agent, Task, Crewfrom crewai_tools import MultiOnTool
# Initialize the toolmultion_tool = MultiOnTool(api_key="YOUR_MULTION_API_KEY", local=False)
# Define an agent that uses the toolbrowser_agent = Agent( role="Browser Agent", goal="Control web browsers using natural language", backstory="An expert browsing agent.", tools=[multion_tool], verbose=True,)
# Example task to search and summarize newsbrowse_task = Task( description="Summarize the top 3 trending AI News headlines", expected_output="A summary of the top 3 trending AI News headlines", agent=browser_agent,)
# Create and run the crewcrew = Crew(agents=[browser_agent], tasks=[browse_task])result = crew.kickoff()MultiOnTool 在初始化时接受以下参数:
- api_key:可选。指定 MultiOn API key。如果未提供,它会查找
MULTION_API_KEY环境变量。 - local:可选。设为
True时,agent 会在本地浏览器中运行。请确保已安装 MultiOn 浏览器扩展并勾选 API Enabled。默认值为False。 - max_steps:可选。设置 MultiOn agent 对单个命令最多可执行的步骤数。默认值为
3。
使用 MultiOnTool 时,agent 会提供自然语言指令,工具会将其转换为网页浏览动作。工具会返回浏览会话结果及其状态。
# Example of using the tool with an agentbrowser_agent = Agent( role="Web Browser Agent", goal="Search for and summarize information from the web", backstory="An expert at finding and extracting information from websites.", tools=[multion_tool], verbose=True,)
# Create a task for the agentsearch_task = Task( description="Search for the latest AI news on TechCrunch and summarize the top 3 headlines", expected_output="A summary of the top 3 AI news headlines from TechCrunch", agent=browser_agent,)
# Run the taskcrew = Crew(agents=[browser_agent], tasks=[search_task])result = crew.kickoff()如果返回的状态是 CONTINUE,应提示 agent 重新发出相同指令以继续执行。
MultiOnTool 作为 CrewAI 中 BaseTool 的子类实现。它封装了 MultiOn 客户端以提供网页浏览能力:
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 """
# Implementation details...
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 instruction for web browsing *args (Any): Additional arguments to pass to the Multion client **kwargs (Any): Additional keyword arguments to pass to the Multion client """ # Implementation details...MultiOnTool 为 CrewAI agents 集成网页浏览能力提供了强大的方式。通过让 agents 可以用自然语言指令与网站交互,它为网页任务开辟了更广泛的可能性,从数据采集和研究,到与网页服务的自动化交互都可以覆盖。