Dev.to AI 🤖 Ai 👁 2 📖 3 min read

Build a Live-Web Research Agent with LangChain, Thordata SERP and GPT

Models don't know what happened this week. They know a lot, and then they hit a cutoff date, and everything after that is guesswork. If you are building anything research-shaped — monitoring, digests, answering questions

Models don't know what happened this week. They know a lot, and then they hit a cutoff date, and everything after that is guesswork. If you are building anything research-shaped — monitoring, digests, answering questions about things that happened recently — the model is the easy part. Getting live search results into it, in a shape it can actually use, is the real work.

This post builds a small agent that does exactly that. It searches Google in real time through the Thordata SERP API, reads structured results, and answers with the sources it used. The Python side is about twenty lines, and the model behind it is swappable — the same code runs on OpenAI, DeepSeek or a local model.

What you need

An API key and two packages:

pip install langchain langchain-thordata
export THORDATA_API_KEY="your-api-key"        # Windows: set THORDATA_API_KEY=...

The langchain package provides the agent loop. langchain-thordata provides the search tool and talks to the SERP API for you.

The whole agent

from langchain.agents import create_agent
from langchain.chat_models import init_chat_model
from langchain_thordata import ThorDataSearchTool

# Any chat model works here. init_chat_model supports many providers,
# so swapping to DeepSeek or a local model is a one-line change.
model = init_chat_model("gpt-6.1-sol", model_provider="openai")

agent = create_agent(model, tools=[ThorDataSearchTool()])

result = agent.invoke({
    "messages": [{
        "role": "user",
        "content": "Find out what changed in Google's Search documentation this week. Search first, then summarize with links.",
    }]
})

print(result["messages"][-1].content)

Under the hood: the model decides it needs fresh information, calls the search tool, gets back structured organic results — title, link and snippet per row — reads them, and writes the answer. The reasoning trace comes back in the result object, so when an answer is wrong you can see exactly which search produced it.

Calling the tool directly

Sometimes you don't want an agent. Same package, no loop:

from langchain_thordata import ThorDataSearchTool

tool = ThorDataSearchTool()
result = tool.invoke({
    "query": "latest AI agent research",
    "engine": "google_news",
    "country": "us",
    "language": "en",
    "num": 5,
})
print(result)

This is the version to reach for in a pipeline step: fixed query, fixed engine, no decisions left to the model.

One API, a family of engines

Google is the default, and the tool accepts the rest of the engine family the API exposes: google_news for monitoring, google_shopping for price checks, plus google_local, google_images, google_videos, google_scholar and more. Same result shape, different slice of the results page — which is what lets one tool cover most research-shaped tasks. The full list is in the API reference.

The honest part: limits and batches

Whatever search provider you use, an agent that decides to search ten times in one task will find your quota faster than you expect. Three habits keep it boring:

Cap the number of searches per task in the prompt itself, so the model knows the budget. Retry with backoff on 429s instead of failing the whole run. And log every query the agent actually made — when an answer is wrong, the transcript of searches is the first thing you will want to read.

One more thing people hit late: batch size. A batch of five hundred short strings and a batch of twenty long paragraphs are not the same cost, and most per-request limiters cannot tell the difference. If you embed or scrape in batches, size them deliberately.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.