Chapter 8: Best Practices and Anti-Patterns - Lessons Learned
Learn from others' mistakes; avoid pitfalls others have discovered
Chapter Overview
Through the previous 7 chapters, you've mastered core design patterns for skill packages. This chapter summarizes best practices, points out common pitfalls, and helps you design high-quality, maintainable skill packages.
What You'll Learn
- ✅ 8 design principles for skills
- ✅ 10 common anti-patterns and how to avoid them
- ✅ How to design your own skill ecosystem
- ✅ Future trends in skill collaboration
8.1 Skill Design Principles
Principle 1: Single Responsibility Principle (SRP)
# One skill does one thing
✅ Good:
- verification: Only verifies
- tdd: Only test-driven development
- review: Only reviews
❌ Bad:
- do-everything: verify + test + review + deploy
Test criteria:
Can you describe this skill's purpose in one sentence?
If it contains "and", "also", it has too many responsibilities.Principle 2: Clear Boundary Principle
# Clear inputs and outputs
Every skill must have:
Input:
- Clearly specify what it needs
- Where to get it from
Output:
- Clearly specify what it produces
- How it will be used
Example:
writing-plans:
Input: requirements document
Output: implementation plan (task_plan.md)
verification:
Input: goal file path
Output: pass/fail + missing itemsPrinciple 3: Stateless Principle
# Skills should not maintain state
❌ Bad:
skill remembers:
- how many times called
- previous results
- user preferences
✅ Good:
skill is stateless:
- each invocation is independent
- no memory of previous calls
- pure functional
Advantages:
- Easy to test
- Can execute concurrently
- Predictable resultsPrinciple 4: Testable Principle
# Every skill should be independently testable
Test checklist:
□ Can it be called independently?
□ Are inputs clear?
□ Are outputs verifiable?
□ Can errors be caught?
□ Are boundary conditions handled?
Example test:
def test_verification():
result = verification(
goal_file="goals/test-goal.md",
ai_assessment="Completed all tasks"
)
assert result['status'] in ['pass', 'fail']
assert isinstance(result['missing_items'], list)Principle 5: Error Handling Principle
# Elegant error handling
Must include:
1. Catch exceptions
2. Provide clear error messages
3. Suggest fix solutions
4. Log records
Example:
try:
result = execute_skill()
except SkillExecutionError as e:
logger.error(f"Skill execution failed: {e}")
return {
'status': 'error',
'message': 'Failed to execute skill',
'reason': str(e),
'suggestion': 'Check skill configuration and try again'
}Principle 6: Composable Principle
# Skills should be easy to compose
Design considerations:
- Can output be another skill's input?
- Is a standard interface defined?
- Does it support chain invocation?
Example:
brainstorming output:
- design_doc.md
writing-plans input:
- requirements: design_doc.md
Chain invocation:
brainstorming → writing-plans → executing-plansPrinciple 7: Idempotency Principle
# Multiple executions produce same result
Important! Especially for file operations:
✅ Good:
create_file_if_not_exists(path)
- First time: Create file
- Second time: File exists, don't create
- Result: File exists
❌ Bad:
append_to_file(path, content)
- First time: Append content
- Second time: Append again
- Result: Duplicate content
Solution:
Check state, avoid duplicate operationsPrinciple 8: Observable Principle
# Skill execution process should be visible
Must record:
1. Start time
2. Execution steps
3. Key decisions
4. End time
5. Result status
Example log:
[2024-03-24 14:30:15] Starting verification
[2024-03-24 14:30:16] Reading goal file: test-goal.md
[2024-03-24 14:30:17] Checking tests... PASSED
[2024-03-24 14:30:18] Checking requirements... PASSED
[2024-03-24 14:30:19] Checking docs... FAILED (missing updates)
[2024-03-24 14:30:20] Verification result: FAIL
[2024-03-24 14:30:21] Missing items: [Update README, Update CHANGELOG]8.2 Common Anti-Patterns
Anti-Pattern 1: God Skill
# Problem: One skill does everything
❌ Example:
name: ultimate-development-skill
does:
- planning
- coding
- testing
- deployment
- monitoring
- everything
Problems:
- Too many responsibilities
- Hard to maintain
- Cannot reuse
- Difficult to test
✅ Solution:
Split into multiple skills:
- planning-skill
- coding-skill
- testing-skill
- deployment-skill
- monitoring-skillAnti-Pattern 2: Over-Abstraction
# Problem: Abstraction for abstraction's sake
❌ Example:
BaseSkill → AbstractSkill → GenericSkill → ConcreteSkill
Too many layers, high understanding cost
✅ Solution:
Keep it simple:
Skill (interface) → ConcreteSkill (implementation)
Two layers sufficientAnti-Pattern 3: Hidden Dependencies
# Problem: Implicit dependencies between skills
❌ Example:
skill_a implicitly depends on skill_b's global variable
But not documented
Problems:
- Unpredictable execution order
- Hard to debug
- Cannot parallelize
✅ Solution:
Explicitly declare dependencies:
skill_a:
depends_on: [skill_b]
input: skill_b.outputAnti-Pattern 4: Configuration Hell
# Problem: Too many configuration items
❌ Example:
skill needs 50 parameters configured:
- param1
- param2
- ...
- param50
Users don't know how to configure
✅ Solution:
Provide reasonable defaults:
skill:
required_params: [name] # Must configure
optional_params:
- timeout: 3600 # Has default
- retry: 3 # Has defaultAnti-Pattern 5: Over-Parallelization
# Problem: Unnecessarily parallelizing
❌ Example:
Parallel execute 100 small tasks
Problems:
- Large agent startup overhead
- Excessive resource consumption
- Actually reduces efficiency
✅ Solution:
Evaluate if worth parallelizing:
IF task count < 3:
Sequential execution
ELIF tasks independent AND resources sufficient:
Parallel execution (max 10 agents)
ELSE:
Batch processingAnti-Pattern 6: Magic Numbers
# Problem: Hardcoded numbers in code
❌ Example:
if result.score > 85:
pass
Why 85? Why not 80 or 90?
✅ Solution:
Use named constants:
PASS_THRESHOLD = 85 # Based on industry standard
if result.score > PASS_THRESHOLD:
passAnti-Pattern 7: Poor Error Messaging
# Problem: Unclear error messages
❌ Example:
Error: Operation failed
User doesn't know:
- What operation failed?
- Why did it fail?
- How to fix it?
✅ Solution:
Provide detailed error information:
Error: Verification failed
Reason: 3 tests did not pass
Details:
- test_login: AssertionError at line 45
- test_api: TimeoutError after 30s
- test_db: ConnectionError
Suggestion: Run tests locally to debugAnti-Pattern 8: Premature Optimization
# Problem: Optimizing before needed
❌ Example:
Designing complex caching system for "possible high concurrency"
But actually only 1-2 users
✅ Solution:
Make it work first, then optimize:
1. Make it work (MVP)
2. Measure performance
3. Identify bottlenecks
4. Optimize where needed
"Premature optimization is the root of all evil"
- Donald KnuthAnti-Pattern 9: Ignoring Boundary Conditions
# Problem: Not considering edge cases
❌ Example:
def process_file(path):
content = read_file(path)
return process(content)
What if:
- path doesn't exist?
- file is empty?
- file is too large?
- no permissions?
All will crash
✅ Solution:
Handle all boundary conditions:
def process_file(path):
# Check existence
if not os.path.exists(path):
raise FileNotFoundError(path)
# Check size
size = os.path.getsize(path)
if size > MAX_FILE_SIZE:
raise FileTooLargeError(size)
# Check permission
if not os.access(path, os.R_OK):
raise PermissionError(path)
# Process
content = read_file(path)
return process(content)Anti-Pattern 10: Missing Documentation
# Problem: Skill has no documentation
❌ Example:
Skill code is written, but no explanation:
- How to use
- What are inputs/outputs
- What limitations
Users cannot use it
✅ Solution:
Provide complete documentation:
---
name: skill-name
description: What this skill does
---
# Usage
## Input
- param1: Description
- param2: Description
## Output
- result: Description
## Examples
Example 1:Invoke skill with: param1: value1 param2: value2
## Limitations
- Cannot handle X
- Requires Y8.3 How to Design Your Own Skill Ecosystem
Step 1: Requirements Analysis
# Identify your needs
Ask yourself:
1. What repetitive work do I often do?
2. Which processes can be standardized?
3. Which tools need integration?
4. Which best practices need to be codified?
Examples:
- Code review process → code-review skill
- Deployment process → deployment skill
- Documentation update process → documentation skillStep 2: Architecture Design
# Design skill package architecture
1. Identify skill types:
- Entry Skills
- Process Skills
- Tool Skills
- Guardian Skills
2. Define skill relationships:
- Dependencies
- Invocation relationships
- Mutual exclusion relationships
3. Draw architecture diagram:
┌─────────────────────────┐
│ Entry Skills │
├─────────────────────────┤
│ Process Skills │
├─────────────────────────┤
│ Tool Skills │
├─────────────────────────┤
│ Guardian Skills │
└─────────────────────────┘Step 3: Skill Implementation
# Implement each skill
Follow template:
---
name: skill-name
description: Clear description
TRIGGER when: [conditions]
---
# Skill Name
## Purpose
What this skill does
## Input
What it needs
## Output
What it produces
## Steps
1. Step 1
2. Step 2
3. Step 3
## Error Handling
How errors are handled
## Examples
Usage examplesStep 4: Testing and Validation
# Test your skills
Unit tests:
□ Test individual skill functionality
□ Test boundary conditions
□ Test error handling
Integration tests:
□ Test skill collaboration
□ Test complete workflows
□ Test performance
User testing:
□ Let other developers try
□ Collect feedback
□ Iterate and improveStep 5: Continuous Maintenance
# Maintain your skill package
Regularly:
- Update dependencies
- Fix bugs
- Add new features
- Improve documentation
- Collect user feedback
Version management:
- Use semantic versioning
- Record CHANGELOG
- Maintain backward compatibility8.4 Future Trends in Skill Collaboration
Trend 1: AI-Driven Intelligent Orchestration
Future direction:
AI automatically determines:
- Which skill should be invoked
- Optimal order between skills
- Whether parallel execution is needed
Example:
AI analyzes user requirements → Automatically generates skill invocation flowTrend 2: Cross-Platform Skill Sharing
Future direction:
Skill marketplace:
- Publish your skills
- Discover others' skills
- Rate and recommend
Standardized interfaces:
- Unified skill format
- Cross-platform compatibility
- Plug and playTrend 3: Adaptive Learning
Future direction:
Skill self-learning:
- Record execution history
- Analyze success rate
- Automatically optimize parameters
Personalization:
- Adapt to user habits
- Optimize execution strategies
- Provide personalized suggestionsTrend 4: Visual Orchestration
Future direction:
Graphical interface:
- Drag-and-drop skill composition
- Process visualization
- Real-time monitoring
Debugging tools:
- Breakpoint debugging
- Step-by-step execution
- Variable inspectionChapter Summary
This chapter summarized:
8 Design Principles: Single responsibility, clear boundaries, stateless, testable, error handling, composable, idempotency, observable
10 Common Anti-Patterns: God skill, over-abstraction, hidden dependencies, configuration hell, over-parallelization, magic numbers, poor error messages, premature optimization, boundary conditions, missing documentation
Design Process: Requirements analysis → Architecture design → Skill implementation → Testing validation → Continuous maintenance
Future Trends: AI orchestration, cross-platform sharing, adaptive learning, visual orchestration
Course Summary
Congratulations on completing the "Skill Design Patterns: From Theory to Practice" course!
You now master:
- ✅ Core design principles of skill packages
- ✅ Application of 8 classic design patterns
- ✅ Best practices and anti-pattern recognition
- ✅ Ability to design your own skill ecosystem
Next Steps:
- Choose a real project
- Apply learned patterns
- Design your first skill package
- Continuously iterate and improve
Remember:
- Practice makes perfect
- Time is the only test of truth
- Use AI, but don't blindly follow
- Dialectical unity, neither deify nor demonize
Extended Reading
- Design Patterns: Elements of Reusable Object-Oriented Software
- Clean Code: A Handbook of Agile Software Craftsmanship
- The Pragmatic Programmer
Final Exercises
Practice Project: Choose a workflow you often do, design a skill package to automate it.
Skill Review: Review an existing skill package, identify design patterns and anti-patterns in it.
Ecosystem: Design a skill package ecosystem architecture diagram for your team.
Thank you for learning! Now go create your own skill packages! 🚀