Recipes
Agent Read-URL 工具
可直接掛進 LLM agent loop 的『讀這個 URL』工具
給你的 agent 一個工具,把任意 URL 轉成乾淨的 Markdown。每當 agent 需要研究某個頁面就呼叫它 —— Thunderbit 處理 JS、反爬、內容清洗,agent 的 context 就能保持高訊噪比。
工具定義(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"]OpenAI function-calling 範例
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"],
},
},
}]當模型呼叫 read_url 時,dispatch 到上面那個函式,再把結果以 tool message 回灌給模型。
小技巧
- agent 場景把
renderMode留在basic即可 —— 在成本與覆蓋率之間是個好預設 - 餵給模型前先截斷 Markdown 長度(例如 8k tokens)
- 大量研究任務改用
/batch/distill—— 參見 RAG 知識庫
相關
本食譜將補充 LangChain/LlamaIndex/CrewAI 變體 —— 敬請期待。