Tutorial

How to Add Web Search to an OpenClaw Agent

Configure web search for OpenClaw agents using a structured search API. Give your agent live SERP data without scraping or browser automation.

OpenClaw agents need real-time web data to ground their responses and avoid hallucination. The default approach of scraping websites from within the agent is unreliable and slow. A structured search API returns clean JSON that the agent can parse directly without HTML processing. This tutorial shows how to configure an OpenClaw agent with a Scavio search tool that returns organic results, AI Overviews, and People Also Ask data. You will build a search-grounded agent that queries live web data on demand.

Prerequisites

  • OpenClaw installed and running
  • A Scavio API key from scavio.dev
  • Python 3.8+ installed

Walkthrough

Step 1: Create the search tool function

Define a tool that calls the Scavio API and returns structured results for the agent.

Python
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", {}),
    }

Step 2: Register the tool with OpenClaw

Add the search tool to the agent's tool registry so it can be called during conversations.

Python
# 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,
}

Step 3: Configure the agent to use search

Set up the agent prompt to prefer search-grounded responses over guessing.

Python
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
"""

Step 4: Test the integration

Run a query through the agent and verify it uses the search tool.

Python
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']}")

Python Example

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",""))

JavaScript Example

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))
);

Expected Output

JSON
An OpenClaw agent with a web search tool that returns structured SERP data, enabling grounded responses with real source citations.

Related Tutorials

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.

OpenClaw installed and running. A Scavio API key from scavio.dev. Python 3.8+ installed. A Scavio API key gives you 250 free credits per month.

Yes. The free tier includes 250 credits per month, 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.

Start Building

Configure web search for OpenClaw agents using a structured search API. Give your agent live SERP data without scraping or browser automation.