Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 47 additions & 16 deletions backend/unified_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,26 @@ def get_knowledge_stats() -> Dict[str, Any]:
}
}

def is_consciousness_bootstrap_complete(cognitive_manager) -> bool:
"""
Check if consciousness bootstrap has already been completed.

Args:
cognitive_manager: The cognitive manager instance with consciousness_engine

Returns:
bool: True if bootstrap is complete, False otherwise
"""
# Check if cognitive_manager and its consciousness_engine exist and are not None
if not cognitive_manager or not hasattr(cognitive_manager, 'consciousness_engine'):
return False

ce = cognitive_manager.consciousness_engine
if not ce or not hasattr(ce, "current_state") or not hasattr(ce.current_state, "phenomenal_experience"):
return False

return ce.current_state.phenomenal_experience.get("bootstrap_complete", False)

async def initialize_core_services():
"""Initialize core services with proper error handling."""
global godelos_integration, websocket_manager, enhanced_websocket_manager, unified_consciousness_engine, tool_based_llm, cognitive_manager, transparency_engine
Expand Down Expand Up @@ -438,9 +458,13 @@ async def initialize_core_services():
# Bootstrap consciousness after initialization
if hasattr(cognitive_manager, 'consciousness_engine') and cognitive_manager.consciousness_engine:
try:
logger.info("πŸŒ… Bootstrapping consciousness in cognitive manager...")
await cognitive_manager.consciousness_engine.bootstrap_consciousness()
logger.info("βœ… Consciousness engine bootstrapped successfully")
# Check if bootstrap has already completed
if not is_consciousness_bootstrap_complete(cognitive_manager):
logger.info("πŸŒ… Bootstrapping consciousness in cognitive manager...")
await cognitive_manager.consciousness_engine.bootstrap_consciousness()
logger.info("βœ… Consciousness engine bootstrapped successfully")
else:
logger.info("🟑 Consciousness engine bootstrap already completed; skipping duplicate call.")
except Exception as bootstrap_error:
logger.warning(f"⚠️ Consciousness bootstrap warning (non-fatal): {bootstrap_error}")

Expand Down Expand Up @@ -479,22 +503,29 @@ async def initialize_core_services():
logger.info("🧠 Unified consciousness loop started")

# Bootstrap consciousness from unconscious state to operational awareness
logger.info("πŸŒ… Initiating consciousness bootstrap sequence...")
# (Only if not already bootstrapped in the cognitive manager section above)
logger.info("πŸŒ… Checking consciousness bootstrap state...")
try:
bootstrap_state = await unified_consciousness_engine.consciousness_state_injector.capture_current_state()
# Update unified consciousness state from bootstrap
if hasattr(bootstrap_state, 'awareness_level') and bootstrap_state.awareness_level < 0.5:
# System needs bootstrapping
logger.info("Consciousness needs bootstrap - initiating awakening sequence")
# Note: UnifiedConsciousnessEngine doesn't have bootstrap_consciousness directly
# We'll need to check if cognitive_manager has it
if cognitive_manager and hasattr(cognitive_manager, 'consciousness_engine'):
await cognitive_manager.consciousness_engine.bootstrap_consciousness()
logger.info("βœ… Consciousness bootstrapped successfully via cognitive manager")
# Check if bootstrap was already completed
if not is_consciousness_bootstrap_complete(cognitive_manager):
# Check if system needs bootstrapping based on awareness level
state_injector = unified_consciousness_engine.cognitive_state_injector
if state_injector:
bootstrap_state = await state_injector.capture_current_state()
if hasattr(bootstrap_state, 'awareness_level') and bootstrap_state.awareness_level < 0.5:
# System needs bootstrapping
logger.info("Consciousness needs bootstrap - initiating awakening sequence")
if cognitive_manager and hasattr(cognitive_manager, 'consciousness_engine'):
await cognitive_manager.consciousness_engine.bootstrap_consciousness()
logger.info("βœ… Consciousness bootstrapped successfully via cognitive manager")
else:
logger.warning("⚠️ Cognitive manager not available for bootstrap, consciousness will self-organize")
else:
logger.info(f"Consciousness already active (level: {bootstrap_state.awareness_level:.2f})")
else:
logger.warning("⚠️ Cognitive manager not available for bootstrap, consciousness will self-organize")
logger.warning("⚠️ Cognitive state injector not available, skipping awareness level check")
else:
logger.info(f"Consciousness already active (level: {bootstrap_state.awareness_level:.2f})")
logger.info("🟑 Consciousness bootstrap already completed; skipping duplicate check.")
except Exception as bootstrap_error:
logger.warning(f"⚠️ Consciousness bootstrap encountered issue (non-fatal): {bootstrap_error}")
logger.info("Consciousness will self-organize through normal operation")
Expand Down
19 changes: 7 additions & 12 deletions demo_consciousness.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
# Add project to path
sys.path.insert(0, '/workspace/GodelOS')

# Import all required modules at the top of the file
from backend.core.consciousness_engine import ConsciousnessEngine
from backend.core.unified_consciousness_engine import UnifiedConsciousnessEngine
from backend.goal_management_system import GoalManagementSystem
from backend.core.metacognitive_monitor import MetaCognitiveMonitor
from backend.core.knowledge_graph_evolution import KnowledgeGraphEvolution

print("=" * 80)
print("🧠 GODELSOS CONSCIOUSNESS INTEGRATION DEMO")
print("=" * 80)
Expand All @@ -32,8 +39,6 @@ async def demo_1_bootstrap():
print("β””" + "─" * 78 + "β”˜")
print()

from backend.core.consciousness_engine import ConsciousnessEngine

print("Creating consciousness engine...")
engine = ConsciousnessEngine()

Expand Down Expand Up @@ -72,8 +77,6 @@ async def demo_2_real_computation():
print("β””" + "─" * 78 + "β”˜")
print()

from backend.core.unified_consciousness_engine import UnifiedConsciousnessEngine

print("Creating unified consciousness engine...")
engine = UnifiedConsciousnessEngine()
await engine.initialize_components()
Expand Down Expand Up @@ -108,8 +111,6 @@ async def demo_3_conscious_query():
print("β””" + "─" * 78 + "β”˜")
print()

from backend.core.unified_consciousness_engine import UnifiedConsciousnessEngine

print("Setting up consciousness engine for query processing...")
engine = UnifiedConsciousnessEngine()
await engine.initialize_components()
Expand Down Expand Up @@ -155,8 +156,6 @@ async def demo_4_goals_phenomenal():
print("β””" + "─" * 78 + "β”˜")
print()

from backend.goal_management_system import GoalManagementSystem

print("Creating goal management system...")
goal_system = GoalManagementSystem()

Expand Down Expand Up @@ -206,8 +205,6 @@ async def demo_5_metacognition_depth():
print("β””" + "─" * 78 + "β”˜")
print()

from backend.core.metacognitive_monitor import MetaCognitiveMonitor

print("Creating metacognitive monitor...")
monitor = MetaCognitiveMonitor()

Expand Down Expand Up @@ -248,8 +245,6 @@ async def demo_6_knowledge_graph_insights():
print("β””" + "─" * 78 + "β”˜")
print()

from backend.core.knowledge_graph_evolution import KnowledgeGraphEvolution

print("Creating knowledge graph...")
kg = KnowledgeGraphEvolution()

Expand Down