🦜LangChain Integration

LangChain Proxy SetupWeb tools and agents with mobile IPs

LangChain is the most popular framework for building LLM applications. Its web browsing tools, search integrations, and agent capabilities all benefit from mobile proxy infrastructure for reliable, unblocked access.

LangChain Web Tools

  • Web search (Google, Bing, DuckDuckGo)
  • URL loaders and web scrapers
  • Document loaders from web sources
  • API integrations and data retrieval

LangChain Tools That Need Proxies

These LangChain components make web requests and benefit from mobile proxy routing.

Search Tools

GoogleSearchAPIWrapper, DuckDuckGoSearchRun, BingSearchAPIWrapper

Search engines rate-limit and block automated queries. Mobile IPs appear as real users.

Web Loaders

WebBaseLoader, AsyncHtmlLoader, PlaywrightURLLoader

Websites block datacenter IPs. Mobile proxies ensure reliable page loading.

URL Utilities

RequestsGetTool, RequestsPostTool, SeleniumURLLoader

API endpoints and dynamic sites need clean IPs for consistent access.

Document Loaders

ArxivLoader, WikipediaLoader, PubMedLoader

Academic and reference sites implement rate limiting that mobile IPs bypass.

Data Retrievers

WebResearchRetriever, TavilySearchAPIRetriever

Research agents making many requests need rotating mobile IPs.

Browser Tools

PlaywrightBrowserToolkit, SeleniumToolkit

Full browser automation requires mobile IPs for anti-bot bypass.

Configuration Examples

1. Environment Variables (Requests-based tools)

import os

# Set proxy for all requests-based LangChain tools
os.environ["HTTP_PROXY"] = "socks5://user:pass@proxy.proxies.sx:10001"
os.environ["HTTPS_PROXY"] = "socks5://user:pass@proxy.proxies.sx:10001"

from langchain_community.tools import DuckDuckGoSearchRun
from langchain_community.document_loaders import WebBaseLoader

# Tools now use mobile proxy automatically
search = DuckDuckGoSearchRun()
result = search.run("latest AI news")

loader = WebBaseLoader("https://example.com")
docs = loader.load()

2. Custom Session with Proxy

import requests
from langchain_community.document_loaders import WebBaseLoader

# Create proxied session
session = requests.Session()
session.proxies = {
    "http": "socks5://user:pass@proxy.proxies.sx:10001",
    "https": "socks5://user:pass@proxy.proxies.sx:10001"
}

# Use session with WebBaseLoader
loader = WebBaseLoader(
    "https://example.com",
    session=session,
    requests_kwargs={"timeout": 30}
)
docs = loader.load()

3. Playwright Browser Tools

from langchain_community.agent_toolkits import PlaywrightBrowserToolkit
from langchain_community.tools.playwright.utils import create_async_playwright_browser

# Create browser with proxy
async def get_proxied_browser():
    browser = await create_async_playwright_browser(
        headless=True,
        proxy={
            "server": "socks5://proxy.proxies.sx:10001",
            "username": "your_username",
            "password": "your_password"
        }
    )
    return browser

# Use with toolkit
browser = await get_proxied_browser()
toolkit = PlaywrightBrowserToolkit.from_browser(async_browser=browser)
tools = toolkit.get_tools()

4. Full ReAct Agent with Web Tools

import os
os.environ["HTTP_PROXY"] = "socks5://user:pass@proxy.proxies.sx:10001"
os.environ["HTTPS_PROXY"] = "socks5://user:pass@proxy.proxies.sx:10001"

from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_react_agent
from langchain_community.tools import DuckDuckGoSearchRun
from langchain import hub

# Initialize LLM
llm = ChatOpenAI(model="gpt-4", temperature=0)

# Get search tool (now proxied)
search_tool = DuckDuckGoSearchRun()
tools = [search_tool]

# Create ReAct agent
prompt = hub.pull("hwchase17/react")
agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

# Run agent - all web requests go through mobile proxy
result = agent_executor.invoke({
    "input": "What are the top AI companies in 2025?"
})
Pro Tip: For production agents making many requests, use our Private plan with multiple ports. Rotate ports between tasks to avoid rate limits.

LangChain Proxy Best Practices

Set Proxies Early

Set environment variables before importing LangChain modules. Some loaders initialize HTTP clients at import time.

Use Async Where Possible

AsyncHtmlLoader and async tools handle multiple requests efficiently. Combine with proxy rotation for high-volume scraping.

Implement Retry Logic

Even with mobile proxies, some requests fail. Use LangChain's built-in retry mechanisms and rotate IPs on persistent failures.

Cache Aggressively

Use LangChain's caching to avoid redundant web requests. This saves bandwidth costs and reduces detection risk.

Power Your LangChain Agents

Get reliable web access for LangChain tools with real mobile IPs.