[Phase 5.3] Capability Fusion & Recombination #65

Closed
opened 2026-04-01 01:58:50 +00:00 by Mark · 0 comments
Owner

Overview

Enable the mesh to combine the best traits from multiple competing variants into a new, superior capability.

Problem Statement

Current championship flow:

Variant A (score: 0.85) ─┐
Variant B (score: 0.82) ─┼─► Winner: Variant A promoted
Variant C (score: 0.78) ─┘

But Variant B might have a better prompt structure while Variant A has better error handling. We can't combine their strengths.

Proposed Solution

5.3.1: Trait Extractor

Create evolution/trait_extractor.py:

class TraitExtractor:
    """Extract measurable traits from capability variants."""
    
    def extract_traits(
        self,
        variant_path: str
    ) -> dict:
        """Extract traits from a capability implementation."""
        return {
            "error_handling_score": 0.9,  # Based on try/except coverage
            "prompt_complexity": 7,       # Prompt template complexity
            "timeout_handling": True,     # Has timeout logic
            "retry_logic": True,          # Has retry logic
            "validation_coverage": 0.8,   # Input validation completeness
            "output_structure": {...},    # Output schema structure
        }
    
    def compare_traits(
        self,
        variants: list[str]
    ) -> dict:
        """Compare traits across variants."""
        ...

5.3.2: Capability Fusion

class CapabilityFusion:
    """Fuse best traits from multiple variants."""
    
    def fuse(
        self,
        variants: list[str],
        strategy: str = "best_of_breed"
    ) -> str:
        """Create new capability combining best traits.
        
        Strategies:
        - best_of_breed: Take best trait from each variant
        - weighted_average: Weight traits by parent scores
        - crossover: Genetic algorithm crossover
        """

5.3.3: Fusion Pipeline

Championship Top 3 Variants
        ↓
TraitExtractor.extract_traits() for each
        ↓
Identify best trait from each category
        ↓
ImplementationGenerator.generate_fused() creates new code
        ↓
Save to _nerve/fused_<id>/ as new variant
        ↓
Enter next championship

Deliverables

  • evolution/trait_extractor.py - Trait extraction
  • evolution/capability_fusion.py - Fusion logic
  • extract_code_traits() - AST-based trait analysis
  • extract_prompt_traits() - Prompt template analysis
  • fuse_capabilities() - Combine best traits
  • Integration with championship post-processing
  • Fusion variant tracking in lineage

Trait Categories

Trait Measurement Method
Error handling AST: try/except block coverage
Input validation Schema compliance check
Output quality Championship score
Latency Execution time stats
Prompt efficiency Token count vs success rate
Retry robustness Retry logic presence
Logging Logging statement count

Success Criteria

  • Can extract measurable traits from any capability
  • Can fuse 2+ variants into new capability
  • Fused capability inherits best traits from parents
  • Fused capability enters championship
  • Fused capabilities show >10% improvement over parents

Dependencies

  • #63 (Code Generation) - for generating fused implementations
  • #64 (Factory Learning) - for trait scoring

Estimated Duration

2 weeks

  • Parent: #62 (Phase 5 Meta)
  • Uses: evolution/championship.py
## Overview Enable the mesh to combine the best traits from multiple competing variants into a new, superior capability. ## Problem Statement Current championship flow: ``` Variant A (score: 0.85) ─┐ Variant B (score: 0.82) ─┼─► Winner: Variant A promoted Variant C (score: 0.78) ─┘ ``` But Variant B might have a better prompt structure while Variant A has better error handling. We can't combine their strengths. ## Proposed Solution ### 5.3.1: Trait Extractor Create `evolution/trait_extractor.py`: ```python class TraitExtractor: """Extract measurable traits from capability variants.""" def extract_traits( self, variant_path: str ) -> dict: """Extract traits from a capability implementation.""" return { "error_handling_score": 0.9, # Based on try/except coverage "prompt_complexity": 7, # Prompt template complexity "timeout_handling": True, # Has timeout logic "retry_logic": True, # Has retry logic "validation_coverage": 0.8, # Input validation completeness "output_structure": {...}, # Output schema structure } def compare_traits( self, variants: list[str] ) -> dict: """Compare traits across variants.""" ... ``` ### 5.3.2: Capability Fusion ```python class CapabilityFusion: """Fuse best traits from multiple variants.""" def fuse( self, variants: list[str], strategy: str = "best_of_breed" ) -> str: """Create new capability combining best traits. Strategies: - best_of_breed: Take best trait from each variant - weighted_average: Weight traits by parent scores - crossover: Genetic algorithm crossover """ ``` ### 5.3.3: Fusion Pipeline ``` Championship Top 3 Variants ↓ TraitExtractor.extract_traits() for each ↓ Identify best trait from each category ↓ ImplementationGenerator.generate_fused() creates new code ↓ Save to _nerve/fused_<id>/ as new variant ↓ Enter next championship ``` ## Deliverables - [ ] `evolution/trait_extractor.py` - Trait extraction - [ ] `evolution/capability_fusion.py` - Fusion logic - [ ] `extract_code_traits()` - AST-based trait analysis - [ ] `extract_prompt_traits()` - Prompt template analysis - [ ] `fuse_capabilities()` - Combine best traits - [ ] Integration with championship post-processing - [ ] Fusion variant tracking in lineage ## Trait Categories | Trait | Measurement Method | |-------|-------------------| | Error handling | AST: try/except block coverage | | Input validation | Schema compliance check | | Output quality | Championship score | | Latency | Execution time stats | | Prompt efficiency | Token count vs success rate | | Retry robustness | Retry logic presence | | Logging | Logging statement count | ## Success Criteria - [ ] Can extract measurable traits from any capability - [ ] Can fuse 2+ variants into new capability - [ ] Fused capability inherits best traits from parents - [ ] Fused capability enters championship - [ ] Fused capabilities show >10% improvement over parents ## Dependencies - #63 (Code Generation) - for generating fused implementations - #64 (Factory Learning) - for trait scoring ## Estimated Duration 2 weeks ## Related - Parent: #62 (Phase 5 Meta) - Uses: `evolution/championship.py`
Mark 2026-05-27 23:29:14 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/mesh-seed#65
No description provided.