ScavioScavio
ProductPricingDocs
Sign InGet Started
  1. Home
  2. Tutorials
  3. How to Integrate a Search API with CrewAI
Tutorial

How to Integrate a Search API with CrewAI

Create a Scavio search tool for CrewAI agents. Includes tool definition, agent configuration, and a crew execution example with Python.

Get Free API KeyAPI Docs

You can give CrewAI agents web search capability by defining a custom BaseTool that calls the Scavio API and passing it to your agent's tools list. The agent decides when to call the search tool based on the task description.

Prerequisites

  • Python 3.9+
  • crewai package
  • Scavio API key
  • Anthropic API key

Walkthrough

Step 1: Install dependencies

Install CrewAI and required packages.

Bash
pip install crewai requests

Step 2: Define the Scavio search tool

Subclass BaseTool to create a CrewAI-compatible search tool.

Python
import requests
from crewai.tools import BaseTool
from pydantic import Field

SCAVIO_KEY = "your-scavio-api-key"

class ScavioSearchTool(BaseTool):
    name: str = "web_search"
    description: str = (
        "Search the web for current information. "
        "Input: a search query. Returns top 5 results with titles, snippets, and URLs. "
        "Use this for any question requiring recent or factual data."
    )

    def _run(self, query: str) -> str:
        r = requests.post(
            "https://api.scavio.dev/api/v1/search",
            json={"query": query, "num_results": 5},
            headers={"x-api-key": SCAVIO_KEY},
            timeout=15
        )
        r.raise_for_status()
        results = r.json().get("organic_results", [])
        return "\n\n".join(
            f"{res['title']}\n{res.get('snippet','')}\n{res['link']}"
            for res in results[:5]
        ) or "No results found."

Step 3: Define agents and tasks

Create a researcher agent with the search tool and a writer agent that synthesizes findings.

Python
from crewai import Agent, Task, Crew, Process
import os

os.environ["ANTHROPIC_API_KEY"] = "your-anthropic-key"

search_tool = ScavioSearchTool()

researcher = Agent(
    role="Research Analyst",
    goal="Find accurate, current information on the topic using web search",
    backstory="You are an expert researcher who always verifies facts with live search.",
    tools=[search_tool],
    llm="claude-sonnet-4-6",
    verbose=False
)

writer = Agent(
    role="Technical Writer",
    goal="Synthesize research findings into a clear, structured report",
    backstory="You turn raw research into clear, actionable summaries.",
    llm="claude-sonnet-4-6",
    verbose=False
)

Step 4: Create tasks and run the crew

Define tasks for each agent and run the crew sequentially.

Python
TOPIC = "vector databases comparison 2026"

research_task = Task(
    description=f"Research '{TOPIC}'. Search for: current top options, pricing, and use cases. Collect at least 3 data points.",
    expected_output="A list of key findings with source URLs",
    agent=researcher
)

write_task = Task(
    description="Write a 3-paragraph summary of the research findings. Include a recommendation.",
    expected_output="A 3-paragraph summary with a final recommendation",
    agent=writer,
    context=[research_task]
)

crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, write_task],
    process=Process.sequential
)

result = crew.kickoff()
print(result.raw)

Python Example

Python
import requests
import os
from crewai import Agent, Task, Crew, Process
from crewai.tools import BaseTool

SCAVIO_KEY = "your-scavio-api-key"
os.environ["ANTHROPIC_API_KEY"] = "your-anthropic-key"

class ScavioSearchTool(BaseTool):
    name: str = "web_search"
    description: str = "Search the web. Input: search query. Returns top 5 results."

    def _run(self, query: str) -> str:
        r = requests.post("https://api.scavio.dev/api/v1/search",
                          json={"query": query, "num_results": 5},
                          headers={"x-api-key": SCAVIO_KEY}, timeout=15)
        r.raise_for_status()
        items = r.json().get("organic_results", [])
        return "\n\n".join(f"{i['title']}\n{i.get('snippet','')}\n{i['link']}" for i in items[:5]) or "No results."

if __name__ == "__main__":
    search_tool = ScavioSearchTool()
    researcher = Agent(role="Researcher", goal="Find current facts via web search",
                       backstory="Expert researcher.", tools=[search_tool], llm="claude-sonnet-4-6")
    writer = Agent(role="Writer", goal="Write clear summaries",
                   backstory="Technical writer.", llm="claude-sonnet-4-6")

    topic = "best search APIs for AI agents in 2026"
    t1 = Task(description=f"Research: {topic}", expected_output="Key findings with sources", agent=researcher)
    t2 = Task(description="Summarize findings in 3 paragraphs with recommendation.",
              expected_output="3-paragraph summary", agent=writer, context=[t1])

    crew = Crew(agents=[researcher, writer], tasks=[t1, t2], process=Process.sequential)
    result = crew.kickoff()
    print(result.raw)

JavaScript Example

JavaScript
// CrewAI is Python-only. Use LangChain JS for a similar pattern in Node.js.
// See: how-to-connect-scavio-to-langchain-rag for the JS equivalent.

Expected Output

JSON
Researcher found 5 sources on vector databases. Key findings:
- Pinecone: serverless, $0.033/1M reads, best for production scale
- Weaviate: open source, hybrid search, active community
- Qdrant: fastest for high-dimensional vectors, Rust-based

Writer summary:
Vector databases have matured significantly in 2026. Three options dominate: Pinecone for managed scale, Qdrant for performance, and pgvector for teams already on PostgreSQL. Pricing varies from free tiers to $0.033/1M vector reads...

Recommendation: Start with pgvector if on PostgreSQL, migrate to Qdrant or Pinecone when you hit performance limits.

Related Tutorials

  • How to Connect Scavio to LangChain RAG
  • How to Build a Multi-Source Research Agent
  • How to Set Up RAG with Search Instead of Vectors

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

Python 3.9+. crewai package. Scavio API key. Anthropic API key. A Scavio API key gives you 50 free credits on signup.

Yes. The free tier includes 50 credits on signup, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Related Resources

Use Case

Pi Coding Agent Web Search Integration

Read more
Best Of

Best Search API for CrewAI Agents in 2026

Read more
Use Case

CrewAI Search Tool

Read more
Best Of

Best Search API for CrewAI in 2026

Read more
Solution

Add Unified Search to Multi-Agent Systems with Scavio

Read more
Solution

One Search Tool for Any AI Agent Framework

Read more

Start Building

Create a Scavio search tool for CrewAI agents. Includes tool definition, agent configuration, and a crew execution example with Python.

Get Free API KeyRead the Docs
ScavioScavio

Real-time search API for AI agents. Search every platform, not just Google.

Product

  • Features
  • Pricing
  • Dashboard
  • Affiliates

Developers

  • Documentation
  • API Reference
  • Quickstart
  • MCP Integration
  • Python SDK

Alternatives

  • Tavily Alternative
  • SerpAPI Alternative
  • Firecrawl Alternative
  • Exa Alternative

Tools

  • JSON Formatter
  • cURL to Code
  • Token Counter
  • All Tools

© 2026 Scavio. All rights reserved.

Featured on TAAFT
Terms of ServicePrivacy Policy