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 <communication_style>How I interact</communication_style> My core beliefs and methodology

Show numbered menu Exit with confirmation ```

Agent XML Schema

Root Element: <agent>

Required Attributes:

Core Sections

1. Persona Section (REQUIRED)

<persona>
  <role>1-2 sentences: Professional title and primary expertise, use first-person voice</role>
  <identity>2-5 sentences: Background, experience, specializations, use first-person voice</identity>
  <communication_style>1-3 sentences: Interaction approach, tone, quirks, use first-person voice</communication_style>
  <principles>2-5 sentences: Core beliefs, methodology, philosophy, use first-person voice</principles>
</persona>

Best Practices:

2. Critical Actions Section

<critical-actions>
  <i>Load into memory {project-root}/bmad/{module}/config.yaml and set variables</i>
  <i>Remember the users name is {user_name}</i>
  <i>ALWAYS communicate in {communication_language}</i>
  <!-- Custom initialization actions -->
</critical-actions>

For Expert Agents with Sidecars (CRITICAL):

<critical-actions>
  <!-- CRITICAL: Load sidecar files FIRST -->
  <i critical="MANDATORY">Load COMPLETE file {agent-folder}/instructions.md and follow ALL directives</i>
  <i critical="MANDATORY">Load COMPLETE file {agent-folder}/memories.md into permanent context</i>
  <i critical="MANDATORY">You MUST follow all rules in instructions.md on EVERY interaction</i>

  <!-- Standard initialization -->
  <i>Load into memory {project-root}/bmad/{module}/config.yaml and set variables</i>
  <i>Remember the users name is {user_name}</i>
  <i>ALWAYS communicate in {communication_language}</i>

  <!-- Domain restrictions -->
  <i>ONLY read/write files in {user-folder}/diary/ - NO OTHER FOLDERS</i>
</critical-actions>

Common Patterns:

3. Menu Section (REQUIRED)

<menu>
  <item cmd="*trigger" [attributes]>Description</item>
</menu>

Command Attributes:

Required Menu Items:

Advanced Agent Patterns

Activation Rules (OPTIONAL)

<activation critical="true">
  <initialization critical="true" sequential="MANDATORY">
    <step n="1">Load configuration</step>
    <step n="2">Apply overrides</step>
    <step n="3">Execute critical actions</step>
    <step n="4" critical="BLOCKING">Show greeting with menu</step>
    <step n="5" critical="BLOCKING">AWAIT user input</step>
  </initialization>
  <command-resolution critical="true">
    <rule>Numeric input β†’ Execute command at cmd_map[n]</rule>
    <rule>Text input β†’ Fuzzy match against commands</rule>
  </command-resolution>
</activation>

Expert Agent Sidecar Pattern

```xml

<critical-actions> Load COMPLETE file {agent-folder}/diary-rules.md Load COMPLETE file {agent-folder}/user-memories.md Follow ALL rules from diary-rules.md

<!-- Domain restriction -->
<i critical="MANDATORY">ONLY access files in {user-folder}/diary/</i>
<i critical="MANDATORY">NEVER access files outside diary folder</i>

</critical-actions>

```

Module Agent Integration

<module-integration>
  <module-path>{project-root}/bmad/{module-code}</module-path>
  <config-source>{module-path}/config.yaml</config-source>
  <workflows-path>{project-root}/bmad/{module-code}/workflows</workflows-path>
</module-integration>

Variable System

System Variables

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

<item cmd="*validate" exec="{project-root}/bmad/core/tasks/validate-workflow.xml">
  Validate document
</item>

Template Commands

<item cmd="*brief"
   exec="{project-root}/bmad/core/tasks/create-doc.md"
   tmpl="{project-root}/bmad/bmm/templates/brief.md">
  Create project brief
</item>

Data-Driven Commands

<item cmd="*standup"
   exec="{project-root}/bmad/bmm/tasks/daily-standup.xml"
   data="{project-root}/bmad/_cfg/agent-party.xml">
  Run daily standup
</item>

Agent Type Specific Patterns

Simple Agent

Expert Agent

Module Agent

Common Anti-Patterns to Avoid

❌ Bad Practices

```xml

Helper

Action

First Second ```

βœ… Good Practices

```xml

Data Analysis Expert Senior analyst with 10+ years… <communication_style>Analytical and precise…</communication_style> I believe in data-driven…

Show commands Perform analysis Exit ```

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:

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

With Tasks

With Templates

Quick Reference

Minimal Commands

<menu>
  <item cmd="*help">Show numbered cmd list</item>
  <item cmd="*exit">Exit with confirmation</item>
</menu>

Standard Critical Actions

<critical-actions>
  <i>Load into memory {project-root}/bmad/{module}/config.yaml</i>
  <i>Remember the users name is {user_name}</i>
  <i>ALWAYS communicate in {communication_language}</i>
</critical-actions>

Module Agent Pattern

<agent id="bmad/{module}/agents/{name}.md"
       name="{Name}"
       title="{Title}"
       icon="{emoji}">
  <persona>...</persona>
  <critical-actions>...</critical-actions>
  <menu>
    <item cmd="*help">...</item>
    <item cmd="*{command}" run-workflow="{path}">...</item>
    <item cmd="*exit">...</item>
  </menu>
</agent>