If you're building AI agents in 2026, one thing becomes obvious pretty quickly: without real-time search, your agent is living in the past. LLMs have a knowledge cutoff, and no amount of prompt engineering can fix that.
The solution? Give your agent a search tool. In this tutorial, I'll walk you through building a LangChain agent that can search Google, Bing, or other search engines in real time using the TalorData SERP API. We'll keep it practical — complete code, explanations, and everything you need to run it yourself.
What We're Building
We'll create a ReAct-style agent that:
- Takes a user question in natural language
- Decides when it needs to search the web
- Calls the TalorData SERP API to fetch live search results
- Synthesizes the results into a coherent answer
The agent will use LangChain with TalorSerpTool from the langchain-talor-serp package.
Why TalorData?
Before we dive into code, let's talk about why I chose TalorData for this tutorial. According to a 1,009-query benchmark published in 2026, TalorData scored 79.19 overall, ranking first among six major SERP API providers including SerpApi, Bright Data, and Serper. It returned the largest number of organic rows (8,931) and had a zero-result rate of just 2.08%.
On the pricing side, TalorData offers 1,000 free requests upon sign-up with no credit card required. Paid plans start at $0.25 per 1,000 requests — significantly lower than incumbents like SerpApi at roughly $10 per 1,000 requests.
The langchain-talor-serp package supports 33 search engines in one tool, including Google, Bing, DuckDuckGo, Google News, Google Images, and more.
Prerequisites
Before we start, make sure you have:
- Python 3.9+
- An OpenAI API key (or any other LLM provider supported by LangChain)
- A TalorData API key (sign up at talordata.com — you get 1,000 free requests)
Step 1: Install Dependencies
Create a new project and install the required packages:
pip install langchain langchain-openai langchain-talor-serp python-dotenv
The langchain-talor-serp package provides LangChain tools for TalorData's SERP APIs, enabling your AI agents to search with geo-targeting and language customization.
Step 2: Set Up Environment Variables
Create a .env file in your project root:
OPENAI_API_KEY=your-openai-api-key
TALOR_API_KEY=your-talordata-api-key
Then load them in your Python script:
import os
from dotenv import load_dotenv
load_dotenv()
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
os.environ["TALOR_API_KEY"] = os.getenv("TALOR_API_KEY")
Step 3: Create the Search Tool (Modern Approach)
The langchain-talor-serp package gives us a clean wrapper around the TalorData API. Here's the recommended way to set it up using LangChain's modern tool-calling approach:
from langchain_talor_serp import TalorSerpTool
from langchain_openai import ChatOpenAI
# Initialize the LLM
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
# Create the search tool from environment variables
tool = TalorSerpTool.from_env()
# Bind the tool to the LLM for tool calling
model_with_tools = llm.bind_tools([tool])
# Now the model can call the search tool
response = model_with_tools.invoke("Search for the latest LangChain news")
print(response)
This is the modern LangChain approach — using bind_tools() instead of the older create_react_agent pattern.
Step 4: Using the Search Tool Directly
You can also invoke the search tool directly with specific parameters:
from langchain_talor_serp import TalorSerpTool
search_tool = TalorSerpTool.from_env()
result = search_tool.invoke({
"query": "LangChain tutorial 2026",
"engine": "google",
"params": {
"gl": "us", # country
"hl": "en", # language
"device": "desktop",
},
})
print(result)
The search parameters include:
-
query: required — the search query text -
engine: optional — engine key likegoogle_news,google_images,bing,duckduckgo -
params: optional — engine-specific parameter object
Common params fields include gl (country), hl (language), device, location, and no_cache.
You can also pass params as a JSON string when the parameter object is generated by a model tool call:
result = search_tool.invoke({
"query": "LangChain tutorial",
"engine": "google",
"params": "{\"hl\": \"zh-CN\", \"gl\": \"cn\"}",
})
Step 5: Build a Complete Agent with ReAct
If you prefer the classic ReAct agent pattern, here's how to set it up:
import os
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from langchain.agents import create_react_agent, AgentExecutor
from langchain_talor_serp import TalorSerpTool
from langchain_core.prompts import PromptTemplate
load_dotenv()
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
os.environ["TALOR_API_KEY"] = os.getenv("TALOR_API_KEY")
def create_search_agent():
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
search_tool = TalorSerpTool.from_env()
prompt = PromptTemplate.from_template("""
You are a helpful AI assistant with access to a search engine.
You have access to the following tool:
- search: use this tool to search the web for real-time information
To use a tool, respond with:
Thought: I need to search for [your query]
Action: search
Action Input: {{"query": "your search query", "engine": "google"}}
When you have the final answer, respond with:
Thought: I now have the information I need
Final Answer: [your complete answer]
Question: {input}
{agent_scratchpad}
""")
agent = create_react_agent(llm=llm, tools=[search_tool], prompt=prompt)
return AgentExecutor(agent=agent, tools=[search_tool], verbose=True, handle_parsing_errors=True)
if __name__ == "__main__":
agent = create_search_agent()
questions = [
"What's the current state of the SERP API market in 2026?",
"Who are the main competitors to TalorData in the SERP API space?"
]
for q in questions:
print(f"\n{'='*50}")
print(f"Q: {q}")
print(f"{'='*50}")
response = agent.invoke({"input": q})
print(f"A: {response['output']}")
Step 6: Query History (Bonus)
The package also provides a history tool to fetch SERP request history with filters:
from langchain_talor_serp import TalorSerpTool
history_tool = TalorSerpTool.history_from_env()
result = history_tool.invoke({
"page": 1,
"page_size": 20,
"search_query": "langchain",
"search_engine": "google",
"status": "success",
"timezone": "Asia/Shanghai",
})
print(result)
History parameters include:
-
page: page number, defaults to 1 -
page_size: page size, defaults to 20 -
search_query: optional keyword filter -
search_engine: optional engine filter such asbing -
status:all,success, orerror -
start_time: optional Unix timestamp in seconds -
end_time: optional Unix timestamp in seconds -
timezone: optional timezone header such asAsia/Shanghaior+08:00
Step 7: Usage Statistics (Bonus)
To monitor your API usage, use the statistics tool:
from langchain_talor_serp import TalorSerpTool
statistics_tool = TalorSerpTool.statistics_from_env()
result = statistics_tool.invoke({
"start_date": "2026-06-01",
"end_date": "2026-06-05",
"engines": "google,bing",
})
print(result)
What About Cost?
One of the nice things about this setup is cost transparency. TalorData uses a 1:1 billing model — one request, one credit. No hidden multipliers. And if your credits expire, buying any new plan automatically restores the expired credits, so your prior spend isn't wasted.
For most development and testing, the 1,000 free requests will take you quite far. Each search in our agent counts as one request.
Common Pitfalls
Missing API keys: Make sure both
OPENAI_API_KEYandTALOR_API_KEYare set in your environment.Engine parameter: If you don't specify an engine, the tool uses a default. For production, explicitly set
engineto avoid surprises.Rate limits: TalorData rejects requests beyond your quota rather than billing you for overage. This is actually a good thing — no surprise charges.
JSON string for params: When
paramscomes from a model tool call, it may be a JSON string. The SDK accepts both dict and string formats.
Next Steps
Once you have the basic agent running, consider:
- Adding multiple search tools (Google, Bing, DuckDuckGo) and letting the agent choose
- Implementing a caching layer to reduce repeated searches
- Adding the history tool to let the agent reflect on past searches
- Deploying the agent with LangGraph for more complex workflows
Final Thoughts
Building an AI agent with real-time search capabilities doesn't have to be expensive or complicated. With LangChain's bind_tools() approach and TalorData's SERP API, you can have a working agent in minimal code. The key is giving your agent the right tools — and a search tool is arguably the most important one you can add.
Have you built an AI agent with web search capabilities? What other tools have you integrated? Drop a comment below — I'd love to hear about your experience.
Question for the community: What's the most creative use case you've built (or want to build) for a search-enabled AI agent? Share your ideas in the comments!
Top comments (0)