Community程式設計與開發github.com

工具設計

此技能用於代理系統的工具介面層:撰寫代理可依此路由的工具描述、設計工具架構與回應格式、命名慣例、可操作錯誤回復訊息、MCP 伺服器設計、工具集整併,以及決定何時新增或移除個別工具。當工作單位為單一工具或一組工具時使用。將專案形貌、管線架構與任務模型匹配決策路由至「專案開發」;將是否引入子代理的決策路由至「多代理模式」。

工具設計 是什麼?

「工具設計」技能專注於代理系統的工具介面層,確保每個工具作為一個明確的合約,讓非確定性的代理能夠可靠地與確定性系統互動。其核心原則包括「整併原則」——將重疊或狹義的工具合併為單一全面工具,以減少選擇錯誤與語意模糊;以及「架構簡化」——用更少的原始通用能力取代大量專業工具,就像檔案系統代理模式僅透過單一指令執行工具直接存取檔案系統。此外,技能強調工具描述工程,要求描述必須回答「做什麼、何時使用、輸入什麼、回傳什麼」四個問題,並提供完整的命名規範(動詞-名詞模式)、MCP 伺服器前綴要求、回應格式最佳化(簡潔 vs 詳細)以及可操作的錯誤訊息設計,讓代理能自動修正錯誤。此技能也包含利用代理進行工具測試與反饋迴圈的模式,透過分析代理使用工具的失敗案例來持續改進工具描述。技能明確劃分工作範圍:專案層級決策歸屬「專案開發」,多代理模式決策歸屬「多代理模式」,而工具輸出 token 最佳化歸屬「上下文最佳化」。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering/tree/main/skills/tool-design

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

為代理設計工具

將每個工具視為確定性系統與非確定性代理之間的合約。與面對人類的 API 不同,面對代理的工具必須僅透過描述就讓合約明確無誤:代理從描述中推斷意圖,並產生必須符合預期格式的呼叫。任何模糊之處都可能成為失敗模式,而這無法透過任何提示工程修復。

此技能的工作單位是單一工具或工具目錄。專案形貌、管線架構、任務模型匹配以及專案層級的成本決策歸屬於 project-development。決定是否引入子代理歸屬於 multi-agent-patterns。此技能負責連接確定性程式碼與代理的介面層。

何時啟用

當工作單位是工具時啟用此技能:

  • 撰寫新的工具描述、架構或回應格式。
  • 除錯代理選錯工具或產生格式異常的呼叫。
  • 整併重疊的工具目錄(經典案例:「我們有 17 個工具,代理有一半時間會選錯」)。
  • 設計可操作的錯誤訊息,讓代理能自行修正。
  • 在整個目錄中一致地命名工具和參數(MCP 命名空間、動詞-名詞命名)。
  • 在新增第三方工具前,根據整併原則進行評估。

不要為其他技能負責的相鄰工作啟用此技能:

  • 決定專案是否應使用 LLM,或管線階段應為何:project-development。
  • 決定應將工作拆分給多個子代理,還是用一個代理搭配更多工具:multi-agent-patterns。
  • 在軌跡層級減少工具輸出的 token 重量(觀察遮蔽、大規模格式選項選擇):context-optimization。

核心概念

圍繞整併原則設計工具:如果人類工程師無法明確說出在特定情況下該使用哪個工具,就不能指望代理做得更好。減少工具集,直到每個工具只有一個明確的目的,因為代理透過比較描述來選擇工具,任何重疊都會導致選擇錯誤。

將每個工具描述視為塑造代理行為的提示工程。描述不是給人類看的文件——它會注入代理的上下文並直接引導推理。撰寫能回答工具做什麼、何時使用、以及回傳什麼的描述,因為這三個問題正是代理在工具選擇期間評估的內容。

詳細主題

工具-代理介面

工具作為合約 將每個工具設計為自包含的合約。當人類呼叫 API 時,他們會閱讀文件、理解慣例並發出適當的請求。代理必須從單一描述區塊中推斷整個合約。透過包含格式範例、預期模式和明確限制,讓合約明確無誤。不要遺漏任何呼叫者需要知道的資訊,因為代理在發出呼叫前無法提出澄清問題。

工具描述即提示 撰寫工具描述時要了解它們會直接載入代理上下文並共同引導行為。像「搜尋資料庫」這樣模糊的描述加上神秘的參數名稱,會迫使代理猜測——而猜測會產生錯誤的呼叫。相反地,應包含使用情境、參數格式範例和合理的預設值。描述中的每個字不是有助於提升工具選擇準確度,就是會損害它。

命名空間與組織 隨著工具集合增長,將工具置於常見前綴的命名空間下,因為代理受益於層級分組。當代理需要資料庫操作時,它會路由到 db_* 命名空間;當需要網路互動時,會路由到 web_*。沒有命名空間,代理必須在扁平列表中評估每個工具,這會隨著數量增加而降低選擇準確度。

整併原則

單一全面工具 建立單一全面工具,而不是多個重疊的狹義工具。與其分別實作 list_users、list_events 和 create_event,不如實作 schedule_event,它在一次呼叫中尋找可用時間並安排。全面工具在內部處理完整工作流程,免除代理以正確順序鏈式呼叫的負擔。

為何整併有效 應用整併原則,因為代理的上下文和注意力有限。集合中的每個工具在工具選擇期間競爭注意力,每個描述消耗上下文預算 token,重疊的功能會造成語意模糊。整併消除了冗餘的描述,移除了選擇上的語意模糊,並縮小了有效的工具集。Vercel 的 d0 案例研究是將專業工具減少為更小的原始工具集並獲得更好衡量結果的具體範例(claim-tool-design-vercel-d0-reduction)。

何時不該整併 當工具有根本不同的行為、服務於不同的情境,或必須能夠獨立呼叫時,應保持分開。過度整併會產生不同的問題:一個具有太多參數和模式的工具會讓代理難以正確設定參數。

架構簡化

將整併原則推向極致,用原始、通用用途的能力取代大多數專業工具。生產環境的證據顯示,這種方法可以勝過複雜的多工具架構。

檔案系統代理模式 透過單一指令執行工具提供直接的檔案系統存取,而不是為資料探索、架構查找和查詢驗證建立自訂工具。代理使用標準 Unix 工具(grep、cat、find、ls)來探索和操作系統。這之所以有效,是因為檔案系統是一個經過驗證的抽象,模型對其有深入理解;標準工具有可預測的行為;代理可以靈活地鏈式使用原始工具,而不受預定義工作流程的限制;以及檔案中的良好文件取代了摘要工具。

何時簡化勝過複雜 在以下情況選擇簡化:資料層文件完善且結構一致;模型具有足夠的推理能力;專業工具限制了而非賦能模型;花在維護支架上的時間多於改善成果。在以下情況避免簡化:底層資料混亂或文件不足;領域需要模型缺乏的專業知識;安全限制必須限制代理行為;或操作確實受益於結構化工作流程。

為未來模型而建 設計能從模型改進中受益的最小化架構,而不是鎖定當前限制的複雜架構。問問自己,每個工具是開啟了新的能力,還是限制了模型自己就能處理的推理——作為「護欄」而建立的工具,隨著模型進步往往會變成累贅。

參閱架構簡化案例研究以取得生產環境證據。

工具描述工程

描述結構 結構化每個工具描述以回答四個問題:

  1. 工具做什麼?精確陳述工具達成了什麼——避免使用「有助於」或「可用於」這類模糊語言。
  2. 何時應使用?指定直接觸發條件(「使用者詢問價格」)和間接訊號(「需要當前市場匯率」)。
  3. 它接受什麼輸入?描述每個參數的型別、限制、預設值和格式範例。
  4. 它回傳什麼?記錄輸出格式、結構、成功回應範例和錯誤條件。

預設參數選擇 設定反映常見使用案例的預設值。預設值透過消除不必要的參數指定來減輕代理負擔,並防止因省略參數而導致的錯誤。選擇能產生有用結果且無需代理理解每個選項的預設值。

回應格式最佳化

提供回應格式選項(簡潔 vs. 詳細),因為工具回應大小會顯著影響上下文使用。簡潔格式僅回傳必要欄位,適用於確認用途。詳細格式回傳完整物件,適用於完整上下文驅動決策的情況。在工具描述中記錄何時使用每種格式,以便代理學習適當選擇。

錯誤訊息設計

為兩個受眾設計錯誤訊息:除錯問題的開發人員和從失敗中恢復的代理。對代理來說,每個錯誤訊息必須是可操作的——它必須說明出了什麼問題以及如何修正。對於可重試的錯誤,包含重試指引;對於輸入錯誤,包含修正後的格式範例;對於不完整的請求,包含特定缺少的欄位。只說「失敗」的錯誤訊息不提供任何恢復訊號。

工具定義架構

在所有工具中建立一致的架構。對工具名稱使用動詞-名詞模式(get_customer、create_order),跨工具使用一致的參數名稱(始終使用 customer_id,而不是有時用 id 有時用 identifier),以及一致的回傳欄位名稱。一致性降低了代理的認知負載,並改善了跨工具的泛化能力。

工具集合設計

將工具集合限制為具有非重疊目的的最小集合,因為描述重疊會導致模型混淆,而且更多工具並不總是帶來更好的結果。當確實需要更多工具時,使用命名空間建立邏輯分組。實作選擇機制:按領域分組工具、基於範例的選擇提示,以及路由到專業子工具的傘狀工具。

MCP 工具命名要求

始終使用完全限定名稱搭配 MCP(Model Context Protocol)以避免「找不到工具」錯誤。

格式:伺服器名稱:工具名稱

# 正確:完全限定名稱
"使用 BigQuery:bigquery_schema 工具來取得資料表架構。"
"使用 GitHub:create_issue 工具來建立議題。"

# 錯誤:未限定名稱
"使用 bigquery_schema 工具..."  # 當有多個伺服器時可能失敗

沒有伺服器前綴,當有多個 MCP 伺服器可用時,代理可能無法找到工具。建立包含所有工具參考中伺服器上下文的命名慣例。

使用代理最佳化工具

將觀察到的工具失敗回饋給代理,以診斷問題並改善描述。將報告的效率提升視為工作負載特定的,直到在目標工具目錄上重現為止。

工具測試代理模式:

def optimize_tool_description(tool_spec, failure_examples):
    """
    使用代理分析工具失敗並改善描述。

    流程:
    1. 代理嘗試在各種任務中使用工具
    2. 收集失敗模式和摩擦點
    3. 代理分析失敗並提出改善建議
    4. 針對相同任務測試改善後的描述
    """
    prompt = f"""
    分析此工具規格和觀察到的失敗。

    工具:{tool_spec}

    觀察到的失敗:
    {failure_examples}

    識別:
    1. 代理為何在此工具上失敗
    2. 描述中缺少哪些資訊
    3. 哪些語意模糊導致不正確的使用

    提出一個能解決這些問題的改善後工具描述。
    """

    return get_agent_response(prompt)

這建立了一個反饋迴圈:使用工具的代理產生失敗資料,代理再使用這些資料來改善工具描述,進而減少未來的失敗。

測試工具設計

根據五個標準評估工具設計:明確性、完整性、可恢復性、效率和一致性。透過提出代表性代理請求並評估產生的工具呼叫是否符合預期行為來進行測試。

實用指引

工具選擇框架

設計工具集合時:

  1. 識別代理必須完成的獨特工作流程
  2. 將相關動作分組到全面工具中
  3. 確保每個工具都有明確、不模糊的目的
  4. 記錄錯誤案例和恢復路徑
  5. 使用實際代理互動進行測試

工具稽核查核清單

在將每個工具新增到代理前使用此核對清單:

  1. 名稱:動詞-名詞,如果目錄有多個領域則需命名空間。
  2. 描述:說明工具做什麼、何時使用以及回傳什麼。
  3. 架構:每個參數都有型別、限制、預設值和範例值。
  4. 回傳形狀:記錄成功和錯誤的承載內容,且為機器可讀。
  5. 恢復:每個錯誤告訴代理在重試前應更改什麼。
  6. 重疊:沒有其他工具具有相同的啟用情境。
  7. 整併決策:除非需要獨立呼叫,否則合併相鄰的狹義工具。
  8. Token 影響:大型回應支援簡潔模式或檔案參考模式。

範例

範例 1:設計良好的工具

def get_customer(customer_id: str, format: str = "concise"):
    """
    依 ID 擷取客戶資訊。

    使用時機:
    - 使用者詢問特定客戶詳細資料
    - 需要客戶背景資訊進行決策
    - 驗證客戶身份

    參數:
        customer_id:格式 "CUST-######"(例如 "CUST-000001")
        format:"concise" 用於關鍵欄位,"detailed" 用於完整記錄

    回傳:
        包含請求欄位的客戶物件

    錯誤:
        NOT_FOUND:找不到客戶 ID
        INVALID_FORMAT:ID 必須符合 CUST-###### 模式
    """

範例 2:設計不佳的工具

此範例展示幾個工具設計的反模式:

def search(query):
    """搜尋資料庫。"""
    pass

此設計的問題:

  1. 模糊的名稱:「search」語意不明——搜尋什麼、為了什麼目的?
  2. 缺少參數:哪個資料庫?query 應該是什麼格式?
  3. 沒有回傳描述:此函數回傳什麼?

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

advanced-evaluation

This skill should be used for advanced LLM evaluation: LLM-as-judge systems, direct scoring, pairwise comparison, rubric calibration, evaluator bias mitigation, confidence scoring, and automated quality assessment.

bdi-mental-states

This skill should be used when modeling agent mental states with BDI concepts: beliefs, desires, intentions, RDF-to-belief transformations, rational agency traces, cognitive agents, BDI ontologies, and neuro-symbolic AI integration.

book-sft-pipeline

This skill should be used for book-to-SFT pipelines: ePub extraction, literary segmentation, author-voice dataset construction, style-transfer training, LoRA workflows, and model evaluation for voice replication.

compaction-control-profiling

This skill should be used when deciding, for a specific model and workload, whether the harness or the model should control compaction, and when qualifying or calibrating that choice with measurements: context-budget sweeps that compare harness-driven and model-driven compaction on one harness, the context-pressure regime where delegation pays, a per-model compaction behavior profile (interface uptake, compression factor per call, reopen rate of archived content, context fill at first compaction, response to pressure warnings), context anxiety and timing-instruction calibration, reversible collapse-and-archive interfaces, and re-qualification after a model or prompt change. Route the editable-file protocol, harness invariants, and edit-position cache cost of self-editing agents to self-managed-context, summary content to context-compression, harness thresholds and cache layout to context-optimization, and general evaluation design to evaluation.

comprehensive-research-agent

Ensure thorough validation, error recovery, and transparent reasoning in research tasks with multiple tool calls

context-compression

This skill should be used when long-running agent sessions need context compression, structured summarization, compaction, token-per-task optimization, or durable handoff summaries that preserve decisions, files, risks, and next actions.

context-degradation

This skill should be used for diagnosing and mitigating context degradation: lost-in-middle failures, context poisoning, context clash, context confusion, attention-pattern issues, and agent performance degradation caused by accumulated or conflicting context.

context-fundamentals

This skill should be used to explain or reason about the foundational concepts of context engineering: what context is, the anatomy of a context window, how attention mechanics work, the U-shaped attention curve, why context quality matters more than quantity, and the mental models needed to interpret every other context-engineering decision. Use this for conceptual explanation, onboarding, and background reading. Route operational work to the specialized skills: debugging attention failures goes to context-degradation, token-efficiency work goes to context-optimization, conversation summarization goes to context-compression, and project-shape decisions go to project-development.

context-optimization

This skill should be used for improving context efficiency: context budgeting, observation masking, prefix or KV-cache strategy, partitioning, token-cost reduction, retrieval scoping, and extending effective context capacity without lowering answer quality.

evaluation

This skill should be used when building agent evaluation systems: deterministic checks, regression suites, multi-dimensional rubrics, quality gates, production monitoring, baseline comparison, and outcome measurement for agent pipelines.

filesystem-context

This skill should be used when agent work needs file-backed context: durable scratchpads, tool-output offloading, just-in-time discovery, cross-agent handoff files, filesystem memory, or cleanup policies for context stored outside the prompt.

harness-engineering

This skill should be used when designing autonomous agent harnesses: research loops, evaluation scaffolds, locked and editable surfaces, durable logs, novelty gates, pruning, rollback, PR preparation, and human approval boundaries.

hosted-agents

This skill should be used when designing hosted or background agent infrastructure: sandboxed execution, remote coding environments, warm pools, session persistence, multiplayer collaboration, self-spawning agents, or Modal-style sandboxes.

instruction-surface-security

Hardens agent runtimes against persistent prompt injection or unauthorized changes to instructions and permissions. Use to audit what agents auto-load, design reviewed activation for project rules, skills, memory, or tool configuration, and test whether trust boundaries hold after reload, restart, or delegation.

latent-briefing

This skill should be used when the user asks to "share memory between agents", "KV cache compaction for multi-agent", "orchestrator worker context", "latent briefing", "reduce worker tokens", "cross-agent memory without summarization", or discusses Attention Matching compaction, recursive language models with workers, or token explosion in hierarchical agents.

long-horizon-prompting

This skill should be used when writing, enhancing, or evaluating the launch prompt for a long-running autonomous agent or a parallel multi-agent orchestration attacking a hard problem: pseudo-formal task briefs that define terms and an exact success predicate linguistically, enumerate non-counting outcomes, set persistence rules with explicit stop and return conditions and effort floors, manage a diverse portfolio of parallel approaches with an approach registry and blocked-route bookkeeping, and gate the return on adversarial audit. Route agent topology and coordination protocols to multi-agent-patterns, runtime control surfaces and loop governance to harness-engineering, evaluator and quality-gate construction to evaluation, judge design to advanced-evaluation, and compaction or memory mechanics to context-compression and memory-systems.

memory-systems

This skill should be used for persistent semantic memory in agent systems: cross-session knowledge retention, entity tracking, temporal validity, graph or vector retrieval, memory consolidation, and memory benchmark selection. Route file-backed scratchpads to filesystem-context, handoff summaries to context-compression, and token-efficiency tactics to context-optimization.

multi-agent-patterns

This skill should be used when designing multi-agent systems that need context isolation, supervisor or swarm coordination, explicit handoffs, parallel execution, or a decision on whether multiple agents are justified.

project-development

This skill should be used for project-level decisions about LLM-powered systems: whether an LLM is the right primitive for the task at hand, the shape of a multi-stage batch or agent pipeline, token and cost estimation, choosing between single-agent and multi-agent at the project level, structured output design for downstream parsing, and structuring agent-assisted iteration. Use this when the unit of work is a whole project or a multi-stage pipeline. Route individual tool design to tool-design and individual skill-loading or context-budget tactics to context-optimization.

self-improvement-loops

This skill should be used when the harness, scaffold, workflow, or optimizer itself is the optimization target: recursive self-improvement (RSI) loops, meta-harnesses, self-improving harnesses that mine their own failures and propose bounded edits, evolutionary or population-based search over agent scaffolds, acceptance gates for self-modifying systems, and agentic context evolution where the mechanism that produces context is versioned and evolved. Route governance of a single autonomous loop (locked surfaces, durable logs, rollback, novelty gates, approval boundaries) to harness-engineering, measurement and quality-gate design to evaluation, judge design to advanced-evaluation, and remote sandbox infrastructure to hosted-agents.

相關技能