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

Exa 搜索工具

使用 Exa 搜索网络,这是最快、最准确的网络搜索 API。获取节省 token 的高亮片段和完整页面内容。

ExaSearchTool 让 CrewAI 智能体使用 Exa 搜索网络,这是最快、最准确的网络搜索 API。它会为任意查询返回最相关的结果,并提供节省 token 的高亮片段和完整页面内容选项。

安装

安装 CrewAI 工具包:

shell
pip install 'crewai[tools]'

环境变量

将你的 Exa API 密钥设置为环境变量:

bash
export EXA_API_KEY='your_exa_api_key'

从 Exa 仪表板 获取 API 密钥。

用法示例

以下是在 CrewAI 智能体中使用 ExaSearchTool 的方法:

python
import os
from crewai import Agent, Task, Crew
from crewai_tools import ExaSearchTool

# Initialize the tool
exa_tool = ExaSearchTool()

# Create an agent that uses the tool
researcher = Agent(
    role='Research Analyst',
    goal='Find the latest information on any topic',
    backstory='An expert researcher who finds the most relevant and up-to-date information.',
    tools=[exa_tool],
    verbose=True
)

# Create a task for the agent
research_task = Task(
    description='Find the top 3 recent breakthroughs in quantum computing.',
    expected_output='A summary of the top 3 breakthroughs with source URLs.',
    agent=researcher
)

# Form the crew and kick it off
crew = Crew(
    agents=[researcher],
    tasks=[research_task],
    verbose=True
)

result = crew.kickoff()
print(result)

配置选项

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

  • type (str,可选):要使用的搜索类型。默认为 "auto"。选项:"auto"、"instant"、"fast"、"deep"。
  • highlights (bool 或 dict,可选):返回与查询最相关且节省 token 的摘录,而不是完整页面。默认为 True。传入类似 {"max_characters": 4000} 的 dict 进行配置,或传入 False 以禁用。
  • content (bool,可选):是否在结果中包含完整页面内容。默认为 False。
  • api_key (str,可选):你的 Exa API 密钥。如果未提供,则回退到 EXA_API_KEY 环境变量。
  • base_url (str,可选):自定义 API 服务器 URL。如果未提供,则回退到 EXA_BASE_URL 环境变量。

调用工具时(或智能体调用它时),可以使用以下搜索参数:

  • search_query (str):必填。搜索查询字符串。
  • start_published_date (str,可选):筛选在此日期之后发布的结果(ISO 8601 格式,例如 "2024-01-01")。
  • end_published_date (str,可选):筛选在此日期之前发布的结果(ISO 8601 格式)。
  • include_domains (list[str],可选):用于限制搜索范围的域名列表。

高级用法

对于大多数智能体工作流,我们推荐 highlights —— 它会返回每个结果中最相关的摘录,并且比完整页面内容使用的 token 少得多:

python
# Get token-efficient excerpts most relevant to the query
exa_tool = ExaSearchTool(
    highlights=True,
    type="auto",
)

# Use it in an agent
agent = Agent(
    role="Researcher",
    goal="Answer questions with current web data",
    tools=[exa_tool]
)

对于详尽的多步骤搜索,请使用 type="deep":

python
exa_tool = ExaSearchTool(
    highlights=True,
    type="deep",
)

有关在 highlights 和完整内容之间进行选择的更多信息,请参阅 Exa 搜索最佳实践。

通过 MCP 使用 Exa

你还可以将智能体连接到 Exa 托管的 MCP 服务器。通过 x-api-key 标头传递你的 API 密钥:

python
from crewai import Agent
from crewai.mcp import MCPServerHTTP

agent = Agent(
    role="Research Analyst",
    goal="Find and analyze information on the web",
    backstory="Expert researcher with access to Exa's tools",
    mcps=[
        MCPServerHTTP(
            url="https://mcp.exa.ai/mcp",
            headers={"x-api-key": "YOUR_EXA_API_KEY"},
        ),
    ],
)

从 Exa 仪表板 获取你的 API 密钥。有关 CrewAI 中 MCP 的更多信息,请参阅 MCP 概览。

特性

  • 节省 token 的高亮片段:从每个结果中获取最相关的摘录,token 用量比全文少 ~10x
  • 语义搜索:基于含义而非仅关键词查找结果
  • 完整内容检索:在搜索结果旁获取网页全文
  • 日期筛选:使用发布日期过滤器将结果限制在特定时间段
  • 域名筛选:将搜索限制到特定域名

NOTE

EXASearchTool 是 ExaSearchTool 的已弃用别名。现有导入仍可继续使用,但会发出弃用警告;请迁移到 ExaSearchTool。

资源

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