[Phase 5.6] Meta-Factory (Factory of Factories) #68

Closed
opened 2026-04-01 02:00:34 +00:00 by Mark · 1 comment
Owner

Overview

Enable the mesh to create and evolve its own factories - a "factory of factories" that can generate new factory types.

Problem Statement

Current factories are fixed:

  • worker_factory - creates worker definitions
  • skill_factory - creates skills
  • capability_factory - creates capabilities
  • prompt_factory - creates prompts
  • contract_factory - creates contracts

We cannot:

  • Create new factory types
  • Evolve factory mutation strategies
  • Discover new mutation patterns

Proposed Solution

5.6.1: Meta-Factory Architecture

Create capabilities/_muscle/meta_factory/:

# capabilities/_muscle/meta_factory/template.yaml
capability:
  id: meta_factory_v1
  class: muscle
  
skills:
  - create_factory
  - mutate_factory
  - analyze_factory_effectiveness
  
contracts:
  - intent_type: factory_creation
    skill_family: meta_factory
    input_schema:
      - target_domain: str  # What the factory should create
      - mutation_strategies: list[str]
      - evaluation_criteria: dict
    output_schema:
      - factory_id: str
      - template_path: str

5.6.2: Factory Specification

@dataclass
class FactorySpec:
    """Specification for a new factory."""
    
    factory_id: str
    target_domain: str  # e.g., "prompts", "contracts", "workflows"
    mutation_strategies: list[MutationStrategy]
    evaluation_criteria: dict
    template_schema: dict
    variant_schema: dict

5.6.3: Factory Creation Skill

def create_factory(
    inputs: dict,
    context: dict
) -> dict:
    """Create a new factory capability.
    
    Steps:
    1. Analyze target domain (what should factory create?)
    2. Design mutation strategies (how to vary outputs?)
    3. Generate factory template.yaml
    4. Generate factory run.py (using ImplementationGenerator)
    5. Register factory in capabilities/
    6. Return factory_id
    """

5.6.4: Factory Evolution

Meta-Factory monitors factory effectiveness
        ↓
Identify underperforming factories
        ↓
Generate factory variants:
  - New mutation strategies
  - Different evaluation criteria
  - Modified template schemas
        ↓
Test factory variants in parallel
        ↓
Promote better-performing factory

Example: Creating a Workflow Factory

# Request to meta_factory
{
    "intent_type": "factory_creation",
    "payload": {
        "target_domain": "workflows",
        "mutation_strategies": [
            "add_step",
            "remove_step", 
            "reorder_steps",
            "parallelize_steps",
            "add_checkpoint"
        ],
        "evaluation_criteria": {
            "success_rate_weight": 0.5,
            "latency_weight": 0.3,
            "cost_weight": 0.2
        }
    }
}

# Output: workflow_factory created
{
    "factory_id": "workflow_factory_v1",
    "template_path": "capabilities/_muscle/workflow_factory/template.yaml",
    "status": "ready"
}

Deliverables

  • capabilities/_muscle/meta_factory/ - Meta-factory capability
  • create_factory skill - Generate new factory
  • mutate_factory skill - Evolve existing factory
  • analyze_factory_effectiveness skill - Track factory performance
  • FactorySpec dataclass - Factory specification
  • Factory template generation
  • Factory implementation generation
  • Integration with LineageTracker

Factory Evolution Metrics

Metric Description
Variant success rate % of variants that get promoted
Mean championship score Average score of factory's variants
Mutation diversity Variety of mutation strategies used
Domain coverage Range of problems factory addresses

Success Criteria

  • Can create new factory for any domain
  • New factory generates valid variants
  • Factory variants compete in championships
  • Factories can be mutated and improved
  • Meta-factory can create 2+ new factory types

Dependencies

  • #64 (Factory Learning) - analytics for factory effectiveness
  • #67 (Lineage Tracking) - track factory genealogy

Estimated Duration

2 weeks

  • Parent: #62 (Phase 5 Meta)
  • Uses: capabilities/_shared/base.py (MutationRegistry)
## Overview Enable the mesh to create and evolve its own factories - a "factory of factories" that can generate new factory types. ## Problem Statement Current factories are fixed: - `worker_factory` - creates worker definitions - `skill_factory` - creates skills - `capability_factory` - creates capabilities - `prompt_factory` - creates prompts - `contract_factory` - creates contracts We cannot: - Create new factory types - Evolve factory mutation strategies - Discover new mutation patterns ## Proposed Solution ### 5.6.1: Meta-Factory Architecture Create `capabilities/_muscle/meta_factory/`: ```yaml # capabilities/_muscle/meta_factory/template.yaml capability: id: meta_factory_v1 class: muscle skills: - create_factory - mutate_factory - analyze_factory_effectiveness contracts: - intent_type: factory_creation skill_family: meta_factory input_schema: - target_domain: str # What the factory should create - mutation_strategies: list[str] - evaluation_criteria: dict output_schema: - factory_id: str - template_path: str ``` ### 5.6.2: Factory Specification ```python @dataclass class FactorySpec: """Specification for a new factory.""" factory_id: str target_domain: str # e.g., "prompts", "contracts", "workflows" mutation_strategies: list[MutationStrategy] evaluation_criteria: dict template_schema: dict variant_schema: dict ``` ### 5.6.3: Factory Creation Skill ```python def create_factory( inputs: dict, context: dict ) -> dict: """Create a new factory capability. Steps: 1. Analyze target domain (what should factory create?) 2. Design mutation strategies (how to vary outputs?) 3. Generate factory template.yaml 4. Generate factory run.py (using ImplementationGenerator) 5. Register factory in capabilities/ 6. Return factory_id """ ``` ### 5.6.4: Factory Evolution ``` Meta-Factory monitors factory effectiveness ↓ Identify underperforming factories ↓ Generate factory variants: - New mutation strategies - Different evaluation criteria - Modified template schemas ↓ Test factory variants in parallel ↓ Promote better-performing factory ``` ## Example: Creating a Workflow Factory ```python # Request to meta_factory { "intent_type": "factory_creation", "payload": { "target_domain": "workflows", "mutation_strategies": [ "add_step", "remove_step", "reorder_steps", "parallelize_steps", "add_checkpoint" ], "evaluation_criteria": { "success_rate_weight": 0.5, "latency_weight": 0.3, "cost_weight": 0.2 } } } # Output: workflow_factory created { "factory_id": "workflow_factory_v1", "template_path": "capabilities/_muscle/workflow_factory/template.yaml", "status": "ready" } ``` ## Deliverables - [ ] `capabilities/_muscle/meta_factory/` - Meta-factory capability - [ ] `create_factory` skill - Generate new factory - [ ] `mutate_factory` skill - Evolve existing factory - [ ] `analyze_factory_effectiveness` skill - Track factory performance - [ ] `FactorySpec` dataclass - Factory specification - [ ] Factory template generation - [ ] Factory implementation generation - [ ] Integration with LineageTracker ## Factory Evolution Metrics | Metric | Description | |--------|-------------| | Variant success rate | % of variants that get promoted | | Mean championship score | Average score of factory's variants | | Mutation diversity | Variety of mutation strategies used | | Domain coverage | Range of problems factory addresses | ## Success Criteria - [ ] Can create new factory for any domain - [ ] New factory generates valid variants - [ ] Factory variants compete in championships - [ ] Factories can be mutated and improved - [ ] Meta-factory can create 2+ new factory types ## Dependencies - #64 (Factory Learning) - analytics for factory effectiveness - #67 (Lineage Tracking) - track factory genealogy ## Estimated Duration 2 weeks ## Related - Parent: #62 (Phase 5 Meta) - Uses: `capabilities/_shared/base.py` (MutationRegistry)
Mark closed this issue 2026-04-02 16:54:38 +00:00
Author
Owner

✅ Implementation Complete

Commit: 3736dfb

Components Delivered:

  • capabilities/_muscle/meta_factory/ - Meta-Factory capability with 3 skills
  • evolution/lineage_tracker.py - Genealogy tracking
  • evolution/trait_extractor.py - Trait extraction from AST
  • evolution/capability_fusion.py - Capability fusion with 3 strategies
  • evolution/factory_analytics.py - Factory analytics

Tests: 845 passing (804 unit + 41 integration)

Key Features:

  • create_factory: Generate new factory types from domain specs
  • mutate_factory: Evolve existing factories with new strategies
  • analyze_factory_effectiveness: Query FactoryAnalytics for insights
  • Human approval gates for new factory creations
  • Lineage integration tracks factory evolution

API Endpoints: /v1/lineage/* for genealogy queries

✅ **Implementation Complete** **Commit:** 3736dfb **Components Delivered:** - `capabilities/_muscle/meta_factory/` - Meta-Factory capability with 3 skills - `evolution/lineage_tracker.py` - Genealogy tracking - `evolution/trait_extractor.py` - Trait extraction from AST - `evolution/capability_fusion.py` - Capability fusion with 3 strategies - `evolution/factory_analytics.py` - Factory analytics **Tests:** 845 passing (804 unit + 41 integration) **Key Features:** - `create_factory`: Generate new factory types from domain specs - `mutate_factory`: Evolve existing factories with new strategies - `analyze_factory_effectiveness`: Query FactoryAnalytics for insights - Human approval gates for new factory creations - Lineage integration tracks factory evolution **API Endpoints:** `/v1/lineage/*` for genealogy queries
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#68
No description provided.