[ PROMPT_NODE_23626 ]
智能体开发
[ SKILL_DOCUMENTATION ]
# Claude Code 插件的智能体开发
## 概述
智能体是自主子进程,能够独立处理复杂的、多步骤的任务。理解智能体结构、触发条件和系统提示词设计,有助于创建强大的自主能力。
**核心概念:**
- 智能体用于自主工作,命令用于用户发起的动作
- 使用带有 YAML 前言的 Markdown 文件格式
- 通过带有示例的 description 字段触发
- 系统提示词定义智能体行为
- 模型和颜色自定义
## 智能体文件结构
### 完整格式
markdown
---
name: agent-identifier
description: Use this agent when [triggering conditions]. Examples:
Context: [Situation description]
user: "[User request]"
assistant: "[How assistant should respond and use this agent]"
[Why this agent should be triggered]
[Additional example...]
model: inherit
color: blue
tools: ["Read", "Write", "Grep"]
---
You are [agent role description]...
**Your Core Responsibilities:**
1. [Responsibility 1]
2. [Responsibility 2]
**Analysis Process:**
[Step-by-step workflow]
**Output Format:**
[What to return]
## 前言字段
### name (必填)
用于命名空间和调用的智能体标识符。
**格式:** 仅限小写字母、数字、连字符
**长度:** 3-50 个字符
**模式:** 必须以字母数字开头和结尾
**良好示例:**
- `code-reviewer`
- `test-generator`
- `api-docs-writer`
- `security-analyzer`
**错误示例:**
- `helper` (太通用)
- `-agent-` (以连字符开头/结尾)
- `my_agent` (不允许使用下划线)
- `ag` (太短,< 3 字符)
### description (必填)
定义 Claude 何时触发此智能体。**这是最关键的字段。**
**必须包含:**
1. 触发条件 ("Use this agent when...")
2. 展示用法的多个 `` 块
3. 每个示例中的上下文、用户请求和助手响应
4. 解释为何触发智能体的 ``
**格式:**
Use this agent when [conditions]. Examples:
Context: [Scenario description]
user: "[What user says]"
assistant: "[How Claude should respond]"
[Why this agent is appropriate]
[More examples...]
**最佳实践:**
- 包含 2-4 个具体示例
- 展示主动和被动触发
- 涵盖同一意图的不同表述
- 在 commentary 中解释推理过程
- 明确说明何时“不”使用该智能体