agora.fleet.web_fetch

Safe HTTPS fetcher for the fetch_url inner tool.

Design constraints locked with the user:

  • HTTPS only. Reject everything else (http, file, data, ftp, …).

  • SSRF guard. Resolve the hostname before the request, and refuse any IP that is loopback, link-local, private (RFC 1918 / 4193), or the cloud metadata address (169.254.169.254). Re-check the resolved IP at request time.

  • Size-bounded. Cap the raw HTML body at max_bytes and the extracted text at max_text_bytes so a 7B model’s context window doesn’t overflow.

  • Text extraction. Use trafilatura to strip nav/sidebar/footer and return just the main content.

  • Non-blocking. All IO via aiohttp under an explicit ClientTimeout.

  • Caching. A FetchCache lets callers share a cache across agents so the architect and implementer don’t re-fetch the same Discord page.

Raises SSRFError on disallowed URLs and FetchError on any other fetch/extraction failure. Both inherit from AgoraError.

Functions

make_fetcher(*, cache[, timeout_seconds, ...])

Build an async def fetch(url) -> str bound to a shared cache.

safe_fetch(url, *[, timeout_seconds, ...])

Fetch a URL, convert to clean text, return the text (truncated).

validate_url(url)

Parse, scheme-check, and DNS-resolve url; return (host, port).

Classes

FetchCache

Per-project in-memory cache: {url: extracted_text}.

Exceptions

FetchError

Generic failure in safe_fetch() — network, HTTP, or extraction.

SSRFError

The URL was rejected by the SSRF guard.

class agora.fleet.web_fetch.FetchCache[source]

Bases: object

Per-project in-memory cache: {url: extracted_text}.

entries: dict[str, str]
get(url)[source]
put(url, text)[source]
__init__(entries=<factory>)
exception agora.fleet.web_fetch.FetchError[source]

Bases: AgoraError

Generic failure in safe_fetch() — network, HTTP, or extraction.

exception agora.fleet.web_fetch.SSRFError[source]

Bases: AgoraError

The URL was rejected by the SSRF guard.

agora.fleet.web_fetch.make_fetcher(*, cache, timeout_seconds=30.0, max_bytes=1048576, max_text_bytes=16384)[source]

Build an async def fetch(url) -> str bound to a shared cache.

async agora.fleet.web_fetch.safe_fetch(url, *, timeout_seconds=30.0, max_bytes=1048576, max_text_bytes=16384, cache=None, user_agent='agora-bot/0.1 (+https://github.com/fabs133/manifold)')[source]

Fetch a URL, convert to clean text, return the text (truncated).

Retries once on transient errors (timeout, 429, 5xx, connection reset) with a short backoff. Non-transient failures (SSRF, 4xx other than 429, malformed content) raise immediately.

Never blocks the event loop. Always raises on any policy violation.

agora.fleet.web_fetch.validate_url(url)[source]

Parse, scheme-check, and DNS-resolve url; return (host, port).

Raises SSRFError on any policy violation. The returned pair is what aiohttp will connect to, so callers can pass the host through server_hostname for TLS verification.