跳转到主要内容

SerpApiGoogleSearchTool

描述

使用 SerpApiGoogleSearchTool 通过 SerpApi 运行 Google 搜索并获取结构化结果。需要一个 SerpApi API 密钥。

安装

uv add crewai-tools[serpapi]

环境变量

  • SERPAPI_API_KEY (必需):SerpApi 的 API 密钥。在 https://serpapi.com/ 创建(有免费套餐)。

示例

代码
from crewai import Agent, Task, Crew
from crewai_tools import SerpApiGoogleSearchTool

tool = SerpApiGoogleSearchTool()

agent = Agent(
    role="Researcher",
    goal="Answer questions using Google search",
    backstory="Search specialist",
    tools=[tool],
    verbose=True,
)

task = Task(
    description="Search for the latest CrewAI releases",
    expected_output="A concise list of relevant results with titles and links",
    agent=agent,
)

crew = Crew(agents=[agent], tasks=[task])
result = crew.kickoff()

注意

  • 在环境中设置 SERPAPI_API_KEY。在 https://serpapi.com/ 创建密钥
  • 另请参阅通过 SerpApi 进行的 Google 购物:/en/tools/search-research/serpapi-googleshoppingtool

参数

运行参数

  • search_query (str, 必需):Google 查询。
  • location (str, 可选):地理位置参数。

注意

  • 此工具封装了 SerpApi 并返回结构化的搜索结果。