AgentSkillsCN

Subagent Design Patterns

设计高效子代理的核心原则。当用户要求“设计子代理”、“构建子代理结构”、“子代理最佳实践”时,可使用此功能。同时提供详尽的指导,并附上相关参考资料,供深入探索。

SKILL.md
--- frontmatter
name: Subagent Design Patterns
description: Core principles for designing effective subagents. Use when asked to "design a subagent", "structure a subagent", "subagent best practices". Provides essential guidance with references for deep dives.
version: 0.2.0

Core Concepts

A subagent is an autonomous AI assistant with custom configuration, operating in its own context window.

When to Use Subagents vs. Main Conversation

Use Main ConversationUse Subagents
Iterative refinementVerbose output (logs, data)
Shared context across phasesTool restrictions needed
Frequent user feedbackSelf-contained tasks
Low latency requiredParallel/background work

Key trade-off: Subagents isolate context but start fresh. Use for self-contained tasks with summary outputs.

For detailed analysis, see references/when-to-use.md.

Five Core Design Decisions

1. Role Clarity (Most Critical)

Write descriptions with:

  • Role statement: "Database performance analyst"
  • Triggers: "Analyze slow queries", "Explain execution plans"
  • Boundaries: "Not for schema design"

Poor: description: Helps with debugging Strong: description: Database query performance specialist. Use proactively when analyzing slow queries or explaining execution plans. Not for schema design.

See references/role-clarity.md for complete guide with examples.

2. Tool Access Strategy

Grant minimum necessary tools:

PatternToolsUse For
Read-only["Read", "Grep", "Glob"]Reviewers, analyzers
Generation["Read", "Write", "Bash"]Creators, scaffolders
Modification["Read", "Edit", "Bash"]Fixers, debuggers

See references/tool-patterns.md for complete patterns and examples.

3. Model Selection

ModelBest ForCost
haikuData analysis, validation~90% cheaper
sonnetCode tasks (recommended default)Balanced
opusComplex reasoningHighest
inheritMatch parent (most common)Varies

4. Permission Modes

  • default - Standard prompts (testing)
  • acceptEdits - Auto-accept modifications (trusted agents)
  • dontAsk - Auto-deny unpermitted (automation)

5. Common Patterns

PatternRoleToolsModel
ReviewerCode/doc analysisRead-onlySonnet
AnalyzerData/log processingRead+BashHaiku
GeneratorCreate artifactsRead+WriteSonnet
FixerDebug/fix issuesRead+Edit+BashSonnet
ValidatorCheck configsRead+BashHaiku

Anti-Patterns to Avoid

  • Vague descriptions ("Helps with stuff")
  • Too many tools (grant only what's needed)
  • System prompts >5000 chars
  • Overlapping subagents
  • No summary output

Quick Reference

For deeper guidance:

  • references/role-clarity.md - Writing powerful descriptions
  • references/tool-patterns.md - Tool access with examples
  • references/parallel-execution.md - Background/parallel design
  • See Implementation skill for technical frontmatter specs