LLMs अपने ट्रेनिंग कटऑफ़ पर जमे हुए हैं और हाल के तथ्यों के बारे में मतिभ्रम करते हैं। किसी एजेंट को एक Google search tool देना दोनों को ठीक करता है — और serp.cheap जैसा एक सस्ता, सिंक्रोनस SERP API आदर्श बैकएंड है क्योंकि latency पूर्वानुमेय है और प्रति-कॉल लागत एजेंट स्केल पर चलाने के लिए पर्याप्त कम है।
सर्च टूल (सादा function)
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"]
)
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.
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.
serp.cheap एजेंट्स के लिए क्यों उपयुक्त है
- सिंक्रोनस ~2s रिस्पॉन्स — एक tool call के अंदर ऑर्केस्ट्रेट करने के लिए कोई async कतार नहीं।
- स्केल पर सस्ता — एजेंट कई सर्च में फैल जाते हैं; $0.0006/call (आधा कैश्ड) रन को किफ़ायती रखता है।
- असली google.com + उद्धरण — मॉडल जिन लिंक को उद्धृत कर सकता है उन्हें लौटाएं, न कि कोई ब्लैक-बॉक्स इंडेक्स।