Tool 生成流程
最後更新
當請求需要現有工具未涵蓋的能力時,Agenvoy 從判斷到建置、驗證與執行的完整流程。
流程
graph TB
Start[請求需要外部資料或缺少對應工具] --> Guide[read_guides tool_generate]
Guide --> SearchAPI[最多查 3 個分類:read_public_apis]
SearchAPI -->|有免金鑰公開 API 適用| Docs[fetch_page 讀取 API 文件]
Docs --> CallHTTP[直接以 http_request 呼叫並回答<br/>不儲存工具]
SearchAPI -->|無適用公開 API / 需金鑰 / 需 Python 計算| KeyCheck{需要 API 金鑰?}
KeyCheck -->|是| Secret[store_secret BRAND_API_KEY<br/>腳本內透過 get_key 讀取]
KeyCheck -->|否| WriteTool
Secret --> WriteTool[write_tool mode=write tag=json + tag=script<br/>每次 write/patch 後自動驗證]
WriteTool -->|驗證失敗| PatchVal[以 write_tool mode=patch 修正]
PatchVal --> WriteTool
WriteTool -->|驗證通過| TestScript[test_script 傳入範例 stdin JSON<br/>沙箱執行,上限 60 秒]
TestScript -->|失敗,最多重試 3 次| PatchRun[以 write_tool mode=patch 修正]
PatchRun --> TestScript
TestScript -->|通過| Invoke[呼叫 script_name 並回答]
SearchAPI -->|既無 API 也無 Python 途徑| Fallback[退回 search_web / fetch_page<br/>註明資料來源]- graph TB
- Start[請求需要外部資料或缺少對應工具] --> Guide[read_guides tool_generate]
- Guide --> SearchAPI[最多查 3 個分類:read_public_apis]
- SearchAPI -->|有免金鑰公開 API 適用| Docs[fetch_page 讀取 API 文件]
- Docs --> CallHTTP[直接以 http_request 呼叫並回答<br/>不儲存工具]
- SearchAPI -->|無適用公開 API / 需金鑰 / 需 Python 計算| KeyCheck{需要 API 金鑰?}
- KeyCheck -->|是| Secret[store_secret BRAND_API_KEY<br/>腳本內透過 get_key 讀取]
- KeyCheck -->|否| WriteTool
- Secret --> WriteTool[write_tool mode=write tag=json + tag=script<br/>每次 write/patch 後自動驗證]
- WriteTool -->|驗證失敗| PatchVal[以 write_tool mode=patch 修正]
- PatchVal --> WriteTool
- WriteTool -->|驗證通過| TestScript[test_script 傳入範例 stdin JSON<br/>沙箱執行,上限 60 秒]
- TestScript -->|失敗,最多重試 3 次| PatchRun[以 write_tool mode=patch 修正]
- PatchRun --> TestScript
- TestScript -->|通過| Invoke[呼叫 script_name 並回答]
- SearchAPI -->|既無 API 也無 Python 途徑| Fallback[退回 search_web / fetch_page<br/>註明資料來源]
步驟說明
- 讀取建置契約 — 動手前先呼叫
read_guides(topics=["tool_generate"])。 - 優先使用免金鑰公開 API — 以
read_public_apis(category)查詢最多 3 個相關分類。若有合適的免金鑰 HTTPS API,用fetch_page確認規格後直接以http_request呼叫並回答,不建立永久工具。 - 僅在必要時建立 script tool — 只有在公開 API 清單無法滿足需求時(例如使用者提供且需要
store_secret金鑰的 API,或需以 Python 計算處理),才透過write_tool(mode=write)在~/.config/agenvoy/tools/script/<name>/寫入tag=json(tool.json)與tag=script(script.py);每次write與patch後會自動執行toolAdapter.Validate。 - 於沙箱測試 — 傳入範例 JSON 呼叫
test_script(60 秒上限)。若失敗則以write_tool(mode=patch)修正並重測(最多重試 3 次)。 - 回答 — 呼叫新註冊的
script_<name>工具取得結果並回答(若 API 與 Python 皆不可行,則退回search_web/fetch_page並註明來源)。
版本紀錄
- v1.6.3:新增 Tool 生成流程專頁,反映
write_tool於write/patch後自動執行toolAdapter.Validate以及透過test_script進行沙箱驗證的流程。