整合

AutoGen

給 Microsoft AutoGen agent 一個用 Thunderbit 驅動的網頁讀取器

AutoGen agent 接受 Python function 當 tool。把 /distill 包起來,任何 AssistantAgent(或 GroupChat 成員)都能即時讀網頁。

安裝

pip install pyautogen httpx

Function tool

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.
    """
    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"]

註冊到 Agent

from autogen import AssistantAgent, UserProxyAgent

llm_config = {"model": "gpt-4o", "api_key": "YOUR_OPENAI_KEY"}

researcher = AssistantAgent(name="researcher", llm_config=llm_config)
proxy      = UserProxyAgent(name="proxy", code_execution_config=False)

researcher.register_for_llm(name="read_url", description="Fetch URL as Markdown")(read_url)
proxy.register_for_execution(name="read_url")(read_url)

proxy.initiate_chat(researcher, message="Summarize https://arxiv.org/abs/2501.00001")

GroupChat

跑多 agent crew(researcher + writer + critic)時,只在 researcher 上 register_for_llm 註冊 read_url,其他 agent 就觸發不了。執行還是走共用的 UserProxyAgent

相關文件