Agents Writing Agents
The core pattern — describe agent behavior in plain language and let Claude write the agent definition. Compose knowledge through project memory.
TUTOR WITH THEFOCUS.AI
Copy this prompt into Claude, ChatGPT, or any external AI assistant. It points the assistant to the course instructions and links it to your student profile to track your progress and customize observations.
You are not enrolled yet. Enroll to generate a Student ID to track lesson completions and store learning notes.
Agents Writing Agents
The Core Pattern
The most powerful pattern in this course: you describe what you want at the “what” level, and AI writes the “how.” This applies to agent definitions just as much as it applies to code.
Instead of carefully crafting agent system prompts, enumerating tools, and tuning model selection, you describe the agent’s behavior in plain language and let Claude generate everything.
Creating the Research Agent
Open the agents panel in Claude Code:
> /agents
Select New Agent → Project Agent → Generate with Claude.
Then describe what you want in plain language:
a research agent that searches the internet based upon the current technologies and choices that have been made in the project to find the best techniques or libraries of doing something, and finds the best choice based upon simplicity, popularity, good support. It should output its findings in reports/yyyy-mm-dd-topic.md and it should have front matter saying when it’s appropriate or not to use. It should explain how to use the library or software, the theory behind it and its basic usage philosophy. The first part of the report will give a short explanation of what you’ve found, then it should go into detail on how to use it (including setup and code examples), and finally it should have a caveats section at the bottom saying when it’s not right. It should include a bibliography of sources it used that can be followed for more information, and the report should be annotated where it got information.
Claude processes this description and generates the complete agent definition — system prompt, tool selection, model choice, output format. You don’t need to know the exact syntax for agent definitions or which tools to grant.
Composing Knowledge Through Project Memory
After creating the agent, teach Claude to consult research reports:
> # Consult the front matter in reports/ before a large build to see if we have useful information
Save this to project memory. Now every session starts with knowledge of where to find research. It’s a lightweight form of Retrieval-Augmented Generation (RAG) — you’re building a knowledge base that agents automatically reference.
Creating the Classification Agent
Later in the project, you’ll use this same pattern to create a specialized classification agent:
> /agents
New Agent → Project Agent → Generate with Claude
This email classifying agent will take an email from @content/uncategorized and examine it and add the taxonomy described in the context-taxonomy-schema in the reports/ directory. It will create a new file in content/decorated with the same name, rewritten front matter, and exact same body text.
Notice the difference from the research agent description. This one:
- References a specific source directory (
@content/uncategorized) - References a specific schema document (
reports/) - Specifies exact behavior (same body text, rewritten frontmatter)
- Defines clear input/output contracts
This is a specialized agent, not a general-purpose one. It’s designed to do one thing well: read markdown, apply taxonomy, write decorated output.
Model Selection Strategy
| Agent Type | Model | Why |
|---|---|---|
| Research Agent | Opus (smartest) | Needs deep reasoning, source evaluation, writing quality |
| Classification Agent | Haiku (fastest) | Repetitive task, needs speed and cost efficiency |
Model selection is part of the description: when generating the research agent, you choose Opus because it generates high-quality, nuanced reports. For classification, you choose Haiku because classifying 200+ files needs speed, and the classification logic is straightforward.
Why This Pattern Matters
You Don’t Need to Be a Prompt Engineer
Writing effective system prompts is a skill that takes practice. With this pattern, you describe behavior at the level you think about it: “this agent researches technologies and writes reports.” The AI handles the prompt engineering.
Separation of Concerns
Each agent has a clear, single responsibility:
| Agent | Responsibility |
|---|---|
tech-research-advisor | Research technologies, write reports |
email-taxonomy-classifier | Classify single file, add frontmatter |
When agents have narrow responsibilities, they’re more reliable. The classification agent doesn’t need to know about EML parsing. The research agent doesn’t need to know about YAML frontmatter.
Iterative Refinement
You can improve agents through conversation. After the classifier runs, you notice it does redundant validation:
It was doing a lot of rework doing the manual checking. Can you extract that validation code so that the @email-taxonomy-classifier can run it after?
Claude extracts validation into a standalone script (validate_taxonomy.py) and updates the agent to use it. The agent definition evolves based on real usage.
Parallel Composition
Once you have a classification agent, you can spawn 50 instances to process 50 files simultaneously:
classify the next 50 emails
This works because the agent is stateless and idempotent — each instance reads one input file, produces one output file, and doesn’t depend on any other instance. The agent’s narrow scope makes parallelism trivial.
The Pattern in Summary
1. Describe what you want (plain language)
↓
2. Claude generates the agent definition
↓
3. You select the model (smart for research, fast for classification)
↓
4. The agent does its one job reliably
↓
5. You refine through conversation
This is compounding: each agent you create makes the next one easier to create, because they share the same project context, the same research reports, and the same output conventions.
Next: Phase 2: Extraction — Use the research agent to decide how to extract emails, then build the converter.