Vous pouvez donner une capacité de recherche web aux agents CrewAI en définissant un outil personnalisé BaseTool qui appelle l'API Scavio et en le passant à la liste d'outils de votre agent. L'agent décide quand appeler l'outil de recherche en fonction de la description de la tâche.
Prérequis
- Python 3.9+
- package crewai
- Clé API Scavio
- Clé API Anthropic
Parcours
Étape 1: Installer les dépendances
Installer CrewAI et les packages requis.
pip install crewai requestsÉtape 2: Définir l'outil de recherche Scavio
Sous-classer BaseTool pour créer un outil de recherche compatible avec CrewAI.
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."Étape 3: Définir les agents et les tâches
Créer un agent chercheur avec l'outil de recherche et un agent rédacteur qui synthétise les résultats.
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
)Étape 4: Créer les tâches et exécuter l'équipe
Définir les tâches pour chaque agent et exécuter l'équipe séquentiellement.
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)Exemple 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)Exemple 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.Sortie attendue
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.