自己寫一個
manifest

Manifest 是一個 JSON 檔,告訴 AI agent 你的 CLI 做什麼、什麼時候該用、怎麼呼叫 這篇教學會帶你走完每個必填欄位,以及那些讓 manifest「被找到」的小習慣

01四個問題

每個 manifest 都在回答四個問題如果你能用一段話回答,你就能寫一個 manifest

問題欄位格式
它做什麼?description10–200 字,平實英文
什麼時候 agent 該選它?intent_triggers≥ 5 條,混合語言
它需要什麼輸入?input_schema類似 JSON Schema
它回傳什麼?output_schemajson / csv / text

02選一個分類

把 manifest 放到對的資料夾共 10 個分類,挑最接近的一個就好

03完整範本

存成 manifests/<分類>/<你的工具>.json,然後改裡面的欄位

{
  "name": "video-to-gif",
  "version": "1.0.0",
  "category": "media",
  "description": "Convert a video file to an animated GIF with configurable framerate and resolution",

  "intent_triggers": [
    "convert mp4 to gif",
    "turn this video into a gif",
    "make a short looping animation from this clip",
    "export the first 5 seconds of a video as a gif",
    "reduce framerate when generating gif",
    "把影片轉成 GIF",
    "幫我把這段影片做成 gif 動圖"
  ],

  "input_schema": {
    "input":  { "type": "string",  "required": true,  "description": "來源影片檔的路徑" },
    "output": { "type": "string",  "required": true,  "description": "輸出 GIF 的路徑" },
    "fps":    { "type": "integer", "required": false, "default": 15 },
    "width":  { "type": "integer", "required": false }
  },

  "output_schema": {
    "format": "json",
    "fields": ["output_path", "frame_count", "file_size_bytes"]
  },

  "examples": [
    {
      "query": "convert demo.mp4 to a 10-fps gif",
      "params": { "input": "demo.mp4", "output": "demo.gif", "fps": 10 }
    }
  ],

  "error_codes": {
    "1": "Input file not found",
    "2": "ffmpeg not installed"
  },

  "tags": ["video", "gif", "ffmpeg"]
}

04寫好 intent_triggers

這個欄位決定 router 找不找得到你的工具值得花時間

原則

為什麼這很重要

Router 會把每條 trigger 向量化用來檢索多樣化的 trigger 讓你的工具在語意空間佔據更完整的區域,從不同角度的問法都能被找到

反面教材

05至少寫一個 example

Example 是「自然語言 query → 對應參數」的範本

{
  "query": "convert demo.mp4 to a 10-fps gif",
  "params": { "input": "demo.mp4", "output": "demo.gif", "fps": 10 }
}

當 agent 的意圖跟某個 example 夠接近(cosine ≥ 0.85),router 直接套用該 example 的 params完全不需要呼叫 LLM這就是「A 路」——零 token、零延遲

每個工具寫 3–5 個 example

每個 example 涵蓋一種使用形態(預設參數、常見覆寫、邊界情況)Example 越多 → A 路命中率越高 → 整體成本越低

06本地驗證

兩步驟檢查:先驗 schema再驗 routing

# 安裝
pip install clibrary-hub

# 1. Schema 檢查 — manifest 的格式對不對?
python -c "from clibrary_hub import validator; r = validator.validate_file('manifests/media/your-tool.json'); print(r); [print('  ERROR:', e) for e in r.errors]; [print('  WARN: ', w) for w in r.warnings]"

# 2. 建 FAISS index(含新加的 manifest)
clibrary-build-index --manifest-dir ./manifests

# 3. Routing 檢查 — router 實際上會選到你的工具嗎?
python -c "from clibrary_hub import router; print(router.route('幫我把 demo.mp4 做成 gif'))"
Validator 會檢查什麼

必填欄位、name kebab-case、semver 版號、合法 categorydescription 長度 10–200、≥ 5 條 intent_triggers(單一語言會給 warning)、input_schema 型別、output_schema.formatexamples 結構、error_codes完全離線執行

如果 schema 過了但 router 沒選到你的工具,多半是 intent_triggers 多樣性不夠或關鍵詞錨點太弱

07送 PR

  1. Fork clibrary-hub/cli-tools
  2. 開分支,把 manifest 放到對應分類資料夾並 commit
  3. 送 PR簡單說明這個工具做什麼、為什麼 agent 會想用它
  4. CI 會自動驗證 schema 並檢查名稱是否重複

常見錯誤

錯誤修正
description 超過 200 字或寫成行銷文案一句話、白話寫它做什麼,不寫它有多好
只有英文 trigger至少加 2 條使用者會用到的其他語言
example 的 params 跑不起來送 PR 前自己跑一次
error_codes 寫得很空("1: error")具體一點:"1": "Input file not found"
不要假造數字

如果你的工具實際上沒有回傳 frame_count,就不要寫進 output_schema.fieldsAgent 會相信這份 manifest 寫的東西