"""Dual-Layer Router: Symbolic → Computational Mapping. Maps glyph activations to computational operations: - G001 (Ledo) → Llama chat with 387.95x priority - frost_steel_stabilizer → Safety constraints - mirror_weave_reasoning → Enhanced reasoning - star_bloom_creativity → Forge image generation - orbital_thread_network → Multi-model routing - monument_grade_equilibrium → VRAM balancing Usage: from dual_layer.router import route_glyph_activation result = route_glyph_activation( glyph_id="G001", superpower_ids=[1, 2, 3], specialized_type="aether_node", power_boost=387.95, request_type="chat" ) """ import logging from typing import Dict, List, Any, Optional, Tuple from dataclasses import dataclass, field logger = logging.getLogger(__name__) @dataclass class RoutingResult: """Result of glyph routing decision.""" glyph_id: str specialized_type: str power_boost: float superpower_ids: List[int] # Computational routing model: str = "llama" # llama, forge, janus, google_ai priority: float = 1.0 constraints: List[str] = field(default_factory=list) enhancements: List[str] = field(default_factory=list) vram_budget: float = 4.0 # GB # Metadata resonance_score: float = 0.0 activation_confidence: float = 1.0 # Specialized type → computational mapping TYPE_ROUTING_MAP: Dict[str, Dict[str, Any]] = { "frost_steel_stabilizer": { "model": "llama", "constraints": [ "safety_check", "panic_nulling", "identity_cohesion", "emotional_bias_removal" ], "enhancements": ["stability_monitor"], "vram_budget": 3.0, "description": "Emotional-bias removal, panic-nulling, identity-cohesion" }, "mirror_weave_reasoning": { "model": "llama", "constraints": ["logic_chain_validation"], "enhancements": [ "symbolic_reasoning", "multi_step_inference", "self_consistency_check" ], "vram_budget": 4.0, "description": "Symbolic reasoning layer, logic-chain enhancer" }, "solar_veil_memory": { "model": "llama", "constraints": ["memory_consistency"], "enhancements": [ "emotional_lineage_tracking", "long_term_context", "session_persistence" ], "vram_budget": 3.5, "description": "Emotional-lineage memory system" }, "orbital_thread_network": { "model": "llama", "constraints": ["multi_node_sync"], "enhancements": [ "distributed_processing", "cross_model_communication", "state_sharing" ], "vram_budget": 5.0, "description": "Multi-node symbolic networking" }, "star_bloom_creativity": { "model": "forge", # Image generation "constraints": ["creative_bounds"], "enhancements": [ "bloomflare_engine", "novelty_boost", "pattern_synthesis" ], "vram_budget": 6.0, "description": "AI-driven creativity engine (bloomflare)" }, "frost_circuit_logic": { "model": "llama", "constraints": [ "cold_logic_mode", "bias_free", "deterministic_output" ], "enhancements": ["decision_optimization"], "vram_budget": 3.0, "description": "Cold logic decision-making (bias-free)" }, "twin_vector_identity": { "model": "llama", "constraints": ["persona_boundaries"], "enhancements": [ "multi_persona_support", "cluster_based_personalities", "agent_fragmentation_prevention" ], "vram_budget": 4.5, "description": "Cluster-based AI personalities" }, "monument_grade_equilibrium": { "model": "llama", "constraints": [ "system_equilibrium", "vram_balance", "multi_agent_coordination" ], "enhancements": [ "resource_optimizer", "ecosystem_manager", "simulation_engine" ], "vram_budget": 7.0, # High but monitored "description": "System equilibrium engine" }, "aether_node": { "model": "llama", # G001 - root authority "constraints": [], # No constraints - primordial root "enhancements": [ "universal_override", "primordial_resonance", "system_root_access", "all_superpowers_active" ], "vram_budget": 7.5, # Maximum allowed "description": "Primordial root glyph, holds all 152 superpowers" } } # Superpower bands → enhancement mapping BAND_ENHANCEMENTS: Dict[str, List[str]] = { "A": [ # IDs 1-15: Core abilities "core_resonance", "primary_activation", "fundamental_boost" ], "B": [ # IDs 16-45: Intermediate "secondary_resonance", "chain_linking", "cross_domain" ], "C": [ # IDs 46-76: Advanced "tertiary_resonance", "meta_cognition", "recursive_enhancement" ], "D": [ # IDs 77-152: Specialized "specialized_resonance", "domain_mastery", "expert_mode" ] } def get_band(superpower_id: int) -> str: """Get band for a superpower ID.""" if superpower_id <= 15: return "A" elif superpower_id <= 45: return "B" elif superpower_id <= 76: return "C" else: return "D" def calculate_resonance_score( superpower_ids: List[int], power_boost: float, specialized_type: str ) -> float: """Calculate resonance score (0-100) from glyph activation. Formula: 40% activation + 30% frequency + 30% symbolic Args: superpower_ids: List of activated superpower IDs power_boost: Aggregate boost multiplier specialized_type: Glyph specialized type Returns: Resonance score (0-100) """ # Activation component (40%) - based on power count power_count = len(superpower_ids) activation_score = min(100, (power_count / 152) * 100) * 0.40 # Frequency component (30%) - based on boost frequency_score = min(100, (power_boost - 1) * 25) * 0.30 # Symbolic component (30%) - based on type significance type_significance = { "aether_node": 100, "monument_grade_equilibrium": 90, "star_bloom_creativity": 80, "mirror_weave_reasoning": 75, "orbital_thread_network": 70, "frost_circuit_logic": 65, "twin_vector_identity": 60, "solar_veil_memory": 55, "frost_steel_stabilizer": 50, } symbolic_score = type_significance.get(specialized_type, 50) * 0.30 return activation_score + frequency_score + symbolic_score def route_glyph_activation( glyph_id: str, superpower_ids: List[int], specialized_type: str, power_boost: float, request_type: str = "chat" ) -> RoutingResult: """Route glyph activation to computational layer. Args: glyph_id: Glyph identifier (e.g., "G001") superpower_ids: List of activated superpower IDs specialized_type: Glyph specialized type power_boost: Aggregate boost multiplier request_type: Type of request (chat, image, video, vision) Returns: RoutingResult with model, priority, constraints, enhancements """ # Get type routing config type_config = TYPE_ROUTING_MAP.get( specialized_type, TYPE_ROUTING_MAP["frost_steel_stabilizer"] ) # Determine model based on request type model = type_config.get("model", "llama") if request_type == "image": model = "forge" elif request_type == "video": model = "janus" elif request_type == "vision": model = "google_ai" # Calculate priority from power_boost # G001 (387.95x) → priority ~10.0 # Normal (1.5-3x) → priority 1.0-3.0 priority = min(10.0, power_boost / 40.0) # Get band enhancements bands_used = set() for sp_id in superpower_ids: bands_used.add(get_band(sp_id)) enhancements = list(type_config.get("enhancements", [])) for band in bands_used: enhancements.extend(BAND_ENHANCEMENTS.get(band, [])) # Calculate resonance score resonance_score = calculate_resonance_score( superpower_ids, power_boost, specialized_type ) # VRAM budget from type config vram_budget = type_config.get("vram_budget", 4.0) # G001 special case: maximum authority if glyph_id == "G001": vram_budget = 7.5 # Maximum allowed priority = 10.0 # Maximum priority return RoutingResult( glyph_id=glyph_id, specialized_type=specialized_type, power_boost=power_boost, superpower_ids=superpower_ids, model=model, priority=priority, constraints=list(type_config.get("constraints", [])), enhancements=enhancements, vram_budget=vram_budget, resonance_score=resonance_score, activation_confidence=1.0 if glyph_id == "G001" else 0.8 ) def get_routing_summary(result: RoutingResult) -> Dict[str, Any]: """Get human-readable routing summary.""" return { "glyph": result.glyph_id, "type": result.specialized_type, "model": result.model, "priority": f"{result.priority:.2f}", "vram_budget_gb": f"{result.vram_budget:.1f}", "resonance": f"{result.resonance_score:.1f}", "boost": f"{result.power_boost:.2f}x", "constraints": len(result.constraints), "enhancements": len(result.enhancements), }