Community编程与开发github.com

工具设计

此技能用于智能体系统的工具接口层:编写智能体可路由的工具描述、设计工具模式与响应格式、命名规范、可操作的错误恢复消息、MCP服务器设计、工具集整合,以及决定何时添加或移除单个工具。当工作单元是单个工具或一组工具时使用。将项目结构、流水线架构和任务模型适配决策路由到项目开发;将是否引入子智能体的决策路由到多智能体模式。

工具设计 是什么?

该技能专注于智能体系统中工具接口层的设计,核心原则是将每个工具视为确定性系统与非确定性智能体之间的契约。与面向人类的API不同,面向智能体的工具必须通过描述本身消除歧义,因为智能体从描述中推断意图并生成调用。任何模糊性都可能成为无法通过提示工程修复的失败模式。技能强调整合原则:如果人类工程师无法明确判断在特定情况下应使用哪个工具,就不能期望智能体做得更好。因此应减少工具集,直到每个工具有唯一明确的目的。它涵盖了工具描述工程、响应格式优化、错误消息设计、MCP命名规范,并通过“文件系统智能体模式”等案例提倡架构精简——用原始通用能力取代专门化工具。该技能支持Claude Code、Cursor、Codex等平台,工作单元是单个工具或工具目录,而项目结构、流水线架构和任务模型适配决策则属于项目开发技能的范围。

兼容平台~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交互时,路由到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. 它返回什么?记录输出格式、结构、成功响应示例和错误条件。

默认参数选择 设置默认值以反映常见用例。默认值通过消除不必要的参数指定来减轻智能体负担,并防止因省略参数而产生的错误。选择能产生有用结果且无需智能体理解每个选项的默认值。

响应格式优化

提供响应格式选项(简洁与详细),因为工具响应大小显著影响上下文使用。简洁格式仅返回必要字段,适用于确认。详细格式返回完整对象,适用于需要完整上下文来驱动决策的情况。在工具描述中记录何时使用每种格式,以便智能体学会适当选择。

错误消息设计

为两类受众设计错误消息:调试问题的开发人员和从故障中恢复的智能体。对于智能体,每个错误消息都必须是可操作的——它必须说明出了什么问题以及如何纠正。对于可重试的错误,包含重试指南;对于输入错误,包含更正后的格式示例;对于不完整的请求,包含具体缺失字段。只显示“失败”的错误消息不提供任何恢复信号。

工具定义模式

在所有工具中建立一致的模式。对工具名称使用动词-名词模式(get_customer、create_order),在所有工具中保持一致参数名称(始终使用customer_id,而不是有时用id、有时用identifier),并保持一致返回字段名称。一致性降低了智能体的认知负荷,并改善了跨工具泛化。

工具集合设计

将工具集合限制为具有非重叠目的的最小集合,因为描述重叠会导致模型混淆,并且更多的工具并不总能带来更好的结果。当确实需要更多工具时,使用命名空间创建逻辑分组。实现选择机制:按域分组工具、基于示例的选择提示、以及路由到专门子工具的伞形工具。

MCP工具命名要求

始终使用带有MCP(模型上下文协议)的完全限定工具名称,以避免“工具未找到”错误。

格式:ServerName:tool_name

# 正确:完全限定名
“使用 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. 缺少参数:哪个数据库?查询应采用什么格式?
  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.

相关技能