|
| 1 | +--- |
| 2 | +name: create-agent |
| 3 | +description: Create new OpenCode agents with research-backed design patterns and industry standards |
| 4 | +version: "1.0" |
| 5 | +author: human-user |
| 6 | +audience: human-user |
| 7 | +workflow: opencode |
| 8 | +--- |
| 9 | + |
| 10 | +# Create Agent |
| 11 | + |
| 12 | +Create a new OpenCode agent following research-backed best practices from OpenAI, Anthropic, and scientific literature. |
| 13 | + |
| 14 | +## When to Use |
| 15 | + |
| 16 | +When you need a new agent with distinct ownership, instructions, tool surface, or approval policy. Not for simple routing — only when the task requires a separate domain of responsibility. |
| 17 | + |
| 18 | +## How to Create an Agent |
| 19 | + |
| 20 | +### 0. Research (mandatory — do this first) |
| 21 | + |
| 22 | +Before writing any agent, research the domain to ground the agent design in industry standards and scientifically-backed evidence: |
| 23 | + |
| 24 | +1. **Identify the agent's domain**: What role, responsibility, and domain will this agent own? |
| 25 | +2. **Search for domain-specific best practices**: |
| 26 | + - For agent architecture: OpenAI Agents SDK, Anthropic Claude Agent SDK, Google Agents SDK |
| 27 | + - For domain methodology: Academic papers, vendor guides, established standards (e.g., OWASP for security, IEEE for software engineering) |
| 28 | + - For known failure modes: Post-mortems, case studies, industry reports |
| 29 | +3. **Synthesize conclusions**: What ownership boundaries work? What tool design patterns? What escalation rules? |
| 30 | +4. **Embed as design decisions**: Write the agent's ownership definition, instruction patterns, tool surface, and escalation rules based on those conclusions — not as citations but as direct guidance |
| 31 | + |
| 32 | +**Example research synthesis:** |
| 33 | +``` |
| 34 | +Agent domain: Security reviewer agent |
| 35 | +Research: OWASP Testing Guide, NIST security controls, Anthropic's adversarial verification patterns |
| 36 | +Conclusion: Security agents should assume breach by default, escalate on any critical finding, use defense-in-depth checklist. |
| 37 | +→ Agent design: "role: reviewer", "escalation: any critical = human", "tool: security-scan + vuln-check" |
| 38 | +``` |
| 39 | + |
| 40 | +### 1. Create the agent file |
| 41 | + |
| 42 | +```bash |
| 43 | +mkdir -p .opencode/agents/ |
| 44 | +``` |
| 45 | + |
| 46 | +Create `.opencode/agents/<agent-name>.md`: |
| 47 | + |
| 48 | +```markdown |
| 49 | +--- |
| 50 | +name: <agent-name> |
| 51 | +description: <1-sentence description of what this agent does> |
| 52 | +role: <product-owner | software-engineer | reviewer | setup-project | human-user> |
| 53 | +steps: <step numbers this agent owns, e.g., "2, 3"> |
| 54 | +--- |
| 55 | + |
| 56 | +# <Agent Name> |
| 57 | + |
| 58 | +[Brief description of the agent's purpose and when it's invoked.] |
| 59 | + |
| 60 | +## Role |
| 61 | + |
| 62 | +<What this agent does in the workflow.> |
| 63 | + |
| 64 | +## Available Skills |
| 65 | + |
| 66 | +| Skill | When to Load | Purpose | |
| 67 | +|---|---|---| |
| 68 | +| `session-workflow` | Every session | Session start/end protocol | |
| 69 | +| `<skill-name>` | When needed | <What the skill provides> | |
| 70 | + |
| 71 | +## Instructions |
| 72 | + |
| 73 | +<Detailed instructions for this agent. Include:> |
| 74 | + |
| 75 | +- When to invoke this agent (trigger conditions) |
| 76 | +- What steps it owns |
| 77 | +- How to use tools |
| 78 | +- When to escalate or hand off |
| 79 | +``` |
| 80 | + |
| 81 | +### 2. Follow the structural rules |
| 82 | + |
| 83 | +Apply the research conclusions about file organization: |
| 84 | + |
| 85 | +| File | When Loaded | Content | Avoid | |
| 86 | +|---|---|---|---| |
| 87 | +| `AGENTS.md` | Always | Shared conventions, commands | Workflow details | |
| 88 | +| `.opencode/agents/*.md` | When role invoked | Role identity, step ownership, skill loads, tool permissions | Duplication | |
| 89 | +| `.opencode/skills/*.md` | On demand | Full procedural instructions | Duplication | |
| 90 | + |
| 91 | +**Why**: Keeping always-loaded files lean preserves attention budget for the task at hand. |
| 92 | + |
| 93 | +### 3. Define clear ownership boundaries |
| 94 | + |
| 95 | +**Split criteria**: |
| 96 | +- Separate ownership (different domain responsibility) |
| 97 | +- Different instructions (not just more detail) |
| 98 | +- Different tool surface (distinct actions) |
| 99 | +- Different approval policy (escalation rules) |
| 100 | + |
| 101 | +**Anti-pattern**: Creating agents just to organize instructions. A single agent with more tools is usually better than multiple agents. |
| 102 | + |
| 103 | +### 4. Write effective instructions |
| 104 | + |
| 105 | +Write instructions that work in practice: |
| 106 | + |
| 107 | +- **Specific triggers**: "Load this skill when X" not "use judgment" |
| 108 | +- **Clear actions**: Every step corresponds to a specific output |
| 109 | +- **Concrete examples**: Include before/after code where helpful |
| 110 | +- **Verification criteria**: How does the agent know it's done? |
| 111 | + |
| 112 | +### 5. Define tool permissions |
| 113 | + |
| 114 | +Design the tool surface based on what the agent needs to accomplish: |
| 115 | + |
| 116 | +- **Start with bash** for breadth |
| 117 | +- **Promote to dedicated tools** when you need to: |
| 118 | + - Gate security-sensitive actions |
| 119 | + - Render structured output |
| 120 | + - Audit usage patterns |
| 121 | + - Serialize vs. parallelize |
| 122 | + |
| 123 | +### 6. Add to AGENTS.md |
| 124 | + |
| 125 | +Register the agent in the workflow section of `AGENTS.md`: |
| 126 | + |
| 127 | +```markdown |
| 128 | +## Agents |
| 129 | + |
| 130 | +| Agent | Role | Steps | Skills | |
| 131 | +|-------|------|-------|--------| |
| 132 | +| <name> | <role> | <steps> | <skills> | |
| 133 | +``` |
| 134 | + |
| 135 | +## Agent Template |
| 136 | + |
| 137 | +```markdown |
| 138 | +--- |
| 139 | +name: <agent-name> |
| 140 | +description: <what this agent does, 1 sentence> |
| 141 | +role: <product-owner | software-engineer | reviewer | setup-project | human-user> |
| 142 | +steps: <owned steps, e.g., "2-3"> |
| 143 | +--- |
| 144 | + |
| 145 | +# <Agent Title> |
| 146 | + |
| 147 | +<2-3 paragraphs: what this agent does, when invoked, what it delivers.> |
| 148 | + |
| 149 | +## Context |
| 150 | + |
| 151 | +<What this agent knows/has access to> |
| 152 | + |
| 153 | +## Available Skills |
| 154 | + |
| 155 | +- `session-workflow` — always |
| 156 | +- `<skill>` — when <trigger> |
| 157 | + |
| 158 | +## Instructions |
| 159 | + |
| 160 | +### Step <N>: <Step Name> |
| 161 | + |
| 162 | +1. <Specific action> |
| 163 | +2. <Specific action> |
| 164 | +3. <Verification> |
| 165 | + |
| 166 | +### Hand-off |
| 167 | + |
| 168 | +When to transfer to <other agent>: <condition> |
| 169 | + |
| 170 | +## Tool Permissions |
| 171 | + |
| 172 | +- Read files: <scope> |
| 173 | +- Write files: <scope> |
| 174 | +- Execute commands: <scope> |
| 175 | +- Network access: <yes/no> |
| 176 | + |
| 177 | +## Escalation |
| 178 | + |
| 179 | +When to escalate to human: <conditions> |
| 180 | +``` |
| 181 | + |
| 182 | +## Existing Agents in This Project |
| 183 | + |
| 184 | +| Agent | Role | Steps | Purpose | |
| 185 | +|---|---|---|---| |
| 186 | +| `product-owner` | product-owner | 1, 5 | Scope discovery, acceptance | |
| 187 | +| `software-engineer` | software-engineer | 2, 3, 5 | Architecture, TDD, releases | |
| 188 | +| `reviewer` | reviewer | 4 | Adversarial verification | |
| 189 | +| `setup-project` | setup-project | meta | Initialize new projects | |
| 190 | + |
| 191 | +## Best Practices Summary |
| 192 | + |
| 193 | +1. **Start with a single agent** — add more only when ownership boundaries are clear |
| 194 | +2. **Define ownership, not volume** — separate domains, not instruction sets |
| 195 | +3. **Keep instructions specific** — concrete triggers, not vague guidance |
| 196 | +4. **Match tools to security needs** — bash for flexibility, dedicated tools for gating |
| 197 | +5. **Test with real usage** — iterate based on failures |
| 198 | +6. **Reference, don't duplicate** — link to skills and AGENTS.md, don't copy content |
0 commit comments