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+
from aether.core import AetherCore, AetherConfig
|
| 13 |
+
from aether.knowledge import KnowledgeGraphEngine
|
| 14 |
+
|
| 15 |
+
logging.basicConfig(level=logging.INFO)
|
| 16 |
+
logger = logging.getLogger("AETHER.Demo")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def demo_knowledge_graph():
|
| 20 |
+
logger.info("\n" + "=" * 60)
|
| 21 |
+
logger.info("DEMO: Knowledge Graph Engine")
|
| 22 |
+
logger.info("=" * 60)
|
| 23 |
+
|
| 24 |
+
kg = KnowledgeGraphEngine(embedding_dim=128, num_relations=20)
|
| 25 |
+
|
| 26 |
+
facts = [
|
| 27 |
+
("AETHER", "is_a", "Agent"),
|
| 28 |
+
("AETHER", "has_capability", "Reasoning"),
|
| 29 |
+
("AETHER", "has_capability", "Learning"),
|
| 30 |
+
("AETHER", "has_capability", "Evolution"),
|
| 31 |
+
("Agent", "requires", "Memory"),
|
| 32 |
+
("Reasoning", "uses", "Knowledge_Graph"),
|
| 33 |
+
("Learning", "uses", "Neural_Networks"),
|
| 34 |
+
("Evolution", "optimizes", "Architecture"),
|
| 35 |
+
("Neural_Networks", "implement", "Learning"),
|
| 36 |
+
("Knowledge_Graph", "implements", "Reasoning"),
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
for h, r, t in facts:
|
| 40 |
+
kg.add_fact(h, r, t, confidence=1.0)
|
| 41 |
+
logger.info(f" Added: ({h}, {r}, {t})")
|
| 42 |
+
|
| 43 |
+
logger.info("\n Query: 'AETHER capabilities'")
|
| 44 |
+
result = kg.query("AETHER has_capability")
|
| 45 |
+
for r in result["results"]:
|
| 46 |
+
logger.info(f" -> {r['tail']} (confidence={r['confidence']:.2f}, source={r['source']})")
|
| 47 |
+
|
| 48 |
+
logger.info("\n Symbolic query: 'AETHER is_a ?'")
|
| 49 |
+
symbolic = kg.reason_symbolic("AETHER", "is_a")
|
| 50 |
+
for r in symbolic:
|
| 51 |
+
logger.info(f" -> {r['tail']} (path={r['path']})")
|
| 52 |
+
|
| 53 |
+
stats = kg.stats()
|
| 54 |
+
logger.info(f"\n KG Stats: {json.dumps(stats, indent=2)}")
|
| 55 |
+
return kg
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def demo_memory_system():
|
| 59 |
+
logger.info("\n" + "=" * 60)
|
| 60 |
+
logger.info("DEMO: CoALA Memory System")
|
| 61 |
+
logger.info("=" * 60)
|
| 62 |
+
|
| 63 |
+
from aether.memory import CoALAMemory
|
| 64 |
+
|
| 65 |
+
memory = CoALAMemory(capacity=16)
|
| 66 |
+
|
| 67 |
+
memory.store({"task": "Solve math problem", "priority": "high"}, "working")
|
| 68 |
+
memory.store({"task": "Update knowledge graph", "priority": "medium"}, "working")
|
| 69 |
+
memory.store({"task": "Evolve architecture", "priority": "high"}, "working")
|
| 70 |
+
|
| 71 |
+
for i in range(5):
|
| 72 |
+
memory.store({
|
| 73 |
+
"episode": i,
|
| 74 |
+
"action": f"action_{i}",
|
| 75 |
+
"reward": 0.5 + i * 0.1,
|
| 76 |
+
}, "episodic")
|
| 77 |
+
|
| 78 |
+
memory.store({
|
| 79 |
+
"gravity": "9.8 m/s^2",
|
| 80 |
+
"pi": "3.14159",
|
| 81 |
+
"euler": "2.71828",
|
| 82 |
+
}, "semantic")
|
| 83 |
+
|
| 84 |
+
logger.info("\n Retrieve 'task' from working memory:")
|
| 85 |
+
results = memory.retrieve("task", memory_type="working", top_k=3)
|
| 86 |
+
for r in results:
|
| 87 |
+
logger.info(f" -> {r}")
|
| 88 |
+
|
| 89 |
+
logger.info("\n Retrieve 'episode' from episodic memory:")
|
| 90 |
+
results = memory.retrieve("episode", memory_type="episodic", top_k=3)
|
| 91 |
+
for r in results:
|
| 92 |
+
logger.info(f" -> {r}")
|
| 93 |
+
|
| 94 |
+
logger.info(f"\n Memory stats: working={len(memory.working)}, episodic={len(memory.episodic)}")
|
| 95 |
+
return memory
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def demo_agents():
|
| 99 |
+
logger.info("\n" + "=" * 60)
|
| 100 |
+
logger.info("DEMO: Agent Orchestration")
|
| 101 |
+
logger.info("=" * 60)
|
| 102 |
+
|
| 103 |
+
from aether.agents import AetherAgentOrchestrator
|
| 104 |
+
|
| 105 |
+
config = AetherConfig(
|
| 106 |
+
macro_policy_dim=128,
|
| 107 |
+
micro_policy_dim=64,
|
| 108 |
+
num_agents=4,
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
orchestrator = AetherAgentOrchestrator(config)
|
| 112 |
+
|
| 113 |
+
logger.info("\n Executing task: 'Build a reasoning system'")
|
| 114 |
+
result = orchestrator.execute("Build a reasoning system", None, {})
|
| 115 |
+
|
| 116 |
+
logger.info(f"\n Output: {result['output'][:100]}...")
|
| 117 |
+
logger.info(f" Blueprint: {result['blueprint']}")
|
| 118 |
+
logger.info(f" Agents used: {list(result['agent_outputs'].keys())}")
|
| 119 |
+
logger.info(f" Routing weights: {[f'{w:.3f}' for w in result['routing_weights']]}")
|
| 120 |
+
|
| 121 |
+
logger.info("\n Running BabyAGI loop for objective: 'Research self-evolution'")
|
| 122 |
+
babyagi_result = orchestrator.run_babyagi("Research self-evolution", max_iterations=3)
|
| 123 |
+
logger.info(f" Completed {babyagi_result['iterations']} iterations")
|
| 124 |
+
logger.info(f" Tasks completed: {len(babyagi_result['completed_tasks'])}")
|
| 125 |
+
|
| 126 |
+
return orchestrator
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def demo_evolution():
|
| 130 |
+
logger.info("\n" + "=" * 60)
|
| 131 |
+
logger.info("DEMO: Evolutionary Engine")
|
| 132 |
+
logger.info("=" * 60)
|
| 133 |
+
|
| 134 |
+
from aether.evolution import AetherEvolutionEngine
|
| 135 |
+
|
| 136 |
+
config = AetherConfig(
|
| 137 |
+
population_size=8,
|
| 138 |
+
mutation_rate=0.15,
|
| 139 |
+
learning_rate=2e-5,
|
| 140 |
+
macro_policy_dim=256,
|
| 141 |
+
micro_policy_dim=128,
|
| 142 |
+
num_agents=4,
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
engine = AetherEvolutionEngine(config)
|
| 146 |
+
|
| 147 |
+
logger.info("\n Generating candidate architectures...")
|
| 148 |
+
candidates = engine.generate_candidates(config, population_size=8)
|
| 149 |
+
logger.info(f" Generated {len(candidates)} candidates")
|
| 150 |
+
|
| 151 |
+
fitness_scores = [0.3 + 0.5 * torch.rand(1).item() for _ in candidates]
|
| 152 |
+
logger.info(f" Fitness scores: {[f'{s:.3f}' for s in fitness_scores]}")
|
| 153 |
+
|
| 154 |
+
logger.info("\n Selecting candidates (Performance-Novelty)...")
|
| 155 |
+
selected = engine.select(candidates, fitness_scores, alpha_exploration=0.3)
|
| 156 |
+
logger.info(f" Selected {len(selected)} candidates")
|
| 157 |
+
|
| 158 |
+
logger.info("\n Applying constrained mutations...")
|
| 159 |
+
mutated = engine.mutate(selected, mutation_rate=0.2)
|
| 160 |
+
logger.info(f" Produced {len(mutated)} mutants")
|
| 161 |
+
|
| 162 |
+
engine.update_archive(candidates, fitness_scores)
|
| 163 |
+
logger.info(f"\n Archive stats: {json.dumps(engine.get_diversity_stats(), indent=2)}")
|
| 164 |
+
|
| 165 |
+
return engine
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def demo_safety():
|
| 169 |
+
logger.info("\n" + "=" * 60)
|
| 170 |
+
logger.info("DEMO: Safety Sandbox")
|
| 171 |
+
logger.info("=" * 60)
|
| 172 |
+
|
| 173 |
+
from aether.safety import SafetySandbox
|
| 174 |
+
|
| 175 |
+
sandbox = SafetySandbox(timeout=30.0)
|
| 176 |
+
|
| 177 |
+
config = AetherConfig(population_size=8, mutation_rate=0.15, learning_rate=2e-5)
|
| 178 |
+
|
| 179 |
+
logger.info("\n Validating safe config...")
|
| 180 |
+
valid = sandbox.validate_architecture(config)
|
| 181 |
+
logger.info(f" Result: {'PASS' if valid else 'FAIL'}")
|
| 182 |
+
|
| 183 |
+
bad_config = AetherConfig(population_size=200, mutation_rate=0.8, learning_rate=0.1)
|
| 184 |
+
|
| 185 |
+
logger.info("\n Validating unsafe config...")
|
| 186 |
+
valid = sandbox.validate_architecture(bad_config)
|
| 187 |
+
logger.info(f" Result: {'PASS' if valid else 'FAIL'}")
|
| 188 |
+
|
| 189 |
+
logger.info("\n Testing sandbox execution...")
|
| 190 |
+
with sandbox.sandbox() as ctx:
|
| 191 |
+
result = sum(range(100))
|
| 192 |
+
ctx["modifications_attempted"].append("safe_operation")
|
| 193 |
+
logger.info(f" Safe operation result: {result}")
|
| 194 |
+
|
| 195 |
+
logger.info(f"\n Audit summary: {json.dumps(sandbox.get_audit_summary(), indent=2)}")
|
| 196 |
+
|
| 197 |
+
return sandbox
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def demo_full_aether():
|
| 201 |
+
logger.info("\n" + "=" * 60)
|
| 202 |
+
logger.info("DEMO: Full AETHER Integration")
|
| 203 |
+
logger.info("=" * 60)
|
| 204 |
+
|
| 205 |
+
config = AetherConfig(
|
| 206 |
+
population_size=4,
|
| 207 |
+
generations=3,
|
| 208 |
+
mutation_rate=0.1,
|
| 209 |
+
learning_rate=2e-5,
|
| 210 |
+
macro_policy_dim=128,
|
| 211 |
+
micro_policy_dim=64,
|
| 212 |
+
num_agents=2,
|
| 213 |
+
enable_self_modification=True,
|
| 214 |
+
)
|
| 215 |
+
|
| 216 |
+
aether = AetherCore(config=config, model_name="demo-model")
|
| 217 |
+
|
| 218 |
+
facts = [
|
| 219 |
+
("AI", "is_a", "Technology"),
|
| 220 |
+
("AGI", "is_a", "AI"),
|
| 221 |
+
("AETHER", "is_a", "AGI"),
|
| 222 |
+
("AETHER", "integrates", "Neural_Networks"),
|
| 223 |
+
("AETHER", "integrates", "Symbolic_Reasoning"),
|
| 224 |
+
("Neural_Networks", "enables", "Learning"),
|
| 225 |
+
("Symbolic_Reasoning", "enables", "Explainability"),
|
| 226 |
+
]
|
| 227 |
+
|
| 228 |
+
for h, r, t in facts:
|
| 229 |
+
aether.knowledge.add_fact(h, r, t)
|
| 230 |
+
|
| 231 |
+
tasks = [
|
| 232 |
+
"What is AETHER?",
|
| 233 |
+
"How does AETHER learn?",
|
| 234 |
+
"Explain AETHER reasoning",
|
| 235 |
+
]
|
| 236 |
+
|
| 237 |
+
for task in tasks:
|
| 238 |
+
logger.info(f"\n Task: {task}")
|
| 239 |
+
result = aether.forward(task)
|
| 240 |
+
logger.info(f" Symbolic weight: {result['symbolic_weight']:.3f}")
|
| 241 |
+
logger.info(f" Neural weight: {result['neural_weight']:.3f}")
|
| 242 |
+
logger.info(f" KG context: {len(result['kg_context']['results'])} results")
|
| 243 |
+
|
| 244 |
+
logger.info("\n Self-reflection...")
|
| 245 |
+
reflection = aether.self_reflect()
|
| 246 |
+
logger.info(f" Generation: {reflection['generation']}")
|
| 247 |
+
logger.info(f" Memory stats: {json.dumps(reflection['memory_stats'], indent=2)}")
|
| 248 |
+
logger.info(f" Neuro-symbolic balance: {json.dumps(reflection['neuro_symbolic_balance'], indent=2)}")
|
| 249 |
+
|
| 250 |
+
logger.info("\n Mock evolution...")
|
| 251 |
+
def mock_eval(cfg):
|
| 252 |
+
return 0.5 + 0.3 * torch.rand(1).item()
|
| 253 |
+
|
| 254 |
+
evolve_result = aether.evolve(mock_eval, num_generations=2)
|
| 255 |
+
logger.info(f" Best fitness: {evolve_result['best_fitness']:.4f}")
|
| 256 |
+
logger.info(f" Generations evolved: {evolve_result['generations_evolved']}")
|
| 257 |
+
logger.info(f" Architecture changes: {len(evolve_result['architecture_history'])}")
|
| 258 |
+
|
| 259 |
+
logger.info("\n Exporting state...")
|
| 260 |
+
state = aether.export_state()
|
| 261 |
+
logger.info(f" State keys: {list(state.keys())}")
|
| 262 |
+
logger.info(f" Metadata: {json.dumps(state['metadata'], indent=2)}")
|
| 263 |
+
|
| 264 |
+
return aether
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def main():
|
| 268 |
+
logger.info("\n" + "=" * 70)
|
| 269 |
+
logger.info(" AETHER: A Self-Evolving Neuro-Symbolic Architecture")
|
| 270 |
+
logger.info(" Integrating AlphaEvolve + BabyAGI + HiMAC + GEA + Yunjue + ASI-Evolve")
|
| 271 |
+
logger.info(" + CoALA + MLPO + Agentic Neural Networks + CoMAS")
|
| 272 |
+
logger.info("=" * 70)
|
| 273 |
+
|
| 274 |
+
start_time = time.time()
|
| 275 |
+
|
| 276 |
+
demo_knowledge_graph()
|
| 277 |
+
demo_memory_system()
|
| 278 |
+
demo_agents()
|
| 279 |
+
demo_evolution()
|
| 280 |
+
demo_safety()
|
| 281 |
+
demo_full_aether()
|
| 282 |
+
|
| 283 |
+
elapsed = time.time() - start_time
|
| 284 |
+
|
| 285 |
+
logger.info("\n" + "=" * 70)
|
| 286 |
+
logger.info(f" All demos completed in {elapsed:.2f}s")
|
| 287 |
+
logger.info("=" * 70)
|
| 288 |
+
logger.info("\n Components verified:")
|
| 289 |
+
logger.info(" [x] Knowledge Graph Engine (RGCN + ComplEx)")
|
| 290 |
+
logger.info(" [x] CoALA Memory (Working + Episodic + Semantic + Procedural)")
|
| 291 |
+
logger.info(" [x] Agent Orchestration (Hierarchical + BabyAGI + MLPO)")
|
| 292 |
+
logger.info(" [x] Evolution Engine (MAP-Elites + Performance-Novelty)")
|
| 293 |
+
logger.info(" [x] Safety Sandbox (Validation + Audit + Constraints)")
|
| 294 |
+
logger.info(" [x] Full AETHER Integration")
|
| 295 |
+
logger.info("\n Ready for training with TRL GRPO!")
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
if __name__ == "__main__":
|
| 299 |
+
main()
|