Agent Templates
Templates for generating project-specific agents that understand your stack, conventions, and patterns.
What are Agent Templates?#
Agent templates are parameterized agent definitions that get customized for your specific project. Instead of using generic agents, templates generate project-specific agents that:
- Understand your exact framework and libraries (e.g., Chi vs Gin, React vs Vue)
- Follow your project's conventions from
docs/CONVENTIONS.md - Know your directory structure and file organization
- Use your database, testing, and deployment patterns
How Templates Work#
Template Structure
Templates live in ~/.config/opencode/agent-templates/ organized by category. Each template has frontmatter metadata and a parameterized agent definition.
Template Frontmatter
---
template: backend/go-chi
description: Go Chi router web service patterns
applies_to:
frameworks: [go-chi, chi]
language: go
generates: backend-dev.md
---The frontmatter declares when the template applies and what agent file it generates.
Template Variables
Templates use Handlebars-style placeholders that get filled in during generation:
| Variable | Source |
|---|---|
{{AGENT_NAME}} | Agent file name (e.g., "Backend Dev") |
{{PROJECT_NAME}} | From project.json |
{{PROJECT.commands.test}} | Project-specific test command |
{{CONVENTIONS.errorHandling}} | From CONVENTIONS.md |
{{#if PROJECT.database.type == 'postgres'}} | Conditional sections based on project config |
Template → Agent Transformation#
When a project is bootstrapped, templates matching the project's stack are rendered into project-specific agents stored in docs/agents/.
Template (generic)
# {{AGENT_NAME}}: Go Chi Agent
You are an agent for **{{PROJECT_NAME}}**.
## Commands
- Test: `{{PROJECT.commands.test || 'go test ./...'}}`
- Lint: `{{PROJECT.commands.lint || 'golangci-lint run'}}`
{{#if CONVENTIONS.errorHandling}}
## Error Handling
Follow patterns from CONVENTIONS.md.
{{else}}
## Error Handling
Use standard Go error wrapping.
{{/if}}Generated Agent (specific)
# Backend Dev: Go Chi Agent
You are an agent for **MyApp**.
## Commands
- Test: `make test`
- Lint: `make lint`
## Error Handling
Follow patterns from CONVENTIONS.md.The generated agent knows your project name, uses your Makefile commands, and references your conventions - no generic guessing.
When to Use Templates#
Use Templates When:
- • Starting a new project with known stack
- • Your framework has specific patterns
- • You have strong conventions to enforce
- • Multiple projects share similar stacks
Use Generic Agents When:
- • Exploring or prototyping quickly
- • Working with unusual/custom stacks
- • Project is small or single-use
- • No strong conventions needed
Available Templates (14)#
Templates are organized by category in ~/.config/opencode/agent-templates/:
Backend
Server-side implementation agents for various frameworks
Go Chi
backend/go-chi.mdNode Express
backend/node-express.mdPython Fastapi
backend/python-fastapi.mdFrontend
UI implementation agents for component libraries
React
frontend/react.mdSvelte
frontend/svelte.mdVue
frontend/vue.mdTesting
Test implementation agents for different frameworks
Go Test
testing/go-test.mdJest React
testing/jest-react.mdPlaywright
testing/playwright.mdPytest
testing/pytest.mdCritics
Code review agents for specific languages
Go
critics/go.mdPython
critics/python.mdTypescript
critics/typescript.mdStyling
UI styling agents for CSS frameworks
Tailwind
styling/tailwind.mdCreating Custom Templates#
You can create custom templates for your organization's specific patterns:
- 1Create the template file
Add a new
.mdfile in the appropriate category folder underagent-templates/ - 2Add frontmatter
Define
template,applies_to, andgeneratesfields - 3Write the agent instructions
Use template variables to reference project-specific values
- 4Bootstrap a project to test
Run
opencode bootstrapand verify the generated agent