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.
pip install crewai requestsStep 2: Define the Scavio search tool
Subclass BaseTool to create a CrewAI-compatible search tool.
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.
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.
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
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
// 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
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.