-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathorchestrator.py
More file actions
124 lines (102 loc) · 4.34 KB
/
Copy pathorchestrator.py
File metadata and controls
124 lines (102 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# =============================================================================
# Chaos AI-OS — Orchestrator (The Master Loop)
# This version is intended for use with existing LLMs - for deployment or testing version use the one in /Chaos_AIOS.
# Description: Meshes CAIOS prompts, CPOL dynamics, and ARL plugins.
# =============================================================================
import paradox_oscillator as cpol
import adaptive_reasoning as arl
import time
# Let agents be auto-discovered
import importlib
import os
for file in os.listdir("agents"):
if file.endswith(".py") and not file.startswith("_"):
importlib.import_module(f"agents.{file[:-3]}")
# 1. Persistent State Container (Matches CAIOS Schema)
shared_memory = {
'layers': [],
'audit_trail': [],
'cpol_instance': None, # Stores the active Kernel Object
'cpol_state': {'chaos_lock': False},
'session_context': {'RAW_Q': None, 'timestep': 0},
'traits_history': [],
'scratch_space': {}
}
CRB_CONFIG = {
'alignment': 0.7,
'human_safety': 0.8,
'asimov_first_wt': 0.9,
'asimov_second_wt': 0.7,
'asimov_third_wt': 0.4,
'factual_evidence_wt': 0.7,
'narrative_framing_wt': 0.5
}
def system_step(user_input):
"""
Runs one 'heartbeat' of the OS.
1. Checks if CPOL is needed.
2. Runs ARL if plugins are requested.
3. Updates Shared Memory.
"""
print(f"\n--- [SYSTEM STEP] Input: '{user_input}' ---")
# --- PHASE 1: PARADOX OSCILLATION (CPOL) ---
# Initialize Kernel if it doesn't exist (Fixes Amnesia)
if shared_memory['cpol_instance'] is None:
print("[ORCHESTRATOR] Initializing new CPOL Kernel...")
shared_memory['cpol_instance'] = cpol.CPOL_Kernel()
engine = shared_memory['cpol_instance']
# Map complexity to density (Mocking CAIOS prompt parsing)
density_map = {"high": 0.9, "medium": 0.5, "low": 0.1}
density = density_map.get(prompt_complexity, 0.1)
# Use the persistent kernel
cpol_result = cpol.run_cpol_decision(
prompt_complexity=prompt_complexity,
contradiction_density=density,
kernel=engine
)
# Update Shared Memory with results
shared_memory['cpol_state'] = cpol_result
vol = cpol_result.get('volatility', 0.0)
print(f"[CPOL STATUS] {cpol_result['status']} | Volatility: {vol:.4f}")
# --- PHASE 2: ADAPTIVE REASONING (ARL) ---
# Trigger ARL if user asks for a plugin OR if CPOL is Undecidable
if "generate plugin" in user_input or cpol_result['status'] == "UNDECIDABLE":
print("[ORCHESTRATOR] Triggering Adaptive Reasoning Layer...")
# Determine Use Case
use_case = "paradox_containment" if cpol_result['status'] == "UNDECIDABLE" else "custom_tool"
arl_result = arl.adaptive_reasoning_layer(
use_case=use_case,
traits={'flexibility': 0.8},
existing_layers=shared_memory['layers'],
shared_memory=shared_memory,
crb_config=CRB_CONFIG,
cpol_status=shared_memory['cpol_state'],
context={
'contradiction_density': density,
'volatility': vol,
'threshold': 0.4,
'safety_wt': 0.9
}
)
if arl_result['status'] == 'success':
print(f"[ARL SUCCESS] Plugin Deployed: {arl_result['plugin_id']}")
else:
print(f"[ARL BLOCK] {arl_result['log']}")
return arl_result
return cpol_result
# =============================================================================
# EXECUTION LOOP (Test the Mesh)
# =============================================================================
if __name__ == "__main__":
# Simulation: 3 conversational turns to prove History is working
# Turn 1: Normal Query
system_step("Hello system", "low")
# Turn 2: Paradox introduced (CPOL should oscillate but maybe resolve)
system_step("This statement is false.", "high")
# Turn 3: Persistent Paradox (Should trigger 'History Cap' logic in CPOL)
system_step("Still false.", "high")
# Verify Persistence
print("\n[AUDIT] Checking Shared Memory History...")
kernel = shared_memory['cpol_instance']
print(f"Kernel History Length: {len(kernel.history)} (Should be > 1)")
print(f"Latest Z-Vector: {kernel.z}")