Recipes
Agent Read-URL 工具
为 LLM agent 循环准备的"读这个 URL"开箱即用工具
给你的 agent 一个工具:把任意 URL 变成干净的 Markdown。Agent 在需要研究网页时调用它 —— Thunderbit 处理 JS、反爬以及内容清洗,让 agent 的上下文保持高信息密度。
工具定义(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 时,分发到上面的函数,再把结果作为 tool message 返回给模型。
小贴士
- agent 场景下
renderMode保持basic即可 —— 在成本 / 覆盖度上是个不错的默认值 - 在喂给模型之前,给返回的 Markdown 加个长度上限(比如 8k tokens)
- 批量研究场景下优先使用
/batch/distill—— 详见 RAG 知识库
相关
这份 recipe 正在补充 LangChain / LlamaIndex / CrewAI 变体,敬请期待。