agent-lifecycle-management
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAgent Lifecycle Management Skill
Agent生命周期管理Skill
Manage agent fleets through Create, Command, Monitor, and Delete operations.
通过创建、指挥、监控和删除操作管理Agent集群。
Purpose
用途
Guide the implementation of CRUD operations for agent fleets, ensuring proper lifecycle management and resource cleanup.
指导Agent集群CRUD操作的实现,确保合理的生命周期管理和资源清理。
When to Use
适用场景
- Setting up agent lifecycle patterns
- Implementing agent management tools
- Designing cleanup and resource management
- Building agent state tracking
- 搭建Agent生命周期模式
- 实现Agent管理工具
- 设计清理与资源管理机制
- 构建Agent状态追踪系统
Prerequisites
前置条件
- Understanding of orchestrator architecture (@single-interface-pattern.md)
- Familiarity with the Three Pillars (@three-pillars-orchestration.md)
- Access to Claude Agent SDK documentation
- 了解编排器架构(@single-interface-pattern.md)
- 熟悉三大支柱(@three-pillars-orchestration.md)
- 可访问Claude Agent SDK文档
SDK Requirement
SDK要求
Implementation Note: Full lifecycle management requires Claude Agent SDK with custom MCP tools. This skill provides design patterns for SDK implementation.
实现说明:完整的生命周期管理需要带有自定义MCP工具的Claude Agent SDK。本Skill提供SDK实现的设计模式。
Lifecycle Pattern
生命周期模式
text
Create --> Command --> Monitor --> Aggregate --> Delete
| | | | |
v v v v v
Template Prompt Status Results Cleanuptext
Create --> Command --> Monitor --> Aggregate --> Delete
| | | | |
v v v v v
Template Prompt Status Results CleanupCRUD Operations
CRUD操作
Create Operation
创建操作
Spin up a new specialized agent.
Parameters:
- : Pre-defined configuration to use
template - : Unique identifier for this agent
name - : Custom prompt (alternative to template)
system_prompt - : haiku, sonnet, or opus
model - : Tools this agent can use
allowed_tools
Example:
python
create_agent(
name="scout_1",
template="scout-fast",
# OR
system_prompt="...",
model="haiku",
allowed_tools=["Read", "Glob", "Grep"]
)Best Practices:
- Use templates for consistency
- Give descriptive names
- Select appropriate model
- Minimize tool access
启动一个新的专用Agent。
参数:
- :要使用的预定义配置
template - :该Agent的唯一标识符
name - :自定义提示词(替代template)
system_prompt - :haiku、sonnet或opus
model - :该Agent可使用的工具
allowed_tools
示例:
python
create_agent(
name="scout_1",
template="scout-fast",
# OR
system_prompt="...",
model="haiku",
allowed_tools=["Read", "Glob", "Grep"]
)最佳实践:
- 使用模板确保一致性
- 赋予描述性名称
- 选择合适的model
- 最小化工具访问权限
Command Operation
指挥操作
Send prompts to an agent.
Parameters:
- : Which agent to command
agent_id - : The detailed instruction
prompt
Example:
python
command_agent(
agent_id="scout_1",
prompt="""
Analyze the authentication module in src/auth/.
Focus on:
1. Current implementation patterns
2. Security considerations
3. Potential improvements
Report findings in structured format.
"""
)Best Practices:
- Detailed, specific prompts
- Clear expected output format
- Include all relevant context
- One task per command
向Agent发送提示词。
参数:
- :要指挥的Agent ID
agent_id - :详细指令
prompt
示例:
python
command_agent(
agent_id="scout_1",
prompt="""
分析src/auth/目录下的认证模块。
重点关注:
1. 当前实现模式
2. 安全考量
3. 潜在改进方向
以结构化格式报告分析结果。
"""
)最佳实践:
- 使用详细、具体的提示词
- 明确预期输出格式
- 包含所有相关上下文
- 单条指令对应单个任务
Monitor Operation (Read)
监控操作(读取)
Check agent status and progress.
Operations:
python
undefined检查Agent的状态与进度。
操作示例:
python
undefinedCheck status
检查状态
check_agent_status(
agent_id="scout_1",
verbose_logs=True
)
check_agent_status(
agent_id="scout_1",
verbose_logs=True
)
List all agents
列出所有Agent
list_agents()
list_agents()
Read agent logs
读取Agent日志
read_agent_logs(
agent_id="scout_1",
offset=0,
limit=50
)
**Status Values**:
| Status | Meaning |
| --- | --- |
| `idle` | Ready for commands |
| `executing` | Processing prompt |
| `waiting` | Waiting for input |
| `blocked` | Permission needed |
| `complete` | Finished |read_agent_logs(
agent_id="scout_1",
offset=0,
limit=50
)
**状态值说明**:
| 状态 | 含义 |
| --- | --- |
| `idle` | 就绪,可接收指令 |
| `executing` | 正在处理提示词 |
| `waiting` | 等待输入 |
| `blocked` | 需要权限 |
| `complete` | 已完成 |Delete Operation
删除操作
Clean up agents when work is complete.
Example:
python
delete_agent(agent_id="scout_1")Key Principle:
"Treat agents as deletable temporary resources that serve a single purpose."
任务完成后清理Agent。
示例:
python
delete_agent(agent_id="scout_1")核心原则:
"将Agent视为可删除的临时资源,仅服务于单一目标。"
Lifecycle Patterns
生命周期模式
Scout-Build Pattern
侦察-构建模式
text
1. Create scout agent
2. Command: Analyze codebase
3. Monitor until complete
4. Aggregate scout findings
5. Delete scout
6. Create builder agent
7. Command: Implement based on findings
8. Monitor until complete
9. Aggregate build results
10. Delete buildertext
1. 创建侦察Agent
2. 下达指令:分析代码库
3. 监控直至完成
4. 汇总侦察结果
5. 删除侦察Agent
6. 创建构建Agent
7. 下达指令:基于分析结果实现功能
8. 监控直至完成
9. 汇总构建结果
10. 删除构建AgentScout-Build-Review Pattern
侦察-构建-评审模式
text
Phase 1: Scout
- Create scouts (parallel)
- Command each with specific area
- Aggregate findings
Phase 2: Build
- Create builder
- Command with scout reports
- Monitor implementation
Phase 3: Review
- Create reviewer
- Command to verify implementation
- Generate final report
Cleanup: Delete all agentstext
阶段1:侦察
- 创建多个侦察Agent(并行)
- 为每个Agent分配特定分析领域
- 汇总分析结果
阶段2:构建
- 创建构建Agent
- 基于侦察报告下达指令
- 监控实现过程
阶段3:评审
- 创建评审Agent
- 下达指令验证实现效果
- 生成最终报告
清理:删除所有AgentParallel Execution
并行执行模式
text
Create: scout_1, scout_2, scout_3 (parallel)
Command each with different area
Monitor all until complete
Aggregate all findings
Delete all scouts
Create: builder_1, builder_2 (parallel)
Command each with different files
Monitor all until complete
Aggregate all changes
Delete all builderstext
创建:scout_1、scout_2、scout_3(并行)
为每个Agent分配不同分析领域
监控所有Agent直至完成
汇总所有分析结果
删除所有侦察Agent
创建:builder_1、builder_2(并行)
为每个Agent分配不同文件任务
监控所有Agent直至完成
汇总所有修改内容
删除所有构建AgentAgent Templates
Agent模板
Fast Scout Template
快速侦察模板
yaml
---
name: scout-fast
description: Quick codebase reconnaissance
tools: [Read, Glob, Grep]
model: haiku
---yaml
---
name: scout-fast
description: 快速代码库侦察
tools: [Read, Glob, Grep]
model: haiku
---Scout Agent
Scout Agent
Analyze codebase efficiently. Focus on:
- File structure
- Key patterns
- Relevant code sections
Report findings concisely.
undefined高效分析代码库。重点关注:
- 文件结构
- 核心模式
- 相关代码段
简洁报告分析结果。
undefinedBuilder Template
构建模板
yaml
---
name: builder
description: Code implementation specialist
tools: [Read, Write, Edit, Bash]
model: sonnet
---yaml
---
name: builder
description: 代码实现专家
tools: [Read, Write, Edit, Bash]
model: sonnet
---Builder Agent
Builder Agent
Implement changes based on specifications.
Follow existing patterns.
Test your changes.
Report what was modified.
undefined基于需求实现代码修改。
遵循现有代码模式。
测试修改内容。
报告修改详情。
undefinedReviewer Template
评审模板
yaml
---
name: reviewer
description: Code review and verification
tools: [Read, Grep, Glob, Bash]
model: sonnet
---yaml
---
name: reviewer
description: 代码评审与验证
tools: [Read, Grep, Glob, Bash]
model: sonnet
---Reviewer Agent
Reviewer Agent
Verify implementation against requirements.
Check for issues and risks.
Report findings by severity.
undefined验证实现是否符合需求。
检查问题与风险。
按严重程度报告结果。
undefinedState Tracking
状态追踪
Track agent state for observability:
json
{
"agent_id": "scout_1",
"template": "scout-fast",
"status": "executing",
"created_at": "2024-01-15T10:30:00Z",
"last_activity": "2024-01-15T10:32:15Z",
"context_tokens": 12500,
"cost": 0.05,
"tool_calls": 15
}追踪Agent状态以实现可观测性:
json
{
"agent_id": "scout_1",
"template": "scout-fast",
"status": "executing",
"created_at": "2024-01-15T10:30:00Z",
"last_activity": "2024-01-15T10:32:15Z",
"context_tokens": 12500,
"cost": 0.05,
"tool_calls": 15
}Resource Cleanup
资源清理
Cleanup Triggers
清理触发条件
| Trigger | Action |
|---|---|
| Work complete | Delete immediately |
| Error state | Delete and report |
| Timeout | Delete and warn |
| User abort | Delete all |
| 触发条件 | 操作 |
|---|---|
| 任务完成 | 立即删除 |
| 错误状态 | 删除并上报 |
| 超时 | 删除并发出警告 |
| 用户终止 | 删除所有Agent |
Cleanup Checklist
清理检查清单
- All agents have termination logic
- Dead agents are detected
- Resources are released
- Final results are captured
- Cleanup is logged
- 所有Agent都有终止逻辑
- 可检测已失效Agent
- 已释放资源
- 已捕获最终结果
- 已记录清理操作
Output Format
输出格式
When implementing lifecycle management, provide:
markdown
undefined实现生命周期管理时,需提供以下内容:
markdown
undefinedLifecycle Implementation
生命周期实现
Agent Templates
Agent模板
[List of templates with configurations]
[包含配置的模板列表]
CRUD Tools
CRUD工具
| Tool | Implementation | Parameters |
|---|---|---|
| create_agent | ... | ... |
| command_agent | ... | ... |
| check_agent_status | ... | ... |
| list_agents | ... | ... |
| delete_agent | ... | ... |
| 工具 | 实现方式 | 参数 |
|---|---|---|
| create_agent | ... | ... |
| command_agent | ... | ... |
| check_agent_status | ... | ... |
| list_agents | ... | ... |
| delete_agent | ... | ... |
State Schema
状态Schema
[JSON schema for agent state]
[Agent状态的JSON Schema]
Cleanup Logic
清理逻辑
[When and how agents are deleted]
undefined[Agent的删除时机与方式]
undefinedAnti-Patterns
反模式
| Anti-Pattern | Problem | Solution |
|---|---|---|
| Keeping dead agents | Resource waste | Delete when done |
| Long-lived agents | Context accumulation | Fresh agents per task |
| Generic agents | Unfocused work | Specialized templates |
| Missing cleanup | Dead agents accumulate | Always delete |
| Reusing agents | Context contamination | Create fresh |
| 反模式 | 问题 | 解决方案 |
|---|---|---|
| 保留已失效Agent | 资源浪费 | 任务完成后立即删除 |
| 长期存活Agent | 上下文堆积 | 每个任务使用全新Agent |
| 通用型Agent | 工作重点不明确 | 使用专用模板 |
| 缺失清理逻辑 | 已失效Agent堆积 | 始终执行删除操作 |
| 复用Agent | 上下文污染 | 创建全新Agent |
Key Quotes
核心引用
"The rate at which you create and command your agents becomes the constraint of your engineering output.""One agent, one prompt, one purpose - then delete."
"创建和指挥Agent的速度将成为工程产出的约束条件。""一个Agent、一条提示词、一个目标——完成即删除。"
Cross-References
交叉引用
- @agent-lifecycle-crud.md - Lifecycle patterns
- @three-pillars-orchestration.md - CRUD pillar
- @single-interface-pattern.md - Orchestrator architecture
- @orchestrator-design skill - System design
- @agent-lifecycle-crud.md - 生命周期模式
- @three-pillars-orchestration.md - CRUD支柱
- @single-interface-pattern.md - 编排器架构
- @orchestrator-design skill - 系统设计
Version History
版本历史
- v1.0.0 (2025-12-26): Initial release
- v1.0.0 (2025-12-26):初始版本
Last Updated
最后更新
Date: 2025-12-26
Model: claude-opus-4-5-20251101
日期:2025-12-26
模型:claude-opus-4-5-20251101