Recipes

Tool Agent Read-URL

Tool drop-in "leggi questo URL" per un loop di agente LLM

Dai al tuo agente un singolo tool che trasforma qualsiasi URL in Markdown pulito. L'agente lo chiama ogni volta che ha bisogno di fare ricerca su una pagina — Thunderbit gestisce JS, anti-bot e pulizia del contenuto, così il contesto dell'agente rimane denso di segnale.

Definizione del tool (Python)

import httpx

API = "https://openapi.thunderbit.com/openapi/v1"
H = {"Authorization": "Bearer YOUR_API_KEY"}

def read_url(url: str) -> str:
    """Fetch a URL and return clean Markdown.

    Use for any web research task: docs, articles, search results, product pages.
    Returns the page as Markdown with metadata stripped.
    """
    resp = httpx.post(f"{API}/distill",
                      headers=H,
                      json={"url": url, "renderMode": "basic"},
                      timeout=60.0)
    resp.raise_for_status()
    return resp.json()["data"]["markdown"]

Esempio di function-calling OpenAI

tools = [{
    "type": "function",
    "function": {
        "name": "read_url",
        "description": "Fetch a URL and return clean Markdown for the agent to read.",
        "parameters": {
            "type": "object",
            "properties": {
                "url": {"type": "string", "description": "The URL to fetch"}
            },
            "required": ["url"],
        },
    },
}]

Quando il modello chiama read_url, fai dispatch alla funzione qui sopra e restituisci il risultato come messaggio tool.

Suggerimenti

  • Mantieni renderMode su basic per l'agente — è un buon default costo / copertura
  • Limita la lunghezza del Markdown restituito (es. 8k token) prima di passarlo al modello
  • Per la ricerca in massa, preferisci /batch/distill — vedi Knowledge Base RAG

Correlati

Questa ricetta è in fase di espansione con varianti LangChain / LlamaIndex / CrewAI — torna presto.