fix: Simplify API - use components directly instead of top-level engine

KAIROSTemporalEngine is used internally by Master/Emissary.
Use _engine_components dict to track master, emissary, sync, witnessing, memory.
Update health_check, process_input, get_coherence, reset_engine to use components.
This commit is contained in:
2026-02-19 21:03:38 +00:00
parent 004f8bde7e
commit 9dbcb3f061
+49 -30
View File
@@ -52,13 +52,14 @@ logger.add(sys.stderr, format="{time} | {level} | {message}")
# Global engine instance # Global engine instance
engine: Optional[KAIROSTemporalEngine] = None engine: Optional[KAIROSTemporalEngine] = None
_engine_components: Optional[Dict[str, Any]] = None
async def health_check() -> Dict[str, Any]: async def health_check() -> Dict[str, Any]:
"""Return system health status.""" """Return system health status."""
global engine global _engine_components
if engine is None: if _engine_components is None:
return { return {
"status": "not_ready", "status": "not_ready",
"timestamp": datetime.utcnow().isoformat(), "timestamp": datetime.utcnow().isoformat(),
@@ -69,28 +70,32 @@ async def health_check() -> Dict[str, Any]:
"message": "Engine not initialized", "message": "Engine not initialized",
} }
master = _engine_components.get("master")
emissary = _engine_components.get("emissary")
sync = _engine_components.get("sync")
# Get current coherence values # Get current coherence values
master_coherence = engine.master.get_coherence() if engine.master else None master_coherence = master.get_coherence() if master else None
emissary_coherence = engine.emissary.get_coherence() if engine.emissary else None emissary_coherence = emissary.get_coherence() if emissary else None
sync_coherence = engine.sync.get_coherence() if engine.sync else None sync_coherence = sync.get_coherence() if sync else None
return { return {
"status": "ready", "status": "ready",
"timestamp": datetime.utcnow().isoformat(), "timestamp": datetime.utcnow().isoformat(),
"coherence": float(engine.coherence) if engine.coherence else None, "coherence": float(sync_coherence) if sync_coherence else None,
"master_coherence": float(master_coherence) if master_coherence else None, "master_coherence": float(master_coherence) if master_coherence else None,
"emissary_coherence": float(emissary_coherence) if emissary_coherence else None, "emissary_coherence": float(emissary_coherence) if emissary_coherence else None,
"sync_coherence": float(sync_coherence) if sync_coherence else None, "sync_coherence": float(sync_coherence) if sync_coherence else None,
"sync_aligned": bool(engine.sync_aligned) if hasattr(engine, 'sync_aligned') else None, "sync_aligned": bool(sync.is_aligned()) if sync else None,
"version": "0.1.0-alpha", "version": "0.1.0-alpha",
} }
async def process_input(input_data: Dict[str, Any]) -> Dict[str, Any]: async def process_input(input_data: Dict[str, Any]) -> Dict[str, Any]:
"""Process input through the KAIROS engine.""" """Process input through the KAIROS engine."""
global engine global _engine_components
if engine is None: if _engine_components is None:
return {"error": "Engine not initialized"} return {"error": "Engine not initialized"}
input_type = input_data.get("type", "text") input_type = input_data.get("type", "text")
@@ -98,20 +103,23 @@ async def process_input(input_data: Dict[str, Any]) -> Dict[str, Any]:
logger.info(f"Processing input: type={input_type}, content={content[:100]}...") logger.info(f"Processing input: type={input_type}, content={content[:100]}...")
master = _engine_components.get("master")
emissary = _engine_components.get("emissary")
# Process based on input type # Process based on input type
if input_type == "text": if input_type == "text":
# Convert text to temporal input # Convert text to temporal input
# Simple encoding: use ord values as phase signals # Simple encoding: use ord values as phase signals
signals = np.array([ord(c) / 127.0 for c in content[:512]], dtype=np.float32) signals = np.array([ord(c) / 127.0 for c in content[:512]], dtype=np.float32)
result = await engine.process(signals) result = await master.process(signals)
elif input_type == "tokens": elif input_type == "tokens":
# Direct token input (for LLM integration) # Direct token input (for LLM integration)
tokens = input_data.get("tokens", []) tokens = input_data.get("tokens", [])
result = await engine.process(np.array(tokens, dtype=np.float32)) result = await master.process(np.array(tokens, dtype=np.float32))
elif input_type == "phase": elif input_type == "phase":
# Direct phase input # Direct phase input
phases = input_data.get("phases", []) phases = input_data.get("phases", [])
result = await engine.process_phase(np.array(phases, dtype=np.float32)) result = await master.process_phase(np.array(phases, dtype=np.float32))
else: else:
return {"error": f"Unknown input type: {input_type}"} return {"error": f"Unknown input type: {input_type}"}
@@ -126,24 +134,28 @@ async def process_input(input_data: Dict[str, Any]) -> Dict[str, Any]:
async def get_coherence() -> Dict[str, Any]: async def get_coherence() -> Dict[str, Any]:
"""Get current coherence metrics.""" """Get current coherence metrics."""
global engine global _engine_components
if engine is None: if _engine_components is None:
return {"error": "Engine not initialized"} return {"error": "Engine not initialized"}
master = _engine_components.get("master")
emissary = _engine_components.get("emissary")
sync = _engine_components.get("sync")
return { return {
"coherence": float(engine.coherence) if engine.coherence else None, "coherence": float(sync.get_coherence()) if sync else None,
"master": { "master": {
"coherence": float(engine.master.get_coherence()) if engine.master else None, "coherence": float(master.get_coherence()) if master else None,
"phase": engine.master.phase.history[-100:].tolist() if hasattr(engine.master, 'phase') and len(engine.master.phase.history) > 0 else None, "phase": master._engine._phases[-100:] if master and hasattr(master, '_engine') else None,
}, },
"emissary": { "emissary": {
"coherence": float(engine.emissary.get_coherence()) if engine.emissary else None, "coherence": float(emissary.get_coherence()) if emissary else None,
"phase": engine.emissary.phase.history[-100:].tolist() if hasattr(engine.emissary, 'phase') and len(engine.emissary.phase.history) > 0 else None, "phase": emissary._engine._phases[-100:] if emissary and hasattr(emissary, '_engine') else None,
}, },
"sync": { "sync": {
"coherence": float(engine.sync.get_coherence()) if engine.sync else None, "coherence": float(sync.get_coherence()) if sync else None,
"aligned": engine.sync_aligned if hasattr(engine, 'sync_aligned') else None, "aligned": sync.is_aligned() if sync else None,
}, },
"timestamp": datetime.utcnow().isoformat(), "timestamp": datetime.utcnow().isoformat(),
} }
@@ -151,7 +163,7 @@ async def get_coherence() -> Dict[str, Any]:
async def reset_engine() -> Dict[str, Any]: async def reset_engine() -> Dict[str, Any]:
"""Reset the KAIROS engine to initial state.""" """Reset the KAIROS engine to initial state."""
global engine global _engine_components
init_engine() init_engine()
@@ -231,14 +243,21 @@ def init_engine(
attention_threshold=coherence_threshold, attention_threshold=coherence_threshold,
) )
# Create main engine # Create main engine wrapper
engine = KAIROSTemporalEngine( # Note: KAIROSTemporalEngine is used internally by Master/Emissary
master=master, # We use the Master/Emissary/Sync combination as our top-level engine
emissary=emissary, engine = None # Will be set on first request
sync_layer=sync_layer,
witnessing_layer=witnessing_layer, # Store engine components globally for health checks
temporal_memory=temporal_memory, global _engine_components
) _engine_components = {
"master": master,
"emissary": emissary,
"sync": sync_layer,
"witnessing": witnessing_layer,
"memory": temporal_memory,
"coherence_threshold": coherence_threshold,
}
logger.info("BECOMINGONE Engine initialized successfully") logger.info("BECOMINGONE Engine initialized successfully")