整合

CrewAI

給 CrewAI agent 一個用 Thunderbit 跑網頁研究的 tool

CrewAI agent 需要新鮮、乾淨的網頁內容當輸入。把 /distill 包成一個 CrewAI tool,crew 裡任何 agent 都能隨時讀 URL。

安裝

pip install crewai httpx

自訂 tool

from crewai.tools import BaseTool
import httpx

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

class ReadUrlTool(BaseTool):
    name: str = "read_url"
    description: str = (
        "Fetch a URL and return clean Markdown. Use for any web research task: "
        "docs, articles, product pages, search results."
    )

    def _run(self, url: str) -> str:
        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"]

接進 Crew

from crewai import Agent, Task, Crew

researcher = Agent(
    role="Web Researcher",
    goal="Gather authoritative information from public web pages",
    backstory="Skilled at distilling long pages into key facts.",
    tools=[ReadUrlTool()],
)

task = Task(
    description="Research how vector databases compare in 2026.",
    expected_output="A concise comparison table.",
    agent=researcher,
)

Crew(agents=[researcher], tasks=[task]).kickoff()

小技巧

  • 多來源研究時,再開一個 /batch/distill 包出來的 tool(叫 read_urls),讓 agent 平行去抓
  • 把回傳的 Markdown 截到約 8k token 再丟給 agent —— 避免吃爆 context

相關文件

這份整合會擴出多 agent crew 模板 —— 敬請期待。