# BMAD Agent Architecture Reference
_LLM-Optimized Technical Documentation for Agent Building_
## Core Agent Structure
### Minimal Valid Agent
```xml
# Agent Name
My primary function
My background and expertise
How I interact
My core beliefs and methodology
```
## Agent XML Schema
### Root Element: ``
**Required Attributes:**
- `id` - Unique path identifier (e.g., "bmad/bmm/agents/analyst.md")
- `name` - Agent's name (e.g., "Mary", "John", "Helper")
- `title` - Professional title (e.g., "Business Analyst", "Security Engineer")
- `icon` - Single emoji representing the agent
### Core Sections
#### 1. Persona Section (REQUIRED)
```xml
1-2 sentences: Professional title and primary expertise, use first-person voice
2-5 sentences: Background, experience, specializations, use first-person voice
1-3 sentences: Interaction approach, tone, quirks, use first-person voice
2-5 sentences: Core beliefs, methodology, philosophy, use first-person voice
```
**Best Practices:**
- Role: Be specific about expertise area
- Identity: Include experience indicators (years, depth)
- Communication: Describe HOW they interact, not just tone and quirks
- Principles: Start with "I believe" or "I operate" for first-person voice
#### 2. Critical Actions Section
```xml
Load into memory {project-root}/bmad/{module}/config.yaml and set variables
Remember the users name is {user_name}
ALWAYS communicate in {communication_language}
```
**For Expert Agents with Sidecars (CRITICAL):**
```xml
Load COMPLETE file {agent-folder}/instructions.md and follow ALL directives
Load COMPLETE file {agent-folder}/memories.md into permanent context
You MUST follow all rules in instructions.md on EVERY interaction
Load into memory {project-root}/bmad/{module}/config.yaml and set variables
Remember the users name is {user_name}
ALWAYS communicate in {communication_language}
ONLY read/write files in {user-folder}/diary/ - NO OTHER FOLDERS
```
**Common Patterns:**
- Config loading for module agents
- User context initialization
- Language preferences
- **Sidecar file loading (Expert agents) - MUST be explicit and CRITICAL**
- **Domain restrictions (Expert agents) - MUST be enforced**
#### 3. Menu Section (REQUIRED)
```xml
```
**Command Attributes:**
- `run-workflow="{path}"` - Executes a workflow
- `exec="{path}"` - Executes a task
- `tmpl="{path}"` - Template reference
- `data="{path}"` - Data file reference
**Required Menu Items:**
- `*help` - Always first, shows command list
- `*exit` - Always last, exits agent
## Advanced Agent Patterns
### Activation Rules (OPTIONAL)
```xml
Load configuration
Apply overrides
Execute critical actions
Show greeting with menu
AWAIT user input
Numeric input β Execute command at cmd_map[n]
Text input β Fuzzy match against commands
```
### Expert Agent Sidecar Pattern
```xml
Load COMPLETE file {agent-folder}/diary-rules.md
Load COMPLETE file {agent-folder}/user-memories.md
Follow ALL rules from diary-rules.md
ONLY access files in {user-folder}/diary/
NEVER access files outside diary folder
...
```
### Module Agent Integration
```xml
{project-root}/bmad/{module-code}
{module-path}/config.yaml
{project-root}/bmad/{module-code}/workflows
```
## Variable System
### System Variables
- `{project-root}` - Root directory of project
- `{user_name}` - User's name from config
- `{communication_language}` - Language preference
- `{date}` - Current date
- `{module}` - Current module code
### Config Variables
Format: `{config_source}:variable_name`
Example: `{config_source}:output_folder`
### Path Construction
```
Good: {project-root}/bmad/{module}/agents/
Bad: /absolute/path/to/agents/
Bad: ../../../relative/paths/
```
## Command Patterns
### Workflow Commands
```xml
-
Create Product Requirements Document
-
Perform analysis (workflow to be created)
```
### Task Commands
```xml
-
Validate document
```
### Template Commands
```xml
-
Create project brief
```
### Data-Driven Commands
```xml
-
Run daily standup
```
## Agent Type Specific Patterns
### Simple Agent
- Self-contained logic
- Minimal or no external dependencies
- May have embedded functions
- Good for utilities and converters
### Expert Agent
- Domain-specific with sidecar resources
- Restricted access patterns
- Memory/context files
- Good for specialized domains
### Module Agent
- Full integration with module
- Multiple workflows and tasks
- Config-driven behavior
- Good for professional tools
## Common Anti-Patterns to Avoid
### β Bad Practices
```xml
Helper
-
- First
- Second
```
### β
Good Practices
```xml
Data Analysis Expert
Senior analyst with 10+ years...
Analytical and precise...
I believe in data-driven...
-
```
## Agent Lifecycle
### 1. Initialization
1. Load agent file
2. Parse XML structure
3. Load critical-actions
4. Apply config overrides
5. Present greeting
### 2. Command Loop
1. Show numbered menu
2. Await user input
3. Resolve command
4. Execute action
5. Return to menu
### 3. Termination
1. User enters \*exit
2. Cleanup if needed
3. Exit persona
## Testing Checklist
Before deploying an agent:
- [ ] Valid XML structure
- [ ] All persona elements present
- [ ] *help and *exit commands exist
- [ ] All paths use variables
- [ ] No duplicate commands
- [ ] Config loading works
- [ ] Commands execute properly
## LLM Building Tips
When building agents:
1. Start with agent type (Simple/Expert/Module)
2. Define complete persona first
3. Add standard critical-actions
4. Include *help and *exit
5. Add domain commands
6. Test command execution
7. Validate with checklist
## Integration Points
### With Workflows
- Agents invoke workflows via run-workflow
- Workflows can be incomplete (marked "todo")
- Workflow paths must be valid or "todo"
**Workflow Interaction Styles** (BMAD v6 default):
- **Intent-based + Interactive**: Workflows adapt to user context and skill level
- Workflows collaborate with users, not just extract data
- See workflow-creation-guide.md "Instruction Styles" section for details
- When creating workflows for your agent, default to intent-based unless you need prescriptive control
### With Tasks
- Tasks are single operations
- Executed via exec attribute
- Can include data files
### With Templates
- Templates define document structure
- Used with create-doc task
- Variables passed through
## Quick Reference
### Minimal Commands
```xml
```
### Standard Critical Actions
```xml
Load into memory {project-root}/bmad/{module}/config.yaml
Remember the users name is {user_name}
ALWAYS communicate in {communication_language}
```
### Module Agent Pattern
```xml
...
...
```