---
source_url: "https://www.serphouse.com/use-cases/langchain-llamaindex-integration?utm_source=openai"
title: "SERPHouse LangChain Integration | Web Search Tool for LLM Agents - SERPHouse"
mirrored_at: 2026-08-07T01:39:33.293Z
host: www.serphouse.com
cited_in_42a: true
mirror_canonical: "https://index.42a.ai/www.serphouse.com/use-cases/langchain-llamaindex-integration__q__utm_source_openai"
---

> **Original source:** https://www.serphouse.com/use-cases/langchain-llamaindex-integration?utm_source=openai

LangChain & LlamaIndex Integration

## Web Search Tool for LangChain  
and LlamaIndex

Add live web search to your LangChain agent or LlamaIndex pipeline in under 10 minutes. Drop-in BaseTool subclass. Zero extra dependencies beyond requests.

50M+

API requests served

99.9%

Uptime SLA

100+

Countries supported

<5s

Median response time

Capabilities

## What you can build with SERPHouse and LangChain

One REST endpoint. Structured JSON. Works with every major Python agent framework.

LangChain BaseTool

Subclass BaseTool in 15 lines. Pass it to AgentExecutor and your agent instantly has live web search. Works with all LangChain agent types.

LlamaIndex Reader

Implement a custom reader that returns Document objects. Drop into any LlamaIndex query engine, retriever, or RAG pipeline.

LangGraph Tool Node

Define as a standard tool node in LangGraph state machines. Reuse the same tool definition across any graph-based agent workflow.

LCEL Compatible

Wrap as a Runnable in LangChain Expression Language (LCEL) chains. Pipe search results directly into your prompt templates.

Async Python Support

Full async implementation with aiohttp or httpx. Run parallel searches in a single agent turn without blocking the event loop.

Framework Agnostic Core

The REST API works with AutoGen, CrewAI, Haystack, Semantic Kernel, and any custom agent. Not just LangChain.

How It Works

## From API key to live web search in 4 steps

The [SERPHouse Web Search API](https://www.serphouse.com/web-search-api) integrates into LangChain and LlamaIndex using standard Python patterns. No custom SDK. No complex configuration.

1

Get your SERPHouse API key

Sign up free. No credit card. Copy the key from your dashboard.

2

Subclass BaseTool (LangChain) or BaseReader (LlamaIndex)

Implement the `_run` method to call the SERPHouse REST API. 15 lines of Python.

3

Pass the tool to your agent executor

Add it to the tools list in `AgentExecutor.from_agent_and_tools()` or `create_openai_tools_agent()`.

4

Agent searches when needed

The LLM decides when to call the tool. Results return as structured text the model uses as context.

Why a custom tool vs. built-in search tools

Feature

SERPHouse

Built-in Google

Setup complexity

REST API key

Google API + CSE setup

Output format

Structured JSON

Unstructured text

Search engines

Google + Bing + Yahoo

Google only

Country targeting

100+ countries

Limited

Production SLA

99.9% uptime

Quota limits

LangChain's built-in Google Search wrapper requires a Google Custom Search API key, hits strict free-tier quotas, and returns unstructured text your LLM must parse. SERPHouse gives structured JSON (including `position`, `title`, `link`, and `snippet`) ready to drop into context.

Code Examples

## LangChain and LlamaIndex integration code

Complete, runnable examples. Subclass BaseTool for LangChain agents, BaseReader for LlamaIndex pipelines, or call the REST endpoint directly from any Python framework.

`BaseTool._run` · LangChain: 15 lines of Python

`BaseReader.load_data` · LlamaIndex: returns Document objects

`results.organic[]` · title, link, snippet per result

from langchain.tools import BaseTool
from pydantic import BaseModel, Field
import requests
from typing import Optional

class WebSearchInput(BaseModel):
    query: str = Field(description="The search query to look up on the web")
    num\_result: Optional\[int\] = Field(
        default=5,
        description="Number of results to return (1-10)"
    )

class SERPHouseSearchTool(BaseTool):
    name: str = "web\_search"
    description: str = (
        "Search the live web for current information, recent events, "
        "and up-to-date facts. Use this when your knowledge may be "
        "outdated or when you need to verify current information."
    )
    args\_schema: type\[BaseModel\] = WebSearchInput

    def \_run(self, query: str, num\_results: int = 5) -> str:
        response = requests.get(
            "https://api.serphouse.com/serp/live",
            headers={"Authorization": "Bearer YOUR\_API\_KEY"},
            params={
                "q": query,
                "loc": "United+States",
                "num\_result": 10
            }
        )
        results = response.json()\["results"\]\["organic"\]
        return "\\n\\n".join(\[
            f"{r\['position'\]}. {r\['title'\]}\\n{r\['snippet'\]}\\nURL: {r\['link'\]}"
            for r in results
        \])

from langchain.agents import AgentExecutor, create\_openai\_tools\_agent
from langchain\_openai import ChatOpenAI
from langchain import hub

llm = ChatOpenAI(model="gpt-4o", temperature=0)
tools = \[SERPHouseSearchTool()\]
prompt = hub.pull("hwchase17/openai-tools-agent")
agent = create\_openai\_tools\_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

result = executor.invoke({
    "input": "What are the most popular AI agent frameworks in 2025?"
})
print(result\["output"\])

from llama\_index.core import Document
from llama\_index.core.readers.base import BaseReader
import requests

class SERPHouseReader(BaseReader):
    """LlamaIndex reader that fetches live web search results as Documents."""

    def \_\_init\_\_(self, api\_key: str, num\_result: int = 5):
        self.api\_key = api\_key
        self.num\_result = num\_results

    def load\_data(self, query: str) -> list\[Document\]:
        response = requests.get(
            "https://api.serphouse.com/serp/live",
            headers={"Authorization": f"Bearer {self.api\_key}"},
            params={
                "q": query,
                "loc": "United+States",
                "num\_result": self.num\_results
            }
        )
        results = response.json()\["results"\]\["organic"\]
        return \[
            Document(
                text=r\["snippet"\],
                metadata={
                    "title": r\["title"\],
                    "url": r\["url"\],
                    "position": r\["position"\],
                    "snippet": r\["snippet"\]
                }
            )
            for r in results
        \]

from llama\_index.core import VectorStoreIndex

reader = SERPHouseReader(api\_key="YOUR\_API\_KEY")
documents = reader.load\_data("latest developments in AI agents 2025")
index = VectorStoreIndex.from\_documents(documents)
query\_engine = index.as\_query\_engine()
response = query\_engine.query(
    "What are developers using to build AI agents?"
)

[Try it live in the API Playground →](https://www.serphouse.com/serp-api-playground)

Why SERPHouse

## Production-ready web search. Not a prototype workaround.

LangChain's built-in search integrations often require separate API credentials, hit free tier quotas, and return unstructured text. SERPHouse gives you structured JSON per result, 100+ country support, Google + Bing + Yahoo in one endpoint, and a production SLA, so the tool your agent relies on doesn't become its reliability bottleneck.

![check](https://www.serphouse.com/images/homePage/serp-description-icon.png)

BaseTool in 15 lines, with no complex setup or extra dependencies.

![check](https://www.serphouse.com/images/homePage/serp-description-icon.png)

Structured JSON: `title`, `link`, `snippet` per result, with no post-processing.

![check](https://www.serphouse.com/images/homePage/serp-description-icon.png)

Works with LCEL, AgentExecutor, LangGraph, and ReAct agents.

![check](https://www.serphouse.com/images/homePage/serp-description-icon.png)

LlamaIndex compatible: `BaseReader` returns `Document` objects natively.

![check](https://www.serphouse.com/images/homePage/serp-description-icon.png)

99.9% uptime SLA, so your agent tool stays available when your users need it.

LangChain AgentExecutor

Works with `create_openai_tools_agent`, `initialize_agent`, and ReAct agents. The same tool definition works across all executor types.

LangGraph

Register as a ToolNode in any graph. Same tool definition, any workflow topology,ReAct-style loops, parallel branches, or conditional routing between nodes.

LlamaIndex

Custom `BaseReader` returns `Document` objects for any query engine or RAG pipeline. Results include `title`, `link`, and `position` in metadata.

FAQ

## Frequently asked questions

Common questions about integrating SERPHouse with LangChain, LlamaIndex, and LangGraph.

## Add web search to your LangChain agent today

Free tier available. No credit card. Your BaseTool calls the live web in under 10 minutes.

Need a custom plan or enterprise volume? [Talk to our team →](https://www.serphouse.com/enterprise-custom-plan-offering)

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.