Hub 文件
將 Spaces 作為代理工具 (Agent Tools)
並獲得增強的文件體驗
開始使用
Spaces 作為代理工具
每個 Gradio Space 都提供一個純文字的 agents.md,編碼代理(如 Claude Code、Codex、OpenCode、Pi 等)可以直接呼叫。您可以透過 huggingface.co/spaces 上的語意搜尋找到所需工具(例如「語音轉錄」),可選擇先在 UI 中試用,然後將您的代理指向該 Space 的 agents.md。回應會提供一次性呼叫 Space 所需的一切資訊:架構 URL、呼叫與輪詢範本、檔案上傳說明以及身份驗證提示。
當串接多個 Spaces 時,這會變得更加強大。代理可以透過呼叫 black-forest-labs/flux-klein-9b-kv 來生成圖片,將提示詞轉為 3D 資產,然後將生成的圖片傳遞給 microsoft/TRELLIS.2 以製作 3D 模型。無需客戶端函式庫,也無需硬編碼整合。
您只需要在環境中設定 HF_TOKEN 即可開始。
透過介面 (UI)
每個相容的 Space 頁面頁首都有一個代理 (Agents) 按鈕。點擊它即可複製該 Space 的 agents.md 的 curl 指令,然後將其貼上到您的代理中。

agents.md 端點
https://huggingface.co/spaces/<namespace>/<repo>/agents.md範例
curl https://huggingface.co/spaces/microsoft/TRELLIS.2/agents.md
返回
To use this application (microsoft/TRELLIS.2: Create 3D model from a single image):
API schema: GET https://microsoft-trellis-2.hf.space/gradio_api/info
Call endpoint: POST https://microsoft-trellis-2.hf.space/gradio_api/call/v2/{endpoint} {"param_name": value, ...}
Poll result: GET https://microsoft-trellis-2.hf.space/gradio_api/call/{endpoint}/{event_id}
File inputs: POST https://microsoft-trellis-2.hf.space/gradio_api/upload -F "files=@file.ext", use as: {"path": "<returned-path>", "meta": {"_type": "gradio.FileData"}, "orig_name": "file.ext"}
Auth: Bearer $HF_TOKEN (https://huggingface.co/settings/tokens)檔案輸入
當端點接收檔案(圖片、音訊、影片等)時,請先將其上傳,並在呼叫時參照回傳的路徑。上傳至 /gradio_api/upload 並重複使用該路徑。
# 1. Upload the file
curl -H "Authorization: Bearer $HF_TOKEN" \
https://microsoft-trellis-2.hf.space/gradio_api/upload \
-F "files=@chair.png"
# → ["/tmp/gradio/.../chair.png"]
# 2. Reference the returned path as a FileData object in your call
curl -H "Authorization: Bearer $HF_TOKEN" \
https://microsoft-trellis-2.hf.space/gradio_api/call/v2/predict \
-d '{"image": {"path": "/tmp/gradio/.../chair.png", "meta": {"_type": "gradio.FileData"}, "orig_name": "chair.png"}}'接受公開 URL(而非上傳檔案)的輸入可以直接傳遞,無需經歷上傳步驟。
身份驗證與 ZeroGPU
大多數熱門的 Spaces 都在 ZeroGPU 上運行,該服務會消耗呼叫者的每日配額。代理應始終傳遞 $HF_TOKEN,以便將呼叫計入您的帳戶,而不是消耗受限的匿名池。私人 Spaces 也需要相同的 Token。您可以在 huggingface.co/settings/tokens 建立 Token(agents.md 中的驗證列會直接連結到此頁面)。
curl -H "Authorization: Bearer $HF_TOKEN" \
https://microsoft-trellis-2.hf.space/gradio_api/call/v2/predict \
-d '{"image": {"path": "https://example.com/chair.png"}}'代理如何使用此功能
- 代理會對 Space 的
/agents.md執行curl指令。 - 它會獲取
/gradio_api/info以了解端點名稱與輸入資訊。 - 針對檔案輸入,它會將檔案 POST 至
/gradio_api/upload並保留回傳的路徑。 - 它會 POST 至
/gradio_api/call/v2/<endpoint>,然後 GET 輪詢 URL 以串流取得結果。