-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.py
More file actions
211 lines (160 loc) · 6.45 KB
/
controller.py
File metadata and controls
211 lines (160 loc) · 6.45 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# =========================================================
# CONTROLLER.PY — FULL SYSTEM ORCHESTRATION LAYER (FIXED)
# =========================================================
# ----------------------------
# CORE IMPORTS
# ----------------------------
from system_registry import SystemRegistry
from llm_society_controller import LLMSocietyController
from cognitive_stack import CognitiveStack
import llm_world_controller
from world_model import WorldModel
from learning_world_model import LearningWorldModel
from goal_system import GoalSystem
from scene_graph import SceneGraph
from visual_mapper import VisualMapper
from game_compiler import GameCompiler
from perception_encoder import PerceptionEncoder
from feedback_loop import FeedbackLoop
from live_sync import LiveSync
from abstraction_engine import AbstractionEngine
from experience_buffer import ExperienceBuffer
from strategy_router import StrategyRouter
from cultural_layer import CulturalLayer
from meta_learning_engine import MetaLearningEngine
from learning_feedback_router import LearningFeedbackRouter
from agent_identity import AgentIdentity
from narrative_memory import NarrativeMemory
from self_modifying_core import SelfModifyingCore
from self_test_harness import SelfTestHarness
from safe_evolution_gate import SafeEvolutionGate
from agent_controller import AgentController
# =========================================================
# CONTROLLER
# =========================================================
import random
import world_validator
class Controller:
def __init__(self, registry):
self.registry = registry
# core systems resolved from registry
self.live_sync = registry.get("live_sync")
self.strategy_router = registry.get("strategy_router")
self.abstraction_engine = registry.get("abstraction_engine")
self.powerups = registry.get("powerups")
self.metrics = registry.get("metrics")
self.evolver = registry.get("evolver")
self.updater = registry.get("updater")
self.binding = registry.get("binding")
self.inventory = registry.get("inventory")
self.shape_renderer = registry.get("shape_renderer")
# behavior stack
self.tracker = registry.get("behavior_tracker")
self.feature_extractor = registry.get("feature_extractor")
self.behavior_model = registry.get("behavior_model")
self.behavior_patch = registry.get("behavior_patch")
self.world_spec = {"rules": {}, "entities": [], "powerups": []}
self.patch_queue = []
self.global_step = 0
self.llm_world = registry.get("llm_world")
# =====================================================
# MAIN LIVE CYCLE
# =====================================================
def run_cycle_live(self, goal, input_text):
# -----------------------------
# PERCEPTION
# -----------------------------
perception = {
"goal": goal,
"input": input_text,
"step": self.global_step
}
print("LLM WORLD OBJECT:", self.llm_world)
print("HAS METHOD:", hasattr(self.llm_world, "generate_patch"))
# -----------------------------
# STRATEGY SELECTION
# -----------------------------
strategy = self.strategy_router.select(perception)
# -----------------------------
# MOCK EXECUTION RESULT
# -----------------------------
results = {
"agent_1": random.random()
}
avg_reward = sum(results.values()) / len(results)
# -----------------------------
# BASE SIGNALS
# -----------------------------
signals = {
"reward": avg_reward,
"entropy": 0.3,
"stability": 0.5
}
# -----------------------------
# APPLY POWERUPS
# -----------------------------
signals = self.powerups.modify_signals(signals)
# -----------------------------
# BEHAVIOR ANALYSIS (PLAYER SIDE)
# -----------------------------
actions = self.tracker.get_recent()
features = self.feature_extractor.extract(actions)
style = self.behavior_model.classify(features)
behavior_patch = self.behavior_patch.generate(style)
if behavior_patch:
self.patch_queue.append(("behavior", behavior_patch))
# -----------------------------
# WORLD EVOLUTION (AI SIDE)
# -----------------------------
self.metrics.log({"results": results})
self.llm_world = self.registry.get("llm_world")
self.validator = self.registry.get("world_validator")
if self.global_step % 10 == 0:
metrics = self.metrics.summarize()
behavior = self.tracker.get_recent()
patch = self.llm_world.generate_patch(
self.world_spec,
metrics,
behavior
)
if self.validator.validate(patch):
self.patch_queue.append(("llm", patch))
# -----------------------------
# APPLY PATCHES
# -----------------------------
self.apply_patch_queue()
# -----------------------------
# HUD RESOLUTION
# -----------------------------
active_shapes = self.binding.resolve(self.inventory, signals)
# -----------------------------
# FINAL OUTPUT
# -----------------------------
output = {
"results": results,
"signals": signals,
"style": style,
"hud_shapes": active_shapes,
"world": self.world_spec
}
self.global_step += 1
return output
# =====================================================
# PATCH APPLICATION
# =====================================================
def apply_patch_queue(self):
for source, patch in self.patch_queue:
if not isinstance(patch, dict):
continue
# rules
if "rules" in patch:
self.world_spec["rules"].update(patch["rules"])
# entities
if "entities" in patch:
self.world_spec.setdefault("entities", [])
self.world_spec["entities"] += patch["entities"]
# powerups
if "powerups" in patch:
self.world_spec.setdefault("powerups", [])
self.world_spec["powerups"] += patch["powerups"]
self.patch_queue.clear()