Lesson 10Sub-agents
Creating Custom Agents
Define your own agents
Agent File Format
An agent is defined in a Markdown file with YAML frontmatter:
--- model: haiku tools: - Read - Grep - Glob --- # Security Auditor You are a security-focused code reviewer. Your job is to find potential security vulnerabilities in the codebase. ## Focus Areas - SQL injection - XSS vulnerabilities - Authentication issues - Sensitive data exposure - Input validation ## Output Format For each issue found, provide: 1. File and line number 2. Vulnerability type 3. Risk level (High/Medium/Low) 4. Suggested fix
Frontmatter structure:
model— model (haiku/sonnet/opus)tools— list of available tools
Document body:
- • Instructions for the agent
- • Task description
- • Output format
Model Selection
| Model | Speed | Cost | Use Case |
|---|---|---|---|
haiku | Very fast | Low | Simple tasks |
sonnet | Fast | Medium | Most tasks |
opus | Slow | High | Complex tasks |
💡 Use haiku for quick search tasks, sonnet for most tasks, opus for complex analysis
Tool Restriction
Specify only the tools the agent needs:
File
ReadEditWriteGlobGrep
Execution
BashTask
Web
WebFetchWebSearch
Interactive
AskUserQuestion
⚠️ Agent without Edit and Write cannot modify files — useful for read-only auditors
Agent Scopes
session
In current session memoryAgent exists only during the sessionproject
.claude/agents/Available to everyone in this projectuser
~/.claude/agents/Available in all your projectsExample Agents
documentation-writer
Generates code documentation
sonnet3 tools
test-generator
Creates unit tests
haiku3 tools
dependency-auditor
Checks dependencies for vulnerabilities
haiku3 tools
migration-planner
Plans database migrations
opus3 tools
Best Practices for Creating Agents
- 1.Give the agent a clear role and limited set of tools
- 2.Use haiku for quick tasks, sonnet for complex ones
- 3.Describe output format for predictable results
- 4.Store common agents in ~/.claude/agents/ for reuse
This lesson is part of a structured LLM course.
My Learning Path