LLM’s zijn bevroren op hun training-cutoff en hallucineren over recente feiten. Een agent een Google-search-tool geven lost beide op — en een goedkope, synchrone SERP API zoals serp.cheap is de ideale backend omdat de latency voorspelbaar is en de kosten per aanroep laag genoeg zijn om op agent-schaal te draaien.
De search-tool (gewone functie)
import requests
def google_search(query: str, country: str = "us") -> str:
"""Search Google and return the top results as text."""
data = requests.post(
"https://api.serp.cheap/v1/search",
headers={"X-API-Key": "YOUR_KEY"},
json={"q": query, "gl": country},
timeout=30,
).json()
return "\n".join(
f'{r["position"]}. {r["title"]} — {r["link"]}\n {r.get("snippet","")}'
for r in data["organic"]
)
Met de OpenAI tool-calling API
tools = [{
"type": "function",
"function": {
"name": "google_search",
"description": "Search Google for up-to-date information.",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string"},
"country": {"type": "string", "default": "us"},
},
"required": ["query"],
},
},
}]
# When the model calls google_search, run the function above and return its
# output as the tool result, then let the model answer with citations.
Met LangChain
from langchain.tools import Tool
search_tool = Tool(
name="google_search",
description="Search Google for current information.",
func=lambda q: google_search(q),
)
# Add search_tool to your agent's tool list.
Waarom serp.cheap past bij agents
- Synchroon ~2s responstijden — geen async wachtrij om te orkestreren binnen een tool call.
- Goedkoop op schaal — agents sturen veel zoekopdrachten uit; $0.0006/aanroep (half gecachet) houdt runs betaalbaar.
- Echte google.com + bronvermeldingen — geef links terug die het model kan citeren, geen black-box index.