LLM은 학습 컷오프 시점에 고정되어 있어 최근 사실을 환각합니다. 에이전트에 Google 검색 도구를 제공하면 두 문제가 모두 해결됩니다 — 그리고 serp.cheap 같은 저렴한 동기식 SERP API는 지연 시간이 예측 가능하고 호출당 비용이 에이전트 규모로 실행할 만큼 낮기 때문에 이상적인 백엔드입니다.
검색 도구 (일반 함수)
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 도구 호출 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이 에이전트에 적합한 이유
- 동기식 ~2초 응답 — 도구 호출 내부에서 조율할 비동기 큐가 없습니다.
- 대규모에서도 저렴함 — 에이전트는 많은 검색을 펼칩니다. 호출당 $0.0006(절반은 캐시)로 실행 비용을 감당할 수 있습니다.
- 실제 google.com + 인용 — 블랙박스 색인이 아니라 모델이 인용할 수 있는 링크를 반환합니다.