Skip to content
CrewAI 文档版本 跟随上游 源快照 5fd3b1d5 更新于 2026-10-18

MultiOn Tool

MultiOnTool 让 CrewAI 智能体能够通过自然语言指令浏览网页并与之交互。

概述

MultiOnTool 旨在封装 MultiOn 的网页浏览能力,使 CrewAI 智能体能够使用自然语言指令控制浏览器。该工具可实现无缝的网页浏览,因此对于需要动态网页数据交互以及基于网页的任务自动化的项目而言,它是必不可少的资产。

安装

要使用该工具,你需要安装 MultiOn 包:

shell
uv add multion

你还需要安装 MultiOn 浏览器扩展并启用 API 使用。

入门步骤

要有效使用 MultiOnTool,请按以下步骤操作:

  1. 安装 CrewAI:确保你的 Python 环境中已安装 crewai[tools] 包。
  2. 安装并使用 MultiOn:按照 MultiOn 文档安装 MultiOn 浏览器扩展。
  3. 启用 API 使用:在浏览器的扩展文件夹中点击 MultiOn 扩展(不是网页上悬浮的 MultiOn 图标)以打开扩展配置。点击 API Enabled 开关以启用 API。

示例

以下示例演示如何初始化该工具并执行网页浏览任务:

python
from crewai import Agent, Task, Crew
from crewai_tools import MultiOnTool

# Initialize the tool
multion_tool = MultiOnTool(api_key="YOUR_MULTION_API_KEY", local=False)

# Define an agent that uses the tool
browser_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 news
browse_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 crew
crew = Crew(agents=[browser_agent], tasks=[browse_task])
result = crew.kickoff()

参数

MultiOnTool 在初始化时接受以下参数:

  • api_key:可选。指定 MultiOn API key。如果未提供,将查找 MULTION_API_KEY 环境变量。
  • local:可选。设为 True 可在本地浏览器中运行智能体。请确保已安装 MultiOn 浏览器扩展并勾选 API Enabled。默认为 False。
  • max_steps:可选。设置 MultiOn 智能体针对一个命令最多可执行的步数。默认为 3。

用量

使用 MultiOnTool 时,智能体会提供自然语言指令,由该工具将其转换为网页浏览操作。该工具会返回浏览会话的结果以及一个状态。

python
# Example of using the tool with an agent
browser_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 agent
search_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 task
crew = Crew(agents=[browser_agent], tasks=[search_task])
result = crew.kickoff()

如果返回的状态为 CONTINUE,应指示智能体重新发出相同的指令以继续执行。

实现细节

MultiOnTool 是作为 CrewAI 中 BaseTool 的子类实现的。它封装了 MultiOn 客户端以提供网页浏览能力:

python
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 智能体中。通过让智能体能够借助自然语言指令与网站交互,它为基于网页的任务开辟了广泛的可能性,从数据收集与调研到与 Web 服务的自动化交互。

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。