Los agentes de OpenClaw necesitan datos web en tiempo real para fundamentar sus respuestas y evitar alucinaciones. El método predeterminado de raspar sitios web desde el agente no es confiable y es lento. Una API de búsqueda estructurada devuelve JSON limpio que el agente puede analizar directamente sin procesamiento HTML. Este tutorial muestra cómo configurar un agente OpenClaw con una herramienta de búsqueda Scavio que devuelve resultados orgánicos, descripciones generales de IA y datos de personas que también preguntan. Creará un agente basado en búsquedas que consulte datos web en vivo bajo demanda.
Requisitos previos
- OpenClaw instalado y ejecutándose
- Una clave API de Scavio de scavio.dev
- Python 3.8+ instalado
Guia paso a paso
Paso 1: Crear la función de herramienta de búsqueda
Defina una herramienta que llame a la API de Scavio y devuelva resultados estructurados para el agente.
import os, requests
API_KEY = os.environ["SCAVIO_API_KEY"]
def web_search(query: str) -> dict:
"""Search the web and return structured results."""
resp = requests.post("https://api.scavio.dev/api/v1/search",
headers={"x-api-key": API_KEY},
json={"platform": "google", "query": query})
data = resp.json()
return {
"results": [{"title": r["title"], "snippet": r.get("snippet",""), "url": r.get("link","")}
for r in data.get("organic_results", [])[:5]],
"ai_overview": data.get("ai_overview", {}),
}Paso 2: Registre la herramienta con OpenClaw
Agregue la herramienta de búsqueda al registro de herramientas del agente para que pueda ser llamada durante las conversaciones.
# Register web_search as an OpenClaw tool
# The agent will call this tool when it needs current information
# Tool schema:
# name: web_search
# description: Search the web for current information
# parameters: query (string) - the search query
tool_config = {
"name": "web_search",
"description": "Search the web for current information",
"function": web_search,
}Paso 3: Configurar el agente para utilizar la búsqueda
Configure el mensaje del agente para que prefiera las respuestas basadas en búsquedas a las conjeturas.
agent_instructions = """
When asked about current events, products, prices, or facts:
1. Use the web_search tool to find current information
2. Cite sources from the search results
3. If AI Overview data is available, include it
4. Never guess or fabricate information
"""Paso 4: Probar la integración
Ejecute una consulta a través del agente y verifique que utilice la herramienta de búsqueda.
result = web_search("best open source LLM frameworks 2026")
for r in result["results"]:
print(f"{r['title']}")
print(f" {r['snippet'][:100]}")
print(f" {r['url']}")Ejemplo en Python
import os, requests
API_KEY = os.environ["SCAVIO_API_KEY"]
def search(query):
resp = requests.post("https://api.scavio.dev/api/v1/search",
headers={"x-api-key": API_KEY},
json={"platform": "google", "query": query})
return resp.json().get("organic_results", [])[:5]
for r in search("best open source LLM frameworks 2026"):
print(r["title"], r.get("link",""))Ejemplo en JavaScript
const H = {"x-api-key": process.env.SCAVIO_API_KEY, "Content-Type": "application/json"};
async function search(query) {
const r = await fetch("https://api.scavio.dev/api/v1/search", {
method: "POST", headers: H,
body: JSON.stringify({platform: "google", query})
});
return (await r.json()).organic_results || [];
}
search("best open source LLM frameworks 2026").then(rs =>
rs.slice(0,5).forEach(r => console.log(r.title))
);Salida esperada
An OpenClaw agent with a web search tool that returns structured SERP data, enabling grounded responses with real source citations.