ScavioScavio
产品定价文档
登录开始使用
  1. 首页
  2. 教程
  3. 如何为 CrewAI 创建 Scavio 搜索工具
教程

如何为 CrewAI 创建 Scavio 搜索工具

构建自定义 CrewAI BaseTool,通过 Scavio API 搜索 Google、Reddit、YouTube 和 Amazon。特工人员进行搜索和分析。

获取免费API密钥API文档

CrewAI 附带了用于 Google 搜索的 SerperDevTool,但它只涵盖一个平台。使用 Scavio 构建自定义 BaseTool 使您的 CrewAI 代理可以通过单一工具访问 Google、Reddit、YouTube、Amazon、沃尔玛和 TikTok 数据,每次搜索只需 0.005 美元。本教程创建了该工具并将其连接到研究和分析团队中。

前置条件

  • Python 3.8+
  • 已安装crewai(pip安装crewai)
  • 来自 scavio.dev 的 Scavio API 密钥
  • 船员的 LLM API 密钥

操作指南

步骤 1: 创建 Scavio 搜索 BaseTool

实施具有多平台搜索支持的 CrewAI BaseTool。

Python
import os, requests
from crewai.tools import BaseTool
from typing import Optional

API_KEY = os.environ['SCAVIO_API_KEY']
SH = {'x-api-key': API_KEY, 'Content-Type': 'application/json'}

class ScavioSearchTool(BaseTool):
    name: str = 'scavio_search'
    description: str = 'Search the web for current information. Supports platforms: google, reddit, youtube, amazon, walmart. Default is google. Returns structured results with titles, links, and snippets.'

    def _run(self, query: str, platform: Optional[str] = None) -> str:
        body = {'query': query, 'country_code': 'us'}
        if platform and platform != 'google':
            body['platform'] = platform
        data = requests.post('https://api.scavio.dev/api/v1/search',
            headers=SH, json=body).json()
        results = data.get('organic_results', [])[:5]
        formatted = []
        for r in results:
            formatted.append(f"{r.get('position', 0)}. {r['title']}\n   {r.get('link', '')}\n   {r.get('snippet', '')[:120]}")
        return f'Results for "{query}" ({platform or "google"}):\n' + '\n\n'.join(formatted)

search_tool = ScavioSearchTool()
print(search_tool._run('best python framework 2026')[:200])

步骤 2: 定义研究人员代理

创建使用搜索工具的研究人员代理和分析人员代理。

Python
from crewai import Agent, Task, Crew

researcher = Agent(
    role='Senior Researcher',
    goal='Find comprehensive, current data on the given topic using web search across multiple platforms',
    backstory='You are an expert researcher who searches Google for official sources, Reddit for user opinions, and YouTube for tutorial coverage.',
    tools=[search_tool],
    verbose=True
)

analyst = Agent(
    role='Data Analyst',
    goal='Analyze research findings and produce actionable insights with data-backed recommendations',
    backstory='You synthesize data from multiple sources into clear, honest analysis. You note when data is limited or uncertain.',
    tools=[],
    verbose=True
)

print('Agents defined: Researcher (with search tool) + Analyst')

步骤 3: 创建任务并集合人员

定义研究和分析任务,然后运行团队。

Python
def run_research_crew(topic):
    research_task = Task(
        description=f'Research "{topic}" thoroughly. Search Google for top results, then search Reddit for real user opinions. Return raw findings organized by source.',
        expected_output='Structured research findings from Google and Reddit with links and key quotes.',
        agent=researcher
    )
    analysis_task = Task(
        description=f'Analyze the research findings on "{topic}". Identify consensus opinions, areas of disagreement, and produce a ranked recommendation with honest tradeoffs.',
        expected_output='Ranked analysis with pros/cons and a clear recommendation. Note any data gaps.',
        agent=analyst
    )
    crew = Crew(
        agents=[researcher, analyst],
        tasks=[research_task, analysis_task],
        verbose=True
    )
    result = crew.kickoff()
    return result

result = run_research_crew('best SERP API for Python developers')
print(f'\n--- Final Output ---\n{str(result)[:500]}')

步骤 4: 添加特定于平台的搜索任务

让团队成员能够搜索 Reddit、YouTube 和 Amazon,以获得更丰富的分析。

Python
def multi_platform_crew(topic):
    google_task = Task(
        description=f'Search Google for "{topic}" and list the top 5 results with titles, URLs, and key points from snippets.',
        expected_output='Top 5 Google results with summaries.',
        agent=researcher
    )
    reddit_task = Task(
        description=f'Search Reddit for "{topic}" to find real user discussions, complaints, and recommendations. Quote specific user opinions.',
        expected_output='Reddit discussion summary with quoted opinions.',
        agent=researcher
    )
    synthesis_task = Task(
        description='Synthesize Google authority sources and Reddit user opinions into a balanced recommendation. Flag where official claims differ from user experience.',
        expected_output='Balanced analysis contrasting official sources with real user experience.',
        agent=analyst
    )
    crew = Crew(agents=[researcher, analyst],
                tasks=[google_task, reddit_task, synthesis_task], verbose=True)
    result = crew.kickoff()
    print(f'Crew complete. Search cost estimate: ~$0.020-0.040')
    return result

multi_platform_crew('best SERP API 2026')

Python 示例

Python
import os, requests
from crewai.tools import BaseTool

SH = {'x-api-key': os.environ['SCAVIO_API_KEY'], 'Content-Type': 'application/json'}

class ScavioSearch(BaseTool):
    name: str = 'web_search'
    description: str = 'Search Google, Reddit, YouTube, Amazon via Scavio API.'
    def _run(self, query: str) -> str:
        data = requests.post('https://api.scavio.dev/api/v1/search',
            headers=SH, json={'query': query, 'country_code': 'us'}).json()
        return '\n'.join(f"{r['title'][:50]}" for r in data.get('organic_results', [])[:3])

tool = ScavioSearch()
print(tool._run('best serp api'))

JavaScript 示例

JavaScript
// CrewAI is Python-only. Use the REST API directly in JS:
const SH = { 'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json' };
async function search(query, platform) {
  const body = { query, country_code: 'us' };
  if (platform) body.platform = platform;
  const data = await fetch('https://api.scavio.dev/api/v1/search', {
    method: 'POST', headers: SH, body: JSON.stringify(body)
  }).then(r => r.json());
  return (data.organic_results || []).slice(0, 3).map(r => r.title.slice(0, 50));
}
const results = await search('best serp api');
console.log(results.join('\n'));

预期输出

JSON
Results for "best python framework 2026" (google):
1. FastAPI - Modern Python Web Framework
   https://fastapi.tiangolo.com
   FastAPI is a modern, fast web framework for building APIs with Python...

Agents defined: Researcher (with search tool) + Analyst

[Researcher] Searching Google for 'best SERP API for Python developers'...
[Researcher] Searching Reddit for user opinions...
[Analyst] Analyzing findings from 2 sources...

--- Final Output ---
Based on research across Google and Reddit:
1. Scavio ($0.005/query) - Multi-platform, good for agents
2. SerpAPI ($0.005/query) - Established, Google-focused
3. DataForSEO ($0.002/query) - Cheapest for volume

Crew complete. Search cost estimate: ~$0.020-0.040

相关教程

  • 如何构建具有预算控制的 LangGraph 搜索代理
  • 如何通过 MCP 将 Web 搜索添加到 Hermes 代理
  • 如何为搜索结果构建代理上下文桥

常见问题

大多数开发者在15到30分钟内完成本教程。您需要一个Scavio API密钥(免费套餐即可)和可用的Python或JavaScript环境。

Python 3.8+. 已安装crewai(pip安装crewai). 来自 scavio.dev 的 Scavio API 密钥. 船员的 LLM API 密钥. Scavio API密钥注册即送50个免费积分。

可以。免费套餐注册即送50个积分,完全足够完成本教程并构建一个可运行的原型解决方案。

Scavio提供原生LangChain包(langchain-scavio)、MCP服务器以及适用于任何HTTP客户端的REST API。本教程使用 the raw REST API, 但您可以根据需要适配您选择的框架。

相关资源

Best Of

2026年CrewAI智能体最佳搜索API

Read more
Use Case

CrewAI 搜索工具

Read more
Best Of

2026 年 CrewAI 智能体最佳搜索 API

Read more
Solution

用 Scavio 构建自定义 CrewAI 搜索工具

Read more
Use Case

OpenSEO 搭配 Scavio 数据后端

Read more
Glossary

CrewAI代理框架

Read more

开始构建

构建自定义 CrewAI BaseTool,通过 Scavio API 搜索 Google、Reddit、YouTube 和 Amazon。特工人员进行搜索和分析。

获取免费API密钥阅读文档
ScavioScavio

面向AI智能体的实时搜索API。搜索所有平台,不仅仅是Google。

产品

  • 功能
  • 定价
  • 控制台
  • 联盟计划

开发者

  • 文档
  • API参考
  • 快速开始
  • MCP集成
  • Python SDK

替代方案

  • Tavily替代方案
  • SerpAPI替代方案
  • Firecrawl替代方案
  • Exa替代方案

工具

  • JSON格式化
  • cURL转代码
  • Token计数器
  • 全部工具

© 2026 Scavio. 保留所有权利。

Featured on TAAFT
服务条款隐私政策