LLMs sind auf ihren Trainings-Stichtag eingefroren und halluzinieren aktuelle Fakten. Einem Agenten ein Google-Such-Tool zu geben, behebt beides — und eine günstige, synchrone SERP API wie serp.cheap ist das ideale Backend, weil die Latenz vorhersehbar und die Kosten pro Aufruf niedrig genug für den Agenten-Maßstab sind.
Das Such-Tool (einfache Funktion)
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"]
)
Mit der 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.
Mit 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.
Warum serp.cheap zu Agenten passt
- Synchrone ~2s-Antworten — keine asynchrone Warteschlange, die du innerhalb eines Tool-Calls orchestrieren musst.
- Günstig im großen Maßstab — Agenten verteilen viele Suchen; $0.0006/Aufruf (zur Hälfte aus dem Cache) hält die Läufe bezahlbar.
- Echtes google.com + Quellenangaben — gib Links zurück, die das Modell zitieren kann, keinen Blackbox-Index.