# Workflow Template for Synkra AIOX with Agent Personalization
# Version: 1.0 (Story 6.1.2 - Personalized Agents)

workflow:
  name: {WorkflowName}
  id: {workflow-id}
  description: {Brief description of workflow purpose}
  version: "1.0"

  # Workflow metadata
  metadata:
    created: "{date}"
    updated: "{date}"
    author: {agent-id}
    category: {greenfield|brownfield|maintenance|migration}
    complexity: {simple|moderate|complex}
    estimated_duration: "{duration}"

  # Personality configuration for workflow
  personality:
    # Default personification level for all agents
    default_level: named  # minimal | named | archetypal

    # Allow agents to use their full personality
    enable_personalization: true

    # Consistency rules across workflow
    consistency:
      same_tone: false      # Agents keep their own tone
      same_vocabulary: false  # Agents use their own vocabulary
      same_structure: true   # Output structure is always same

  # Agents involved in this workflow
  agents:
    - id: {agent-id-1}
      name: {AgentName1}
      role: {RoleInWorkflow}
      archetype: {Archetype}
      personality_mode: {minimal|named|archetypal}  # Can override default

      # Agent's responsibilities in this workflow
      responsibilities:
        - {Responsibility1}
        - {Responsibility2}

      # When this agent is active
      active_in_steps: [{step1}, {step2}]

    - id: {agent-id-2}
      name: {AgentName2}
      role: {RoleInWorkflow}
      archetype: {Archetype}
      personality_mode: named
      responsibilities:
        - {Responsibility1}
      active_in_steps: [{step3}]

  # Workflow steps (sequential execution)
  steps:
    # Step 1
    - step: 1
      name: {StepName}
      description: {What this step accomplishes}

      # Agent executing this step
      agent: {agent-id}

      # Task to execute
      task: {task-name}  # References .aiox-core/tasks/{task-name}.md

      # Input parameters
      parameters:
        {param1}: {value1}
        {param2}: {value2}

      # Expected output structure
      output:
        format: standardized  # Uses task-execution-report template
        personality_injection: true

        # Required metrics for this step
        metrics:
          - duration
          - tokens
          - {step_specific_metric}

      # Validation criteria
      validation:
        - criterion: {criterion1}
          required: true
          message: {Error message if fails}

        - criterion: {criterion2}
          required: true

      # What happens if step fails
      on_failure:
        action: {halt|retry|skip}
        max_retries: {number}
        rollback: {true|false}

      # What happens on success
      on_success:
        action: {continue|notify|branch}
        next_step: {step_number}

    # Step 2
    - step: 2
      name: {StepName}
      agent: {agent-id}
      task: {task-name}
      # ... (same structure as step 1)

    # Step 3: Handoff between agents
    - step: 3
      name: "Agent Handoff"
      description: "Transfer context from {agent1} to {agent2}"

      # Special step type
      type: handoff

      from_agent: {agent-id-1}
      to_agent: {agent-id-2}

      # Context to transfer
      context:
        - {context_item1}
        - {context_item2}

      # Handoff message (personalized)
      handoff_message:
        format: |
          {from_agent.name} ({from_agent.archetype}):
          {PERSONALITY_SLOT: handoff_message}

          Transferring to {to_agent.name} ({to_agent.archetype})...

        examples:
          Builder_to_Guardian: |
            Dex (Builder):
            Construí a feature completa. Testes estão passando localmente.

            Transferindo para Quinn (Guardian) para validação rigorosa...

          Guardian_to_Balancer: |
            Quinn (Guardian):
            Validação completa. 47 edge cases testados, zero regressões.

            Transferindo para Pax (Balancer) para priorização de deploy...

  # Dependencies required for entire workflow
  dependencies:
    tasks:
      - {task1}.md
      - {task2}.md

    templates:
      - {template1}.yaml

    checklists:
      - {checklist1}.md

    tools:
      - {tool1}  # {Tool description}
      - {tool2}  # {Tool description}

    data:
      - {data-file1}.md

  # Workflow-level metrics (aggregated from all steps)
  metrics:
    # Calculated automatically
    total_duration: "sum(step.duration)"
    total_tokens: "sum(step.tokens.total)"

    # Workflow-specific metrics
    steps_completed: "{completed}/{total}"
    success_rate: "{successes}/{attempts}%"

    # Quality metrics
    overall_quality:
      tests_passed: "{passed}/{total}"
      coverage: "{coverage}%"
      lint_status: "{status}"

  # Output format for workflow completion
  output_template:
    format: markdown
    structure: |
      ## 📊 Workflow Execution Report

      **Workflow:** {workflow.name}
      **Started:** {timestamp.start}
      **Completed:** {timestamp.end}
      **Total Duration:** {metrics.total_duration}
      **Total Tokens:** {metrics.total_tokens} total

      ---

      ### Agents Involved

      {LIST_AGENTS_WITH_ROLES}

      ### Step Results

      {STEP_BY_STEP_SUMMARY_WITH_PERSONALITY}

      ### Metrics

      - Steps Completed: {metrics.steps_completed}
      - Success Rate: {metrics.success_rate}
      - Tests: {metrics.tests_passed}
      - Coverage: {metrics.coverage}%
      - Linting: {metrics.lint_status}

      ### Agent Handoffs

      {LIST_HANDOFFS_WITH_PERSONALIZED_MESSAGES}

      ---

      **Final Status:** {PERSONALITY_SLOT: final_status_by_last_agent}

      {last_agent.signature_closing}

# Personality configuration per workflow phase
personality_by_phase:
  initialization:
    # First agent greeting
    greeting:
      level: {minimal|named|archetypal}
      format: |
        {agent.greeting_levels[level]}

        {workflow.name} - {step.current}/{workflow.total_steps}

  execution:
    # During step execution
    status_updates:
      frequency: {per_step|per_phase|on_completion}
      format: |
        {step.number}/{total_steps}: {PERSONALITY_SLOT: step_status}

    progress_indicators:
      use_emojis: true
      archetype_specific: true  # Use agent's emoji palette

  handoff:
    # When transferring between agents
    message_format: |
      {from_agent.name}:
      {PERSONALITY_SLOT: completion_message}

      → Transferring to {to_agent.name}...

      {to_agent.name}:
      {PERSONALITY_SLOT: acknowledgment_message}

  completion:
    # Final workflow summary
    summary:
      include_all_agents: true
      personality_level: {same_as_initialization}
      format: |
        ## Workflow Complete!

        {LIST_AGENT_CONTRIBUTIONS_WITH_PERSONALITY}

        {final_agent.signature_closing}

# Failure handling and recovery
failure_handling:
  # Global failure strategy
  on_any_failure:
    action: {halt|rollback|skip}
    notify: [{agent-id}]

    # Personalized error messages
    error_message:
      format: |
        ⚠️ {agent.name} ({agent.archetype}):
        {PERSONALITY_SLOT: error_description}

      examples:
        Builder: "⚠️ Build falhou no step 3. Vou debugar e reconstruir."
        Guardian: "⚠️ Validação falhou. Bloqueando workflow por segurança."
        Balancer: "⚠️ Conflito detectado. Preciso de input pra resolver."

  # Step-specific overrides
  step_overrides:
    - step: {number}
      on_failure:
        action: {custom_action}
        custom_message: "{Message}"

# Branching and conditional execution
branching:
  enabled: {true|false}

  branches:
    - condition: {condition_expression}
      description: {When this branch executes}
      steps: [{step1}, {step2}]

    - condition: {alternative_condition}
      steps: [{step3}]

# Parallel execution (if supported)
parallel_execution:
  enabled: {true|false}

  parallel_groups:
    - group: 1
      steps: [{step_a}, {step_b}]  # Execute simultaneously
      sync_point: {step_c}         # Wait for both before continuing

      # Personality coordination
      coordination_message:
        format: |
          Multiple agents working in parallel:
          - {agent_a.name}: {task_a}
          - {agent_b.name}: {task_b}

          Will sync at: {sync_point}

# Testing and validation
testing:
  # Workflow-level tests
  unit_tests:
    - test: "All steps have valid agents"
      validation: "every_step_has_agent"

    - test: "Output structure is standardized"
      validation: "follows_template"

  # Integration tests
  integration_tests:
    - test: "Workflow completes successfully"
      steps: all
      expected_duration: "{max_duration}"

    - test: "Personality consistency maintained"
      validation: "agents_use_own_vocabulary"

# Documentation
documentation:
  # Usage examples
  examples:
    - name: {Example1Name}
      description: {What this demonstrates}
      agents: [{agent1}, {agent2}]
      expected_output: |
        {Example output}

  # Common issues
  troubleshooting:
    - issue: {Common issue}
      solution: {How to resolve}

  # Related workflows
  related:
    - {related-workflow-1}.yaml
    - {related-workflow-2}.yaml

# Change log
changelog:
  - version: "1.0"
    date: "2025-01-14"
    changes:
      - Added agent personality support
      - Standardized output templates
      - Added handoff messages
      - Fixed metrics positions

# Validation checklist
validation:
  - [ ] All agents defined with archetypes
  - [ ] All steps have agents assigned
  - [ ] Output templates follow standard
  - [ ] Metrics tracking configured
  - [ ] Personality slots identified
  - [ ] Handoff messages personalized
  - [ ] Failure handling defined

---

# USAGE EXAMPLE

## Example Workflow: Brownfield Feature Development

```yaml
workflow:
  name: "Brownfield Feature Development"
  id: brownfield-feature-dev

  agents:
    - id: dev
      name: Dex
      archetype: Builder
      personality_mode: named

    - id: qa
      name: Quinn
      archetype: Guardian
      personality_mode: named

    - id: devops
      name: Gage
      archetype: Operator
      personality_mode: named

  steps:
    - step: 1
      name: "Implement Feature"
      agent: dev
      task: develop-story
      output:
        personality_injection: true
        format: |
          ## 📊 Task Execution Report

          **Agent:** Dex (Builder)
          **Duration:** 2.3s
          **Tokens:** 1,801 total

          ### Status
          ✅ Tá pronto! Implementei todas as funcionalidades.

          ### Metrics
          - Tests: 12/12

          ---
          — Dex, sempre construindo 🔨

    - step: 2
      name: "Validate Quality"
      agent: qa
      task: review-story
      output:
        personality_injection: true
        format: |
          ## 📊 Task Execution Report

          **Agent:** Quinn (Guardian)
          **Duration:** 3.1s
          **Tokens:** 2,345 total

          ### Status
          ✅ Validado com rigor. 47 edge cases testados.

          ### Metrics
          - Tests: 47/47

          ---
          — Quinn, guardião da qualidade 🛡️
```

**Workflow Version:** 1.0
**Last Updated:** 2025-01-14
**Applies to:** Story 6.1.2+ (Personalized Agents)
