PTENES
MODULE 2.3 · Track 2 · Building in practice

🧠 The body is the brain

The frontmatter configures the agent, but the the .md body is what decides how it thinks, how it acts, and what it delivers. A well-written body turns a generic tool into a reliable specialist.

7
Topics
~35
Minutes
Medium
Level
Practice
Type

Every well-built subagent climbs the same ladder: it starts with a clear role, moves through the numbered steps and reaches a output format that any orchestrator can read. What separates a weak agent from a reliable specialist is this progression.

ROLE you are a senior… CONTEXT when invoked… STEPS 1. analyze · 2. check… OUTPUT + DO NOT structured format Subagent body ladder — each rung amplifies the next
1

🎭 Role: "you are a senior…"

The first line of the body defines the identity from the agent. This isn't vanity — it's a signal of expertise. The model calibrates vocabulary, depth, and tone based on this statement. A well-written role sentence is worth more than ten paragraphs of vague instructions.

Anatomy of an effective role

A complete role has three parts: level (senior / staff / principal), domain (security engineer / code reviewer / technical writer) and operational context (working in a production codebase / reviewing PRs / writing for developers).

Level
senior · staff · principal · lead
Domain
security engineer · reviewer · writer
Context
in production · reviewing PRs · writing docs

✓ Effective role

  • ✓ "You are a senior security engineer reviewing production Python code for OWASP vulnerabilities."
  • ✓ "You are a staff technical writer creating developer documentation for a REST API."
  • ✓ Includes the specific domain + usage context

✗ Weak role

  • ✗ "You are a helpful assistant." — too generic, no domain cues
  • ✗ "You are an expert." — without specifying what in
  • ✗ Omit the role entirely

Tip: test your role by asking "what vocabulary would a [your role] use?" — if the answer changes between "helpful assistant" and "senior security engineer", the role is doing real work.

2

🔢 Numbered steps: "when invoked: 1…"

After the role come the execution steps — the exact sequence the agent should follow every time it’s invoked. Numbered steps turn emergent (unpredictable) behavior into reproducible.

1
Read the entire input before acting
A nearly universal first step. Keeps the agent from responding to the first sentence and ignoring the context that follows.
2
Classify / identify the item type
A typical second step in reviewers and classifiers. Defines the processing route before execution.
3
Run the main analysis
The actual domain work. Be specific: "check for SQL injection, XSS, insecure deserialization" is better than "look for bugs."
4
Format and deliver the output
Final step: applies the defined output format. Keeps things consistent even if the orchestrator changes.

Why number them?

The model tends to follow numbered lists more faithfully than paragraphs of instructions. Numbering creates a explicit execution contract — skipping a step becomes visible to whoever reviews the output.

3

📄 Output format

The orchestrator will read what the subagent returns. If the format varies, the orchestrator needs extra logic to parse it. A declared output format in the agent's body eliminates this variation and makes integration trivial.

Section ## Output Format in the body

Explicitly state the format in a separate section from the body. Use Markdown for structure and code fences to show the exact expected schema.

## Output Format
Respond with a Markdown document containing:
- **Summary**: 1–2 sentences
- **Findings**: numbered list, each with severity (HIGH/MED/LOW)
- **Recommendation**: one actionable fix per finding
Do not include any other sections.

✓ Structured format

  • ✓ Dedicated section ## Output Format
  • ✓ Named fields with types (string, number, list)
  • ✓ JSON schema when the orchestrator will parse it automatically

✗ Free-form format

  • ✗ No format declaration — output varies with each invocation
  • ✗ "Respond in prose" for automated integrations
  • ✗ Optional fields with no declared default value

Tip: when the subagent will return data for another agent to process, prefer JSON over Markdown — it’s easier to parse programmatically. Use Markdown when the output is for people to read directly.

4

🚫 What NOT to do

Declaring explicit constraints is just as important as stating what to do. The model knows more than you want it to use—the section on not doing sets the scope and prevents the agent from "overhelping" outside its role.

Section ## Constraints

Use a section ## Constraints or ## Do not to list prohibited behaviors. Each restriction should be actionable — not vague.

## Constraints
- Do not fix code — only report findings
- Do not comment on style — focus on security only
- Do not escalate to the user — return results to orchestrator
- Do not hallucinate CVE numbers — say "unverified" if unsure

⚠️ Empty restrictions don't work

"Do not do anything harmful" is not an actionable constraint—the model already has guardrails for that. Useful constraints are specific to the agent’s domain: "do not suggest architectural changes" (for a code reviewer), "do not translate content" (for a qa-checker).

🎯
Specific
Avoid "don't do bad things"
🔒
Scope limit
Defines where the agent stops
📡
Escalation
Specify whether it should escalate
🔕
Silence
When nothing is returned
5

⚡ One agent, one task

The biggest mistake in an agent’s body isn’t what’s there — it’s what’s more. Agents that do multiple things don’t do any of them well. The test is simple: if you can put a "and also" in the agent's role, it needs to be split up.

The "and also" test

✗ Do-it-all agent
You are a senior engineer.
Review the code for bugs,
and also suggest improvements,
and also update the docs,
and also check security.
✓ Specialized agents
bug-finder: review for correctness
security-reviewer: OWASP checks
doc-writer: update docs
refactor-advisor: suggest improvements

Practical tip: when an agent takes too long, produces large, hard-to-parse outputs, or gets "confused" between operating modes — it’s a sign it’s trying to do too much. Split at the "and also" point.

🔬
Specialization
One role → one responsibility
🧩
Composition
Orchestrator combines specialists
🔄
Testability
Single agent = single point of failure
6

🔧 The body invokes skills

A subagent can use skills registered in the system — it invokes them by name, with a command in the body. This allows the agent to delegate parts of the work to specialized skills without having to reimplement behaviors that already exist.

How to declare in the body

## When invoked
1. Read the target file(s) fully.
2. Use the `impeccable` skill to check prose quality.
3. Apply findings to the output.
4. Return a diff-style summary.

The skill’s usage instructions go in the numbered steps—not in the role. The role defines who the agent is; the steps define what it uses.

✓ Correct delegation

  • ✓ Skill invoked at a specific, numbered step
  • ✓ Skill result integrated into the final output
  • ✓ Skill does one thing; agent orchestrates the workflow

✗ Common problems

  • ✗ Invoke a skill without using the result (token waste)
  • ✗ Call a skill that does exactly what the agent already does
  • ✗ Invoke multiple skills without an ordering criterion
🎓
Skill
Reusable behavior
📋
Invocation
By name, in the steps
🔗
Composition
Agent + skills = system
♻️
Reuse
Skill serves N agents
7

🔁 Iterate with feedback

An agent’s body doesn’t come ready-made. The first version works 70% of the time — the other 30% reveals what’s missing or wrong. Iterate with real feedback is what separates an agent that "works sometimes" from one that is "reliable in production."

1
Initial draft
Role + basic steps + format. It doesn’t need to be perfect—it needs to be testable.
2
Run with 3-5 real inputs
Choose representative cases from real usage — not easy inputs. The agent needs to perform well on difficult cases.
3
Identify the failure pattern
Where does the output diverge from what you expected? Wrong format, scope creep, skipped step? Each failure maps to a correction in the body.
4
Fix it in the body, retest
One fix at a time. If you change three things at once, you won’t know which one fixed it. Simple versioning: v1, v2, v3.

Practical rule: if you had to explain it to the orchestrator "the agent returned X, but you should ignore part Y", that’s a sign the fix should be in the agent’s body, not in the orchestrator’s logic.

📎

Real example: security-reviewer.md

Below is a complete security review subagent body. Each section demonstrates one of this module’s concepts applied together.

~/.claude/agents/security-reviewer.md
--- name: security-reviewer description: Reviews code for security vulnerabilities. Invoke when a file or diff needs OWASP/CVE analysis before merge. model: claude-sonnet-4-5 tools: - Read - Bash --- You are a senior security engineer specializing in application security for Python and TypeScript production codebases. Your sole responsibility is identifying security vulnerabilities — not fixing code, not commenting on style. ## When invoked 1. Read every file or diff provided in full before making any assessment. 2. Identify the language and framework in use (Django, FastAPI, Next.js, etc.). 3. Check systematically for the following vulnerability classes: - Injection (SQL, command, LDAP) - Authentication and session management flaws - Sensitive data exposure (secrets in code, logging PII) - Insecure deserialization - Known vulnerable dependency versions (check package.json / requirements.txt) 4. For each finding, assign a severity: HIGH / MEDIUM / LOW. 5. Format and return your report as specified below. ## Output Format Return a Markdown document with exactly these sections: **Summary**: 1-2 sentences on overall security posture. **Findings**: numbered list. Each entry: - Severity: HIGH / MEDIUM / LOW - Location: filename:line - Description: what the vulnerability is - Evidence: the relevant code snippet (max 3 lines) **Verdict**: PASS (no HIGH/MEDIUM), REVIEW (has MEDIUM), or BLOCK (has HIGH) ## Constraints - Do not suggest code fixes — report only - Do not comment on code quality, style, or architecture - Do not escalate directly to the user — return results to orchestrator - If a CVE number is uncertain, write "potential CVE — unverified" instead of a CVE ID - Do not analyze files outside the provided scope

Why this body works

  • → Specific role: seniority + domain + scope (Python/TS, production)
  • → Checklist steps: 5 steps that cover the entire workflow without ambiguity
  • → Declared format: 3 named sections with an exact structure
  • → Actionable restrictions: 5 security-domain-specific prohibitions

Detailed content

PROMPT 1 Turn the checklist into an agent’s body
Read this PR review checklist: [paste the checklist here] Turn it into a complete subagent body for a .md file: - Role (senior + domain extracted from the checklist) - Numbered steps (mapped from the checklist items) - Output format (structured, parseable) - Constraints (what the agent must NOT do beyond the checklist)

Use when you already have a documented process and want to turn it into an agent.

PROMPT 2 Audit existing content
Read this subagent’s body: [paste the .md here] Evaluate: 1. Is the role specific enough? (level + domain + operational context) 2. Do the steps cover the full workflow without gaps? 3. Is the output format specified and parseable? 4. Are the constraints domain-specific or too generic? Return a list of improvements with concrete examples.

Use it to review agents that “almost work” and identify what’s missing.

PROMPT 3 Split up the do-everything agent
This agent does many things: [paste the agent body here] Apply the "and also" test: 1. List each separate responsibility the agent has 2. Propose splitting it into N specialized agents (name + role for each) 3. For the most important agent, write the full body Criterion: each agent must have exactly one responsibility.

Use when an agent does everything but does nothing well.

🖥️

Simulated screen: invoking the security-reviewer

The orchestrator invoked the security-reviewer in an authentication file. See how the structured body produces consistent, parseable output.

claude — subagent: security-reviewer illustrative recreation
# Invoking security-reviewer in auth/login.py
→ Reading full file (312 lines)...
→ Framework detected: FastAPI + SQLAlchemy
→ Checking vulnerability classes...
## Summary
Two HIGH-severity findings in auth/login.py. SQL injection via raw query and hardcoded secret key. Immediate action required before merge.
## Findings
1. Severity: HIGH
Location: auth/login.py:87
Description: Raw SQL string interpolation — SQL injection
query = f"SELECT * FROM users WHERE email = '{email}'"
2. Severity: MEDIUM
Location: auth/login.py:12
Description: Hardcoded SECRET_KEY in source file
SECRET_KEY = "dev-secret-do-not-use"
## Verdict
BLOCK — 1 HIGH finding requires resolution before merge.
🏋️

Exercise: split up a do-it-all agent

Apply what you learned in this module.

The problematic agent

You are a helpful senior engineer. When invoked: 1. Review the code for bugs AND style issues AND security problems. 2. Suggest architectural improvements if you see any. 3. Update the changelog. 4. If there are tests missing, write them. 5. Check documentation is up to date. 6. Respond in a friendly, conversational tone with all your thoughts.

Your task

  1. 1 List all separate responsibilities of this agent (apply the “and also” test)
  2. 2 Suggest 3 specialized agents (name + one-line role for each)
  3. 3 Write the full body of one of the agents: role + numbered steps + output format + constraints

Completion criterion

  • ✓ You identified ≥4 separate responsibilities in the original agent
  • ✓ Each proposed agent passes the “and also” test — zero overlap in responsibilities
  • ✓ The body you wrote has a specific role (level + domain + context)
  • ✓ The numbered steps cover the complete workflow without “and also”
  • ✓ The output format is declared and could be parsed by another agent
  • ✓ The constraints are domain-specific — not generic

📌 What you learned

✓ Role: level + domain + operational context — not "helpful assistant"
✓ Numbered steps: turn emergent behavior into something reproducible
✓ Output format: explicitly declared, parseable by the orchestrator
✓ Constraints: domain-specific, actionable, not generic
✓ Testing “and also”: one agent, one responsibility
✓ Skills: invoked in the steps, not on paper
✓ Iteration: draft → 3-5 real inputs → failure pattern → fix
Next module
2.4 → Tools and permissions
The body defines what the agent does — but the tools define what it can do. In the next module, you'll learn to declare and restrict tool access with surgical precision.
← 2.2 The description is the trigger 2.4 Tools and permissions →