Skip to content

Updated

CrewAI and LangGraph Proxy:
Fixed Region for Agent Tools

  1. Put the proxy in the one function that opens websites, and give that function to the framework as a tool.
  2. The tool-definition pages of CrewAI, LangGraph (LangChain) and LlamaIndex describe tools as ordinary Python functions, so the proxy is a setting of the HTTP client inside the function, for example httpx.Client(proxy=...).
  3. Choose the country when you generate the proxy: rotating residential from US$1.50 per GB covers 195+ countries and regions, and the Premium line adds state and city. Keep the credentials in the function, not in the prompt, and check the exit before the agent starts.

Check it right after buyingExample output

curl -x http://USER:PASS@HOST:PORT https://ipinfo.io/json

ip
203.0.113.24
country
US
Matches the country you picked
Day 15
203.0.113.24
Same address for the whole term
Example addresses (203.0.113.0/24), not real exits
01 / 11Where the proxy goes

Where the proxy goes in CrewAI, LangGraph and LlamaIndex, with one shared tool function, three wrappers and a check of the exit country.

Where the proxy goes

CrewAI, LangGraph and LlamaIndex decide what the agent does next. A web request leaves your machine from the function a tool calls, so that function is where the proxy belongs. The pages we read on defining tools show them as plain Python functions, with no proxy setting of their own.

CrewAI's ScrapeWebsiteTool is one example: its source fetches pages with requests.get and passes no proxies argument, so a proxy has to come from your own client or from the environment. Setting HTTPS_PROXY for the whole process also reaches every other library that uses requests, which is why we put the proxy in the tool's own client.

How each framework takes a tool

How each framework takes a tool
ItemHow a tool is definedHow it reaches the agent
CrewAI@tool from crewai.tools, or a BaseTool subclass with _runtools=[...] on the Agent
LangGraph (LangChain)@tool from langchain.toolsThe tools list, bound with model.bind_tools(tools) and run in a tool node of the graph
LlamaIndexFunctionTool.from_defaults(fn, name=..., description=...)tools=[...] on FunctionAgent

Sources: the CrewAI, LangGraph and LlamaIndex documentation pages listed below, read on 20 November 2026. Import paths change between releases; check your installed version.

One function that opens websites through the proxy

import os
import httpx

# http://LOGIN:PASSWORD@HOST:PORT from My assets: the HTTP line, port 2222
PROXY_URL = os.environ["PROXY_URL"]


def fetch_page(url: str) -> str:
    """Fetch a web page through the proxy and return the first 4000 characters."""
    with httpx.Client(proxy=PROXY_URL, timeout=30, follow_redirects=True) as client:
        response = client.get(url)
        response.raise_for_status()
        return response.text[:4000]


def check_exit() -> str:
    """Return the IP and country that websites see for this proxy."""
    return fetch_page("https://ipinfo.io/json")

Example only: save it as proxy_tools.py and set PROXY_URL to your own value. httpx takes the proxy with the proxy parameter; for SOCKS5 it needs httpx[socks], so this uses the HTTP line.

CrewAI: the function as a tool

from crewai import Agent
from crewai.tools import tool

from proxy_tools import fetch_page


@tool("Fetch page from the fixed region")
def fetch_page_tool(url: str) -> str:
    """Fetch a web page through the proxy and return its text."""
    return fetch_page(url)


researcher = Agent(
    role="Regional price checker",
    goal="Read the pages you are given and report what a local visitor sees",
    backstory="You only read pages through the fetch tool.",
    tools=[fetch_page_tool],
)

Example only: the @tool decorator and the tools list follow the CrewAI documentation. Add the Task and Crew you already use.

LangGraph: the function as a tool

from langchain.tools import tool

from proxy_tools import fetch_page


@tool
def fetch_page_tool(url: str) -> str:
    """Fetch a web page through the proxy and return its text."""
    return fetch_page(url)


tools = [fetch_page_tool]
model_with_tools = model.bind_tools(tools)  # `model` is your chat model, as in the LangGraph quickstart
# Run the tool calls in the tool node of your StateGraph, as the quickstart does.

Example only: the @tool decorator and bind_tools follow the LangGraph quickstart. Your own model and graph go around it.

LlamaIndex: the function as a tool

from llama_index.core.agent.workflow import FunctionAgent
from llama_index.core.tools import FunctionTool

from proxy_tools import fetch_page

fetch_tool = FunctionTool.from_defaults(
    fetch_page,
    name="fetch_page",
    description="Fetch a web page through the proxy and return its text.",
)

agent = FunctionAgent(llm=llm, tools=[fetch_tool])  # `llm` is your LlamaIndex LLM

Example only: FunctionTool.from_defaults and FunctionAgent follow the LlamaIndex documentation. Your own LLM goes in llm.

Fix the region and the IP

The country is chosen when you generate the proxy. The Budget line takes a country only. The Premium line also takes a state or city, which is useful when an agent checks a local page. Rotating lines give each new connection a new IP, and a reused connection keeps its IP, so an agent that reads several pages of one site should use a session that holds one IP.

For an agent that signs in to one account, use a static ISP IP instead: it does not rotate during the lease, from US$0.50 for 1 day. The guide on proxy types for AI agents compares the three types.

How to do it with Proxy302

  1. Step 1

    Open the rotating residential page and generate a proxy for the country the agent should read from.

  2. Step 2

    Open My assets and copy HOST, PORT, USERNAME and PASSWORD. Build PROXY_URL as http://LOGIN:PASSWORD@HOST:PORT with the HTTP line on port 2222. One username and password also works over SOCKS5 on port 3333 if your tool needs it.

  3. Step 3

    Save the shared function as proxy_tools.py, set PROXY_URL as an environment variable and call check_exit() once. The country in the answer should be the one you chose.

  4. Step 4

    Wrap fetch_page for your framework as above, and tell the agent in its task to call the tool for every page.

If the tool fails

HTTP 407 or a proxy error from httpx

Check Check USERNAME, PASSWORD, HOST and PORT, and that the URL starts with http:// and uses port 2222.

Fix Copy the values again from My assets and call check_exit().

Stop when Stop after two tries and open a Support ticket with the order number.

The exit country is not the one you chose

Check Call check_exit() and read the country, then compare with another lookup.

Fix Generate the proxy again with the right country.

Stop when If two lookups still disagree, report it instead of rerunning the agent.

The agent seems to ignore the proxy

Check Check that the page was fetched by your tool and not by a built-in web tool that has no proxy setting.

Fix Remove the built-in web tool from the agent and give it only your tool.

Stop when Do not rely on HTTPS_PROXY alone; put the proxy in the tool's client.

FAQ

How do I add a proxy to CrewAI?

Write a tool that fetches pages with an HTTP client configured with the proxy, define it with the @tool decorator and put it in the Agent's tools list. The built-in ScrapeWebsiteTool passes no proxies argument.

Does LangGraph have a proxy setting?

The quickstart we read defines tools as @tool functions and has no proxy setting. Configure the proxy in the function the tool calls.

How do I fix the country for an agent?

Choose the country when you generate the proxy, then call a check function that reads https://ipinfo.io/json through it before the agent starts.

Can I use SOCKS5?

Yes, with httpx[socks] installed. The same username and password work over SOCKS5 on port 3333, but the HTTP line on port 2222 needs no extra package.

Will the proxy also carry my model API calls?

Not if you set it only on the tool's client. A process-wide HTTPS_PROXY would reach every library that uses requests, so scope the proxy to the tool.

Further reading

Setup guides Proxy302 publishes on GitHub on the same topic:

Reference links

8
  1. HTTPX documentation: proxies

    Official documentation · Confirmed on:

    Read on 20 November 2026: httpx takes a proxy with the proxy parameter, for example httpx.Client(proxy="http://username:password@localhost:8030"); SOCKS is optional and needs pip install httpx[socks].

  2. CrewAI documentation: create custom tools

    Official documentation · Confirmed on:

    Read on 20 November 2026: a tool is defined with the @tool decorator from crewai.tools or by subclassing BaseTool with an args_schema and a _run method.

  3. CrewAI documentation: agents

    Official documentation · Confirmed on:

    Read on 20 November 2026: an Agent takes role, goal, backstory and a tools list.

  4. LangGraph quickstart (LangChain documentation)

    Official documentation · Confirmed on:

    Read on 20 November 2026: tools are defined with the @tool decorator from langchain.tools, collected in a list and bound with model.bind_tools(tools); the graph is built with StateGraph from langgraph.graph.

  5. LlamaIndex documentation: tools

    Official documentation · Confirmed on:

    Read on 20 November 2026: FunctionTool.from_defaults(fn, name=..., description=...) from llama_index.core.tools, and FunctionAgent(llm=llm, tools=[...]) from llama_index.core.agent.workflow.

  6. CrewAI tools source: ScrapeWebsiteTool

    Third-party source · Confirmed on:

    Read on 20 November 2026: ScrapeWebsiteTool fetches pages with requests.get(url, timeout=15, headers=..., cookies=...) and passes no proxies argument.

  7. PRAW documentation: configuration (requests proxy variables)

    Official documentation · Confirmed on:

    Read on 20 November 2026: PRAW uses requests, which supports the HTTP_PROXY and HTTPS_PROXY environment variables.

  8. Proxy302 product facts and price list

    Product observation · Confirmed on:

    Product facts file of the site, checked 10 November 2026 against the console, the backend and the price table: per-IP lease prices in US$ (1 PTC = US$1), lease terms, protocols and ports, countries, quantity limits, no free trial.

Ready to try it?

Create an account, top up once, then pick rotating residential, static ISP or datacenter IPs and have one running in your browser within minutes.