Skip to content
Merged
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
7 changes: 4 additions & 3 deletions backend/core/cognitive_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
37 changes: 37 additions & 0 deletions backend/core/consciousness_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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...")

Expand Down
4 changes: 2 additions & 2 deletions backend/core/knowledge_graph_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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

Expand Down
15 changes: 11 additions & 4 deletions backend/core/metacognitive_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', [])}"
)
Expand Down
12 changes: 8 additions & 4 deletions backend/core/unified_consciousness_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +576 to +583
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check if len(depth_history) > 0: on line 576 is redundant. Since the outer condition on line 574 ensures len(self.consciousness_history) > 5, and line 575 creates depth_history from the last 5 elements with self.consciousness_history[-5:], depth_history will always contain exactly 5 elements at this point. The additional check can be removed.

Suggested change
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
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

Copilot uses AI. Check for mistakes.
else:
current_state.recursive_awareness["strange_loop_stability"] = 0.5

Expand Down
3 changes: 1 addition & 2 deletions backend/goal_management_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
10 changes: 2 additions & 8 deletions backend/unified_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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": {
Expand Down
6 changes: 4 additions & 2 deletions demo_consciousness.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion inline_test.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 3 additions & 1 deletion quick_verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
Loading