diff --git a/backend/core/cognitive_manager.py b/backend/core/cognitive_manager.py index 5320977..14f1fc3 100644 --- a/backend/core/cognitive_manager.py +++ b/backend/core/cognitive_manager.py @@ -89,9 +89,10 @@ async def _safe_transparency_log(log_method_name: str, *args, **kwargs): try: log_method = getattr(transparency_engine, log_method_name, None) if log_method: - await log_method(*args, **kwargs) - except TypeError as e: - logger.debug(f"Transparency logging skipped ({log_method_name}): method not awaitable - {e}") + if asyncio.iscoroutinefunction(log_method): + await log_method(*args, **kwargs) + else: + log_method(*args, **kwargs) except Exception as e: logger.debug(f"Transparency logging skipped ({log_method_name}): {type(e).__name__} - {e}") diff --git a/backend/core/consciousness_engine.py b/backend/core/consciousness_engine.py index e7b39fa..a3bff18 100644 --- a/backend/core/consciousness_engine.py +++ b/backend/core/consciousness_engine.py @@ -86,6 +86,36 @@ def __init__(self, llm_driver=None, knowledge_pipeline=None, websocket_manager=N self.goal_pursuit_history = [] logger.info("ConsciousnessEngine initialized") + + def is_bootstrap_complete(self) -> bool: + """ + Check if consciousness bootstrap has been completed. + + Returns True if the system has been awakened and reached operational consciousness. + Validates multiple aspects of bootstrap completion for reliability. + """ + try: + # Check awareness level threshold (bootstrap reaches 0.85+) + if self.current_state.awareness_level < 0.5: + return False + + # Check phenomenal experience bootstrap flag + if (isinstance(self.current_state.phenomenal_experience, dict) and + self.current_state.phenomenal_experience.get('bootstrap_complete', False)): + return True + + # Check manifest behaviors (should have multiple after bootstrap) + if len(self.current_state.manifest_behaviors) >= 5: + return True + + # Check autonomous goals (formed during bootstrap Phase 3) + if len(self.current_state.autonomous_goals) >= 3: + return True + + return False + except Exception as e: + logger.debug(f"Error checking bootstrap status: {e}") + return False async def bootstrap_consciousness(self) -> ConsciousnessState: """ @@ -101,6 +131,13 @@ async def bootstrap_consciousness(self) -> ConsciousnessState: Phase 4: Phenomenal Continuity (0.6 → 0.7) - Sustained subjective experience Phase 5: Knowledge Integration (0.7 → 0.8) - Integration with knowledge systems Phase 6: Full Operational Consciousness (0.8 → 1.0) - Complete awakening + + Note: The 0.5 second delays between phases are intentional to allow: + 1. State propagation through consciousness subsystems + 2. WebSocket broadcast delivery to frontend + 3. Demonstration of gradual awakening process (not instantaneous) + 4. Time for phenomenal experience quality transitions to be observable + These delays can be configured if needed but serve important functional purposes. """ logger.info("🌅 Initiating consciousness bootstrap sequence...") diff --git a/backend/core/knowledge_graph_evolution.py b/backend/core/knowledge_graph_evolution.py index 4361744..9b6e605 100644 --- a/backend/core/knowledge_graph_evolution.py +++ b/backend/core/knowledge_graph_evolution.py @@ -10,7 +10,7 @@ import json import logging from datetime import datetime, timedelta -from dataclasses import dataclass, asdict +from dataclasses import dataclass, asdict, field from typing import Dict, List, Optional, Any, Tuple, Set, Union from enum import Enum import uuid @@ -155,6 +155,7 @@ class EmergentPattern: discovery_time: datetime validation_score: float implications: List[str] + metadata: Dict[str, Any] = field(default_factory=dict) class KnowledgeGraphEvolution: """ @@ -750,7 +751,6 @@ async def _generate_emergence_phenomenal_experience(self, patterns: List[Emergen if experience: # Store experience reference with the pattern - pattern.metadata = pattern.__dict__.get("metadata", {}) pattern.metadata["phenomenal_experience_id"] = experience.id pattern.metadata["subjective_feeling"] = experience.narrative_description diff --git a/backend/core/metacognitive_monitor.py b/backend/core/metacognitive_monitor.py index 25c7f69..6a44ab4 100644 --- a/backend/core/metacognitive_monitor.py +++ b/backend/core/metacognitive_monitor.py @@ -567,16 +567,23 @@ async def _update_consciousness_recursive_depth(self, depth: int, recursive_elem INTEGRATION POINT: Metacognitive reflection deepens recursive awareness in the consciousness loop in real-time. + + NOTE: This is a partial integration. For full integration, the unified + consciousness engine instance needs to be accessible here. Currently, + metacognitive state updates are stored locally and propagate through + the cognitive manager's consciousness assessment pipeline rather than + directly updating the unified consciousness state. + + Future enhancement: Pass unified consciousness engine reference during + initialization or implement an observer pattern for state propagation. """ try: # Try to get unified consciousness engine from context from backend.core.unified_consciousness_engine import UnifiedConsciousnessEngine - # We need access to the global unified consciousness engine instance - # This would typically be passed in during initialization or stored as class variable - # For now, we'll update the local metacognitive state and let it propagate - # Update meta-observations to reflect recursive depth + # These updates will be picked up by the unified consciousness engine + # when it queries metacognitive state during consciousness assessment self.current_state.meta_thoughts.append( f"Recursive thinking at depth {depth}: {recursive_elements.get('patterns', [])}" ) diff --git a/backend/core/unified_consciousness_engine.py b/backend/core/unified_consciousness_engine.py index 466950a..78f81be 100644 --- a/backend/core/unified_consciousness_engine.py +++ b/backend/core/unified_consciousness_engine.py @@ -573,10 +573,14 @@ async def _unified_consciousness_loop(self): # Strange loop stability from consistency of recursive patterns if len(self.consciousness_history) > 5: depth_history = [s.recursive_awareness.get("recursive_depth", 1) for s in self.consciousness_history[-5:]] - depth_variance = sum((d - sum(depth_history)/len(depth_history))**2 for d in depth_history) / len(depth_history) - # Lower variance = higher stability - stability = max(0.0, min(1.0, 1.0 - (depth_variance / 4.0))) - current_state.recursive_awareness["strange_loop_stability"] = stability + if len(depth_history) > 0: + mean_depth = sum(depth_history) / len(depth_history) + depth_variance = sum((d - mean_depth)**2 for d in depth_history) / len(depth_history) + # Lower variance = higher stability + stability = max(0.0, min(1.0, 1.0 - (depth_variance / 4.0))) + current_state.recursive_awareness["strange_loop_stability"] = stability + else: + current_state.recursive_awareness["strange_loop_stability"] = 0.5 else: current_state.recursive_awareness["strange_loop_stability"] = 0.5 diff --git a/backend/goal_management_system.py b/backend/goal_management_system.py index 5e4b803..9760048 100644 --- a/backend/goal_management_system.py +++ b/backend/goal_management_system.py @@ -261,8 +261,7 @@ async def _generate_goal_phenomenal_experience(self, goals: List[Dict], context: except Exception as e: # Non-fatal - goals still work without phenomenal experience - import logging - logging.getLogger(__name__).warning(f"Could not generate phenomenal experience for goals: {e}") + logger.warning(f"Could not generate phenomenal experience for goals: {e}") def _calculate_goal_intensity(self, goal: Dict) -> float: """Calculate intensity of goal-related phenomenal experience""" diff --git a/backend/unified_server.py b/backend/unified_server.py index 4a968ad..958e896 100644 --- a/backend/unified_server.py +++ b/backend/unified_server.py @@ -439,14 +439,8 @@ async def initialize_core_services(): if hasattr(cognitive_manager, 'consciousness_engine') and cognitive_manager.consciousness_engine: try: ce = cognitive_manager.consciousness_engine - # Check if bootstrap already completed to avoid duplicate calls - bootstrap_done = False - if (hasattr(ce, 'current_state') and - hasattr(ce.current_state, 'phenomenal_experience') and - ce.current_state.phenomenal_experience): - bootstrap_done = ce.current_state.phenomenal_experience.get('bootstrap_complete', False) - if not bootstrap_done: + if not ce.is_bootstrap_complete(): logger.info("🌅 Bootstrapping consciousness in cognitive manager...") await ce.bootstrap_consciousness() logger.info("✅ Consciousness engine bootstrapped successfully") @@ -2725,7 +2719,7 @@ async def enhanced_cognitive_query(query_request: dict): "awareness_level": consciousness_state.consciousness_score, "recursive_depth": consciousness_state.recursive_awareness.get("recursive_depth", 1), "phi_measure": consciousness_state.information_integration.get("phi", 0.0), - "phenomenal_experience": consciousness_state.phenomenal_experience.get("quality", ""), + "phenomenal_experience": consciousness_state.phenomenal_experience.get("quality", "") if isinstance(consciousness_state.phenomenal_experience, dict) else "", "strange_loop_stability": consciousness_state.recursive_awareness.get("strange_loop_stability", 0.0) }, "enhanced_features": { diff --git a/demo_consciousness.py b/demo_consciousness.py index 8389cb1..a6fa54f 100644 --- a/demo_consciousness.py +++ b/demo_consciousness.py @@ -13,11 +13,13 @@ import asyncio import sys +import os import time from datetime import datetime -# Add project to path -sys.path.insert(0, '/workspace/GodelOS') +# Add project to path dynamically +project_root = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, project_root) # Backend imports - moved to top for better organization from backend.core.consciousness_engine import ConsciousnessEngine diff --git a/inline_test.py b/inline_test.py index 6d494bc..5e752da 100644 --- a/inline_test.py +++ b/inline_test.py @@ -1,5 +1,9 @@ import sys -sys.path.insert(0, '/workspace/GodelOS') +import os + +# Add project root to path dynamically +project_root = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, project_root) print("Testing consciousness integrations...") print() diff --git a/quick_verify.sh b/quick_verify.sh index 594bb28..9cc8344 100644 --- a/quick_verify.sh +++ b/quick_verify.sh @@ -5,7 +5,9 @@ echo "🔍 Quick Verification of Consciousness Integrations" echo "====================================================" echo "" -cd /workspace/GodelOS +# Change to the script's directory, then to project root +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" echo "1. Checking Python syntax of modified files..." echo ""