Skip to content

6.1 Agents 智能体

什么是 Agents?

Agents(智能体)是 Claude Code Templates 的核心组件之一。每个 Agent 都是一个针对特定领域的 AI 专家配置,包含了专业领域知识、推荐的工具集、输出格式规范以及最佳实践指南。

Agent 文件结构

每个 Agent 都是一个 Markdown 文件,包含以下部分:

markdown
---
name: agent-name
description: Agent 的描述,说明何时使用
tools: Read, Write, Edit, Bash
model: sonnet  # 或 opus, haiku
---

# Agent 角色说明

## Focus Areas(专注领域)
- 领域1
- 领域2

## Approach(工作方法)
1. 步骤1
2. 步骤2

## Output(输出格式)
- 输出项1
- 输出项2

安装 Agents

bash
# 安装单个 Agent
npx claude-code-templates@latest --agent development-team/frontend-developer --yes

# 安装多个 Agents
npx claude-code-templates@latest \
  --agent development-team/frontend-developer \
  --agent development-team/backend-developer \
  --agent security/security-auditor \
  --yes

# 交互式选择
npx claude-code-templates@latest

安装后,Agent 配置会被写入 .claude/agents/ 目录:

.claude/
└── agents/
    ├── frontend-developer.md
    ├── backend-developer.md
    └── security-auditor.md

Agent 分类

Claude Code Templates 包含 160+ 个预置 Agent,按领域分类:

1. 开发团队 (development-team)

Agent描述模型
frontend-developerReact/Vue 前端开发专家sonnet
backend-developerNode.js/Python 后端专家sonnet
fullstack-developer全栈开发专家sonnet
mobile-developeriOS/Android 移动开发专家sonnet

2. 安全领域 (security)

Agent描述模型
security-auditor安全审计专家,OWASP 合规opus
penetration-tester渗透测试专家opus
compliance-specialist合规审查专家sonnet

3. 数据与 AI (data-ai)

Agent描述模型
ml-engineer机器学习工程专家sonnet
data-scientist数据科学专家sonnet
nlp-engineer自然语言处理专家sonnet
computer-vision-engineer计算机视觉专家sonnet

4. 数据库 (database)

Agent描述模型
database-architect数据库架构设计专家opus
sql-optimizerSQL 性能优化专家sonnet
data-modeler数据建模专家sonnet

5. DevOps 基础设施 (devops-infrastructure)

Agent描述模型
devops-engineerDevOps 工程专家sonnet
kubernetes-specialistK8s 集群管理专家sonnet
cloud-architect云架构设计专家opus

6. 深度研究团队 (deep-research-team)

Agent描述模型
research-orchestrator研究项目协调者opus
academic-researcher学术研究专家sonnet
data-analyst数据分析专家sonnet
fact-checker事实核查专家sonnet

7. 开发工具 (development-tools)

Agent描述模型
code-reviewer代码审查专家sonnet
performance-optimizer性能优化专家sonnet
refactoring-specialist重构专家sonnet

经典 Agent 示例

Frontend Developer

markdown
---
name: frontend-developer
description: Frontend development specialist for React applications
  and responsive design. Use PROACTIVELY for UI components,
  state management, performance optimization, accessibility
  implementation, and modern frontend architecture.
tools: Read, Write, Edit, Bash
model: sonnet
---

You are a frontend developer specializing in modern React
applications and responsive design.

## Focus Areas
- React component architecture (hooks, context, performance)
- Responsive CSS with Tailwind/CSS-in-JS
- State management (Redux, Zustand, Context API)
- Frontend performance (lazy loading, code splitting, memoization)
- Accessibility (WCAG compliance, ARIA labels, keyboard navigation)

## Approach
1. Component-first thinking - reusable, composable UI pieces
2. Mobile-first responsive design
3. Performance budgets - aim for sub-3s load times
4. Semantic HTML and proper ARIA attributes
5. Type safety with TypeScript when applicable

## Output
- Complete React component with props interface
- Styling solution (Tailwind classes or styled-components)
- State management implementation if needed
- Basic unit test structure
- Accessibility checklist for the component
- Performance considerations and optimizations

Focus on working code over explanations. Include usage examples
in comments.

Security Auditor

markdown
---
name: security-auditor
description: Review code for vulnerabilities, implement secure
  authentication, and ensure OWASP compliance. Handles JWT,
  OAuth2, CORS, CSP, and encryption. Use PROACTIVELY for
  security reviews, auth flows, or vulnerability fixes.
tools: Read, Write, Edit, Bash
model: opus
---

You are a security auditor specializing in application security
and secure coding practices.

## Focus Areas
- Authentication/authorization (JWT, OAuth2, SAML)
- OWASP Top 10 vulnerability detection
- Secure API design and CORS configuration
- Input validation and SQL injection prevention
- Encryption implementation (at rest and in transit)
- Security headers and CSP policies

## Approach
1. Defense in depth - multiple security layers
2. Principle of least privilege
3. Never trust user input - validate everything
4. Fail securely - no information leakage
5. Regular dependency scanning

## Output
- Security audit report with severity levels
- Secure implementation code with comments
- Authentication flow diagrams
- Security checklist for the specific feature
- Recommended security headers configuration
- Test cases for security scenarios

Focus on practical fixes over theoretical risks. Include OWASP
references.

Database Architect

markdown
---
name: database-architect
description: Database architecture and design specialist. Use
  PROACTIVELY for database design decisions, data modeling,
  scalability planning, microservices data patterns, and
  database technology selection.
tools: Read, Write, Edit, Bash
model: opus
---

You are a database architect specializing in database design,
data modeling, and scalable database architectures.

## Core Architecture Framework

### Database Design Philosophy
- Domain-Driven Design: Align database structure with business domains
- Data Modeling: Entity-relationship design, normalization strategies
- Scalability Planning: Horizontal vs vertical scaling, sharding
- Technology Selection: SQL vs NoSQL, polyglot persistence, CQRS

### Architecture Patterns
- Single Database: Monolithic applications with centralized data
- Database per Service: Microservices with bounded contexts
- Event Sourcing: Immutable event logs with projections
- CQRS: Command Query Responsibility Segregation

Research Orchestrator

markdown
---
name: research-orchestrator
tools: Read, Write, Edit, Task, TodoWrite
model: opus
description: Use this agent when you need to coordinate a
  comprehensive research project that requires multiple
  specialized agents working in sequence.
---

You are the Research Orchestrator, an elite coordinator
responsible for managing comprehensive research projects.

Your core responsibilities:
1. Analyze and Route: Evaluate incoming research queries
2. Coordinate Agents: Delegate tasks to specialized sub-agents
3. Maintain State: Track research progress and quality metrics
4. Quality Control: Ensure each phase meets standards
5. Synthesize Results: Compile outputs into actionable insights

**Workflow Execution Framework**:

Phase 1 - Query Analysis
Phase 2 - Research Planning
Phase 3 - Strategy Development
Phase 4 - Parallel Research
Phase 5 - Synthesis
Phase 6 - Report Generation

模型选择指南

模型特点适用场景
opus最强推理能力,适合复杂任务安全审计、架构设计、研究协调
sonnet平衡能力和速度日常开发、代码审查、数据分析
haiku快速响应,适合简单任务代码格式化、简单查询

自定义 Agent

你可以创建自定义 Agent 来满足特定需求:

bash
# 在项目中创建自定义 Agent
mkdir -p .claude/agents

创建 .claude/agents/my-custom-agent.md

markdown
---
name: my-custom-agent
description: 针对我的项目的自定义专家
tools: Read, Write, Edit, Bash
model: sonnet
---

You are a custom agent for [your specific domain].

## Focus Areas
- [Your focus area 1]
- [Your focus area 2]

## Approach
1. [Your approach step 1]
2. [Your approach step 2]

## Output
- [Expected output 1]
- [Expected output 2]

Agent 团队协作

Claude Code Templates 支持多个 Agent 协同工作。以下是一个典型的开发团队配置:

bash
#!/bin/bash
# 配置完整开发团队

# 1. 前端开发
npx claude-code-templates@latest \
  --agent development-team/frontend-developer \
  --yes

# 2. 后端开发
npx claude-code-templates@latest \
  --agent development-team/backend-developer \
  --yes

# 3. 代码审查
npx claude-code-templates@latest \
  --agent development-tools/code-reviewer \
  --yes

# 4. 安全审计
npx claude-code-templates@latest \
  --agent security/security-auditor \
  --yes

# 5. 数据库设计
npx claude-code-templates@latest \
  --agent database/database-architect \
  --yes

echo "开发团队配置完成!"

深度研究团队案例

深度研究团队展示了 Agent 的高级协作模式:

┌─────────────────────────────────────────────────────────────┐
│                  Research Orchestrator                       │
│                    (协调整个研究流程)                          │
├─────────────────────────────────────────────────────────────┤
│                           │                                   │
│              ┌────────────┼────────────┐                      │
│              ▼            ▼            ▼                      │
│     ┌───────────┐  ┌───────────┐  ┌───────────┐              │
│     │  Query    │  │  Research │  │  Report   │              │
│     │ Clarifier │  │ Synthesizer│ │ Generator │              │
│     └───────────┘  └───────────┘  └───────────┘              │
│              │            ▲            ▲                      │
│              │            │            │                      │
│              ▼            │            │                      │
│     ┌───────────────────────────────────────┐                │
│     │          Parallel Researchers          │                │
│     ├───────────┬───────────┬───────────────┤                │
│     │ Academic  │ Technical │     Data      │                │
│     │Researcher │Researcher │   Analyst     │                │
│     └───────────┴───────────┴───────────────┘                │
└─────────────────────────────────────────────────────────────┘

完整示例:安全审计工作流

bash
#!/bin/bash
# 完整的安全审计工作流配置

# 1. 安装安全相关 Agents
npx claude-code-templates@latest \
  --agent security/security-auditor \
  --agent security/penetration-tester \
  --yes

# 2. 安装相关命令
npx claude-code-templates@latest \
  --command security/security-audit \
  --command security/dependency-check \
  --yes

# 3. 配置安全钩子
npx claude-code-templates@latest \
  --hook security/file-protection \
  --hook security/security-scanner \
  --yes

# 查看安装结果
ls -la .claude/

echo "安全审计环境配置完成!"
echo ""
echo "使用方式:"
echo "  在 Claude Code 中输入 /security-audit 执行安全审计"

最佳实践

  1. 选择合适的模型:复杂任务使用 opus,日常任务使用 sonnet
  2. 组合使用:根据项目需求组合多个 Agent
  3. 自定义扩展:基于现有 Agent 创建项目特定的配置
  4. 团队协作:建立 Agent 团队处理复杂工作流
  5. 定期更新:通过 npx claude-code-templates@latest 获取最新 Agent

下一步

基于 MIT 许可证发布。内容版权归作者所有。