BMAD-METHOD/.claude/orchestrator/intelligent-templates.md

13 KiB

Intelligent Template System - Adaptive Document Generation

System Overview

The Intelligent Template System provides context-aware, validated document generation with conditional logic, automatic quality assessment, and adaptive complexity handling.

Template Intelligence Engine

Enhanced Template Schema

template_definition:
  metadata:
    id: "project-brief-v2"
    name: "Intelligent Project Brief"
    version: "2.0.0"
    complexity_adaptable: true
    validation_enabled: true
    
  configuration:
    context_awareness: true
    conditional_sections: true
    validation_rules: true
    quality_assessment: true
    auto_improvement: true
    
  context_requirements:
    required_inputs:
      - "user_specification"
      - "project_metadata.complexity_score"
    optional_inputs:
      - "global_context.domain_knowledge"
      - "global_context.technical_preferences"
      
  variables:
    # Core variables with validation
    project_name:
      type: "string"
      required: true
      validation:
        min_length: 3
        max_length: 100
        pattern: "^[A-Za-z0-9\\s\\-_]+$"
        no_placeholder_text: true
        
    complexity_score:
      type: "number"
      source: "project_metadata.complexity_score"
      range: [1, 10]
      
    target_users:
      type: "array"
      required: true
      validation:
        min_items: 1
        max_items: 5
        item_validation:
          type: "string"
          min_length: 10
          no_vague_terms: ["users", "people", "everyone"]
          
    core_features:
      type: "array"
      required: true
      validation:
        min_items: 3
        max_items: 20
        complexity_scaling: true
        item_validation:
          type: "string"
          min_length: 15
          must_contain_action_verb: true
          specificity_score: ">= 7"
          
  sections:
    # Conditional sections based on complexity
    executive_summary:
      condition: "always"
      template: |
        ## Executive Summary
        
        {{project_name}} addresses {{problem_statement_summary}} for {{target_audience_summary}}. 
        
        **Key Value Proposition:** {{value_proposition}}
        
        **Success Metrics:** {{#each success_metrics}}{{this}}{{#unless @last}}, {{/unless}}{{/each}}
        
        {{#if complexity_score >= 7}}
        **Strategic Importance:** {{strategic_context}}
        {{/if}}        
      
      validation:
        required_elements: ["value_proposition", "success_metrics"]
        min_word_count: 50
        max_word_count: 200
        readability_score: ">= 8"
        
    problem_statement:
      condition: "always"
      template: |
        ## Problem Statement
        
        {{problem_description}}
        
        {{#if quantified_impact}}
        **Current Impact:** {{quantified_impact}}
        {{/if}}
        
        {{#if complexity_score >= 6}}
        ### Root Cause Analysis
        {{#each root_causes}}
        - **{{category}}:** {{description}}
        {{/each}}
        {{/if}}
                
      validation:
        required_elements: ["problem_description"]
        specificity_check: "must_include_specific_metrics_or_examples"
        avoid_terms: ["many users", "often", "sometimes", "various"]
        min_word_count: 100
        
    technical_considerations:
      condition: "complexity_score >= 5"
      template: |
        ## Technical Considerations
        
        ### Platform Requirements
        - **Target Platforms:** {{target_platforms}}
        - **Performance Requirements:** {{performance_specs}}
        {{#if complexity_score >= 8}}
        - **Scalability Targets:** {{scalability_requirements}}
        - **Integration Requirements:** {{#each integration_requirements}}{{this}}{{#unless @last}}, {{/unless}}{{/each}}
        {{/if}}
        
        ### Technology Constraints
        {{#each technical_constraints}}
        - **{{category}}:** {{constraint}} ({{rationale}})
        {{/each}}
        
        {{#if complexity_score >= 7}}
        ### Architecture Considerations
        - **Service Architecture:** {{service_architecture_preference}}
        - **Data Architecture:** {{data_architecture_notes}}
        - **Security Requirements:** {{security_level_required}}
        {{/if}}
                
      validation:
        required_when_included: ["target_platforms", "performance_specs"]
        technical_specificity: "must_include_specific_technologies_or_standards"
        
    risk_assessment:
      condition: "complexity_score >= 6 OR project_constraints.timeline == 'rush'"
      template: |
        ## Risk Assessment & Mitigation
        
        ### High-Priority Risks
        {{#each high_risks}}
        - **{{name}}** ({{probability}} probability, {{impact}} impact)
          - **Description:** {{description}}
          - **Mitigation:** {{mitigation_strategy}}
          {{#if contingency_plan}}
          - **Contingency:** {{contingency_plan}}
          {{/if}}
        {{/each}}
        
        {{#if complexity_score >= 8}}
        ### Technical Risk Analysis
        - **Technology Risks:** {{technology_risks}}
        - **Integration Risks:** {{integration_risks}}
        - **Performance Risks:** {{performance_risks}}
        {{/if}}
                
      validation:
        required_elements: ["high_risks"]
        risk_completeness: "each_risk_must_have_mitigation"
        
    simplified_scope:
      condition: "complexity_score <= 3"
      template: |
        ## MVP Scope (Simplified Approach)
        
        ### Core Features (Essential)
        {{#each core_features}}
        - **{{name}}:** {{description}}
        {{/each}}
        
        ### Success Criteria
        {{success_criteria_simple}}
        
        ### Out of Scope
        - Advanced features can be added in future iterations
        - Focus on core user workflow first
        - Optimize for learning and iteration speed
                
    comprehensive_scope:
      condition: "complexity_score >= 7"
      template: |
        ## Comprehensive Project Scope
        
        ### Phase 1: Foundation (MVP)
        {{#each phase_1_features}}
        - **{{name}}:** {{description}} ({{effort_estimate}})
        {{/each}}
        
        ### Phase 2: Enhancement
        {{#each phase_2_features}}  
        - **{{name}}:** {{description}} ({{effort_estimate}})
        {{/each}}
        
        ### Phase 3: Advanced Features
        {{#each phase_3_features}}
        - **{{name}}:** {{description}} ({{effort_estimate}})
        {{/each}}
        
        ### Success Metrics by Phase
        - **Phase 1:** {{phase_1_metrics}}
        - **Phase 2:** {{phase_2_metrics}}
        - **Phase 3:** {{phase_3_metrics}}
                
  quality_gates:
    content_validation:
      checks:
        - name: "no_placeholder_content"
          pattern: "{{.*}}"
          failure: "Template variables not properly substituted"
          
        - name: "specific_language"
          avoid_terms: ["various", "multiple", "many", "some", "often", "usually"]
          failure: "Content too vague, needs specific details"
          
        - name: "quantified_statements"
          require_pattern: "\\d+%|\\$[0-9,]+|[0-9,]+\\s*(users|customers|requests|transactions)"
          min_occurrences: 2
          failure: "Needs more quantified statements"
          
        - name: "actionable_content"
          require_verbs: ["will", "must", "should", "enables", "provides", "reduces", "increases"]
          min_occurrences: 5
          failure: "Content not actionable enough"
          
    structure_validation:
      checks:
        - name: "required_sections_present"
          sections: ["executive_summary", "problem_statement"]
          failure: "Missing required sections"
          
        - name: "section_length_appropriate"
          rules:
            executive_summary: {min_words: 50, max_words: 200}
            problem_statement: {min_words: 100, max_words: 500}
          failure: "Section length inappropriate"
          
        - name: "logical_flow"
          sequence: ["problem", "solution", "implementation", "success"]
          failure: "Document flow illogical"
          
  auto_improvement:
    triggers:
      - quality_score < 7.0
      - validation_failures > 2
      - user_feedback_negative
      
    improvements:
      specificity_enhancement:
        action: "add_specific_examples_and_metrics"
        confidence_threshold: 0.8
        
      structure_optimization:
        action: "reorganize_for_better_flow"
        confidence_threshold: 0.7
        
      clarity_improvement:
        action: "simplify_language_and_add_definitions"
        confidence_threshold: 0.9

Template Processing Engine

Context-Aware Template Renderer

template_processor:
  preprocessing:
    - validate_input_context
    - calculate_complexity_adaptations
    - determine_conditional_sections
    - prepare_variable_substitutions
    
  processing:
    - render_conditional_sections
    - substitute_variables_with_validation
    - apply_formatting_rules
    - inject_quality_checkpoints
    
  postprocessing:
    - validate_output_quality
    - check_completeness
    - assess_readability
    - generate_improvement_suggestions
    
  context_injection:
    method: "structured_data_merge"
    validation: "pre_render_validation"
    fallback: "use_default_values_with_warnings"

Integration with Agent System

Enhanced Agent Template Usage

# Added to each agent prompt
## <template_integration>
### Available Intelligent Templates:
You have access to context-aware templates that adapt based on:
- Project complexity score ({{project_metadata.complexity_score}}/10)
- Previous agent outputs and their quality scores
- Global project constraints and preferences

### Template Usage Protocol:
1. **Select Appropriate Template**: Choose based on your output type and project complexity
2. **Validate Context Availability**: Confirm required context is available before rendering
3. **Quality Self-Check**: Review template output against built-in quality gates
4. **Structured Data Generation**: Provide both human-readable output and structured data

### Templates Available to You:
{{#each available_templates}}
- **{{name}}** (Complexity: {{min_complexity}}-{{max_complexity}})
  - Use for: {{use_cases}}
  - Required context: {{required_context}}
  - Quality threshold: {{quality_threshold}}
{{/each}}
</template_integration>

## <template_quality_validation>
After using any template, validate your output against these criteria:

**Content Quality:**
- [ ] No placeholder text ({{...}}) remains
- [ ] Specific, quantified statements included
- [ ] Actionable language used throughout
- [ ] Appropriate level of detail for complexity score

**Structure Quality:**
- [ ] All required sections included
- [ ] Logical information flow
- [ ] Appropriate section lengths
- [ ] Clear headings and organization

**Context Integration:**
- [ ] Referenced all available previous agent outputs
- [ ] Maintained consistency with project constraints
- [ ] Adapted appropriately to complexity level
- [ ] Included relevant cross-references
</template_quality_validation>

Intelligent Template Examples

Complexity-Adaptive Project Brief Template

# Project Brief: {{project_name}}
{{#template_metadata}}
<!-- Generated using Intelligent Template System v2.0 -->
<!-- Complexity Score: {{complexity_score}}/10 -->
<!-- Template Adaptations: {{active_adaptations}} -->
{{/template_metadata}}

{{> executive_summary}}

{{> problem_statement}}

## Proposed Solution

{{solution_description}}

{{#if complexity_score >= 6}}
### Solution Architecture Overview
{{solution_architecture_summary}}

### Key Differentiators
{{#each key_differentiators}}
- **{{category}}:** {{description}} ({{competitive_advantage}})
{{/each}}
{{/if}}

## Target Users & Market

### Primary User Segment: {{primary_segment_name}}
{{primary_user_description}}

{{#if secondary_users_exist}}
### Secondary User Segment: {{secondary_segment_name}}
{{secondary_user_description}}
{{/if}}

{{#if complexity_score >= 7}}
### Market Analysis
- **Market Size:** {{market_size}}
- **Growth Rate:** {{market_growth}}
- **Key Competitors:** {{#each competitors}}{{name}}{{#unless @last}}, {{/unless}}{{/each}}
{{/if}}

{{> technical_considerations}}

{{> risk_assessment}}

{{#if complexity_score <= 3}}
{{> simplified_scope}}
{{else}}
{{> comprehensive_scope}}
{{/if}}

## Next Steps

### Immediate Actions (Week 1)
{{#each immediate_actions}}
1. {{action}} ({{responsible_party}})
{{/each}}

### PM Handoff Requirements
This Project Brief provides {{completeness_level}} context for {{project_name}}. 

**Required for PM Phase:**
- All sections marked as "Required" must be completed
- Technical constraints must be validated with technical team
- User segment definitions must include specific demographics

{{#if complexity_score >= 7}}
**Additional Enterprise Requirements:**
- Stakeholder sign-off on scope and budget
- Compliance and security review completed
- Resource allocation confirmed
{{/if}}

---

**Quality Assessment:** {{quality_score}}/10 (Generated: {{generation_timestamp}})

This Intelligent Template System transforms our static templates into adaptive, context-aware document generators that ensure high-quality, consistent outputs regardless of project complexity.