DEV Community

talor
talor

Posted on

LlamaIndex + TalorData SERP API: Build AI Agents That Search the Live Web 🚀

Large language models are great at reasoning, but they have one fundamental limitation: they don‘t know what’s happening right now. Ask about today‘s news, and they’ll either hallucinate or politely decline.

LlamaIndex is one of the most powerful frameworks for building RAG applications and AI agents. But even the best RAG pipeline is only as good as its data sources — and if your data is static, your answers are outdated.

The fix? Give your LlamaIndex agent a real-time search tool.

In this tutorial, I‘ll show you how to integrate TalorData SERP API with LlamaIndex in under 30 minutes. By the end, you’ll have an agent that can search Google, Bing, Yandex, and DuckDuckGo — and use the results to answer questions with real-time data.

What We‘re Building

A LlamaIndex agent that:

  1. Receives a user query (e.g., “What are the latest trends in AI search?”)
  2. Automatically decides whether it needs to search the web
  3. Calls the TalorData SERP API to fetch structured search results
  4. Synthesizes the results into a coherent, well-sourced answer

Prerequisites

  • Python 3.9+
  • A TalorData API key (sign up for free — 1,000 free requests)
  • An OpenAI API key (or any LLM supported by LlamaIndex)
  • Basic familiarity with LlamaIndex

Step 1: Install Dependencies

pip install llama-index-core llama-index-llms-openai talordata-serp python-dotenv
Enter fullscreen mode Exit fullscreen mode

Step 2: Set Up Environment Variables

Create a .env file:

OPENAI_API_KEY=your-openai-api-key
TALORDATA_API_KEY=your-talordata-api-key
Enter fullscreen mode Exit fullscreen mode

Step 3: Create the Search Tool

LlamaIndex provides FunctionTool, which can turn any Python function into a tool that an agent can use. Here‘s how we wrap the TalorData search function:

import os
import json
from dotenv import load_dotenv
from llama_index.core.tools import FunctionTool
from talordata_serp import TalorClient

load_dotenv()

client = TalorClient(api_key=os.environ["TALORDATA_API_KEY"])

def search_web(query: str, engine: str = "google", num_results: int = 5) -> str:
    """
    Search the web using TalorData SERP API.

    Args:
        query: The search query string
        engine: Search engine to use (google, bing, yandex, duckduckgo)
        num_results: Number of results to return (max 10)

    Returns:
        JSON string containing search results with titles, links, and snippets
    """
    try:
        response = client.search(
            q=query,
            engine=engine,
            num=num_results,
            json=2  # Structured JSON output
        )

        results = []
        for item in response.get("organic_results", [])[:num_results]:
            results.append({
                "title": item.get("title", ""),
                "link": item.get("link", ""),
                "snippet": item.get("snippet", "")
            })

        return json.dumps(results, indent=2)

    except Exception as e:
        return json.dumps({"error": str(e)})

# Create the tool
search_tool = FunctionTool.from_defaults(
    fn=search_web,
    name="web_search",
    description="Search the web for real-time information using Google, Bing, Yandex, or DuckDuckGo."
)
Enter fullscreen mode Exit fullscreen mode

Step 4: Build the LlamaIndex Agent

Now we create an agent that can use this tool

from llama_index.core.agent import ReActAgent
from llama_index.llms.openai import OpenAI

# Initialize the LLM
llm = OpenAI(model="gpt-4o-mini", temperature=0)

# Create the agent with our search tool
agent = ReActAgent.from_tools(
    tools=[search_tool],
    llm=llm,
    verbose=True,
    system_prompt=(
        "You are a helpful research assistant. When a user asks about current events, "
        "recent information, or anything that requires up-to-date knowledge, use the "
        "web_search tool to find the information. Base your answers on the search results."
    )
)
Enter fullscreen mode Exit fullscreen mode

Step 5: Test It

response = agent.chat("What are the latest developments in AI-powered search engines in 2026?")
print(response)
Enter fullscreen mode Exit fullscreen mode

The agent will:

  1. Recognize that it needs current information
  2. Call web_search with the appropriate query
  3. Receive structured JSON results
  4. Synthesize a well-sourced answer

How It Works Under the Hood

Step What Happens
1 User asks a question that requires current data
2 LlamaIndex agent evaluates the query and decides to use the web_search tool
3 The tool calls TalorData SERP API with the query parameters
4 TalorData returns structured JSON from the specified search engine
5 The agent synthesizes the results into a natural language answer

Why TalorData SERP API?

TalorData is designed specifically for AI applications that need reliable, real-time search data:

  • One API for Google, Bing, Yandex, and DuckDuckGo — no need for multiple integrations
  • Structured JSON output — no HTML parsing, ready for LLM consumption
  • Pay-per-success billing — you only pay when you get data back
  • P90 latency under 1 second — built for real-time AI workloads
  • Native LlamaIndex support — official integration resources available

What You Can Build

Use Case Description
Real-time research assistant Answers questions with up-to-date web data
Competitive intelligence agent Monitors competitor rankings and mentions
News summarization bot Fetches and summarizes latest news on any topic
SEO monitoring tool Tracks keyword positions automatically
Market research agent Gathers current market intelligence

Cost

At $1.00 per 1,000 requests (down to $0.25/1K at volume), most applications cost just a few dollars per month.

Get Started

The complete integration takes less than 30 minutes.

👉 Try TalorData SERP API — 1,000 free requests, no credit card required.

Have questions? Drop a comment below! 👇

Top comments (0)