Skip to main content
FetchTool provides a simple interface to fetch content from URLs using various HTTP methods.

Constructor

No parameters required. Inherits from BaseTool.

Methods

fetch_url

Fetch content from a URL using HTTP requests.
url
str
required
The URL to fetch
method
str
HTTP method to use: GET, POST, PUT, DELETE, etc. (default: “GET”)
headers
Dict[str, str]
Optional headers to include in the request
body
str
Optional body content for POST/PUT requests
Returns: Response text or error message Timeout: 30 seconds

Usage

Basic GET request

from agentor import Agentor
from agentor.tools import FetchTool

fetch_tool = FetchTool()

agent = Agentor(
    name="Web Fetcher",
    model="gpt-4o-mini",
    tools=[fetch_tool]
)

result = agent.run("Fetch the content from https://api.example.com/data")
print(result)

GET request with headers

from agentor.tools import FetchTool

fetch = FetchTool()

result = fetch.fetch_url(
    url="https://api.example.com/data",
    method="GET",
    headers={
        "Authorization": "Bearer token123",
        "Accept": "application/json"
    }
)
print(result)

POST request with body

import json

# POST JSON data
result = fetch.fetch_url(
    url="https://api.example.com/items",
    method="POST",
    headers={"Content-Type": "application/json"},
    body=json.dumps({"name": "New Item", "value": 42})
)
print(result)

Other HTTP methods

# PUT request
result = fetch.fetch_url(
    url="https://api.example.com/items/123",
    method="PUT",
    headers={"Content-Type": "application/json"},
    body=json.dumps({"name": "Updated Item"})
)

# DELETE request
result = fetch.fetch_url(
    url="https://api.example.com/items/123",
    method="DELETE"
)

Error handling

The tool returns error messages as strings:
# HTTP error (404, 500, etc.)
result = fetch.fetch_url("https://api.example.com/nonexistent")
print(result)  # HTTP Error: 404 - Not Found

# Network error
result = fetch.fetch_url("https://invalid.domain.xyz")
print(result)  # Error fetching URL: ...

# Timeout (30 seconds)
result = fetch.fetch_url("https://slow-api.example.com")
print(result)  # Error fetching URL: timeout

Use cases

  • Fetching data from REST APIs
  • Web scraping simple HTML pages
  • Testing API endpoints
  • Downloading content from URLs
  • Webhook testing

Notes

FetchTool uses httpx under the hood with a 30-second timeout for all requests.
This tool makes actual HTTP requests. Be careful when using it with untrusted URLs or in production environments with rate limits.

Source reference

src/agentor/tools/fetch.py:8
Last modified on March 4, 2026