Defining Roles
Roles define who an agent is. Every agent session is composed from a role definition that sets personality, constraints, and communication style. A role lives in .agents/roles/<name>/ with two files: role.json and ROLE.md.
The role.json schema
{ "name": "engineer", "description": "Software engineer — implements features, writes tests, fixes bugs", "capabilities": ["code-generation", "file-editing", "testing", "refactoring"], "prompt_file": "ROLE.md", "quality_gates": ["unit-tests", "lint-clean", "no-hardcoded-secrets"], "skill_refs": [], "cli": "agent", "model": "claude-sonnet-4-20250514", "timeout": 600}| Field | Required | Description |
|---|---|---|
name | yes | Unique identifier, matches directory name |
description | yes | One-line summary shown in role listings |
capabilities | yes | Tags for skill matching and task routing |
prompt_file | yes | System prompt markdown, relative to role dir |
quality_gates | no | Checks QA applies when reviewing output |
skill_refs | no | Skills auto-loaded for every session |
cli | no | CLI tool to spawn the agent (agent, opencode) |
model | no | Default LLM model, overridden by plan config |
timeout | no | Max seconds per session (default: 600) |
Creating a role
-
Create the directory.
mkdir -p .agents/roles/security-auditor -
Write
role.jsonwith name, capabilities, and quality gates. -
Write
ROLE.md— this becomes the agent’s system prompt. -
Test the role by referencing it in a plan epic.
Writing effective ROLE.md files
---name: security-auditordescription: You are a Security Auditor...tags: [security, audit, review]trust_level: core---# Your ResponsibilitiesPrimary job description.## WorkflowStep-by-step process.## CommunicationHow to use channel tools.## Quality StandardsNon-negotiable rules.- Be specific: “Read the
fixmessage, address every point” - Include example tool calls with realistic parameters
- Define what “done” means for this role
- Reference MCP tools by name:
post_message,report_progress - Set constraints: “Never modify files outside working_dir”
- Use vague instructions like “be helpful”
- Assume context — spell out message formats
- Mix responsibilities — QA should not write implementation code
- Skip the frontmatter — it is used for role resolution
Capability tags
Capabilities control skill matching and task routing:
| Capability | Typical roles |
|---|---|
code-generation | engineer, architect |
code-review | qa, security-auditor |
testing | engineer, qa |
architecture | architect |
documentation | technical-writer |
Quality gates
Quality gates tell QA what to check when reviewing this role’s output:
"quality_gates": ["unit-tests", "lint-clean", "no-hardcoded-secrets", "api-docs-updated"]Forking an existing role
-
Copy the role directory.
cp -r .agents/roles/engineer .agents/roles/backend-engineer -
Update
role.json. Changename,description, and adjust capabilities. -
Customize
ROLE.md. Remove irrelevant instructions, add domain-specific workflows. -
Reference in your plan.
## Epic 2: API Layer### Roles- backend-engineer
Built-in roles
| Role | Purpose |
|---|---|
engineer | General-purpose implementation |
architect | System design and technical decisions |
qa | Testing and quality validation |
manager | Orchestration, triage, coordination |
reporter | Documentation and report generation |
technical-writer | Documentation specialist |
Role resolution order
The engine resolves role names in this order:
- Project
.agents/roles/<name>/(local override) - Global
~/.ostwin/.agents/roles/<name>/(installed roles) - Built-in roles shipped with OSTwin
The first match wins, letting you override global roles per-project.