omega-runtime 1.1.0

Production runtime orchestrator integrating all ExoGenesis Omega subsystems with health monitoring
Documentation
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# omega-runtime

[![Crates.io](https://img.shields.io/crates/v/omega-runtime)](https://crates.io/crates/omega-runtime)
[![Documentation](https://docs.rs/omega-runtime/badge.svg)](https://docs.rs/omega-runtime)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

Production runtime orchestrator integrating all ExoGenesis Omega subsystems with health monitoring, circuit breakers, and graceful degradation.

**Part of the [ExoGenesis-Omega](https://github.com/prancer-io/ExoGenesis-Omega) cognitive architecture.**

## Overview

`omega-runtime` is the production-ready orchestration layer that brings together all ExoGenesis Omega components: AgentDB for vector storage, the 12-tier Memory system, 7 temporal Loops, and META-SONA for architecture evolution. It provides a unified, type-safe API with built-in reliability features for deploying AI systems at scale.

The runtime handles subsystem lifecycle management, inter-component communication, health monitoring, automatic recovery, and graceful degradation under failure conditions.

## Features

- **Unified API**: Single interface to all Omega subsystems
- **Health Monitoring**: Continuous health checks for all components
- **Circuit Breakers**: Automatic failure detection and isolation
- **Graceful Degradation**: Maintains reduced functionality during failures
- **Retry Logic**: Configurable exponential backoff with jitter
- **Event System**: Comprehensive event bus for system-wide notifications
- **State Management**: Robust state machine with lifecycle tracking
- **Configuration**: Validated configuration with sensible defaults
- **Metrics**: Built-in performance and usage metrics
- **Async-First**: Full Tokio integration for high concurrency

## Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
omega-runtime = "0.1.0"
```

## Quick Start

```rust
use omega_runtime::{OmegaRuntime, OmegaConfig, OmegaAPI};
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create runtime with default configuration
    let config = OmegaConfig::default();
    let runtime = Arc::new(OmegaRuntime::new(config).await?);

    // Start all subsystems
    runtime.start().await?;

    // Create high-level API
    let api = OmegaAPI::new(runtime.clone());

    // Store a memory
    api.store_memory(
        omega_runtime::MemoryTier::Semantic,
        "Rust is a systems programming language".to_string(),
        vec![0.1; 768],
        0.9,
    ).await?;

    // Create an intelligence
    let spec = omega_runtime::IntelligenceSpec {
        name: "Assistant".to_string(),
        min_capability: 0.80,
        ..Default::default()
    };

    let intelligence = api.create_intelligence(spec).await?;
    println!("Created intelligence: {}", intelligence.name);

    // Get runtime health
    let health = api.health_status().await?;
    println!("Runtime health: {:?}", health.overall);

    // Shutdown gracefully
    runtime.stop().await?;
    Ok(())
}
```

## Core Concepts

### OmegaRuntime

The main orchestrator managing all subsystems:

- **AgentDB**: Vector database for semantic search
- **Memory**: 12-tier cosmic memory system
- **Loops**: 7 temporal cognitive loops
- **META-SONA**: Architecture search and evolution

Each subsystem is independently monitored and can fail gracefully.

### OmegaAPI

High-level interface abstracting subsystem details:

```rust
impl OmegaAPI {
    // Memory operations
    pub async fn store_memory(...) -> Result<String>;
    pub async fn recall_memories(...) -> Result<Vec<Memory>>;

    // Intelligence operations
    pub async fn create_intelligence(...) -> Result<Intelligence>;
    pub async fn list_intelligences(...) -> Result<Vec<Intelligence>>;

    // Loop operations
    pub async fn execute_loop_cycle(...) -> Result<CycleOutput>;
    pub async fn loop_status(...) -> Result<LoopStatus>;

    // System operations
    pub async fn health_status() -> Result<HealthStatus>;
    pub async fn metrics() -> Result<RuntimeMetrics>;
}
```

### Health Monitoring

Continuous monitoring with automatic recovery:

- **Subsystem Health**: Independent health checks
- **Performance Metrics**: Latency, throughput, error rates
- **Resource Usage**: Memory, CPU, storage
- **Automatic Recovery**: Restart failed components

### Circuit Breakers

Prevent cascade failures:

- **Closed**: Normal operation
- **Open**: Failures detected, bypass subsystem
- **Half-Open**: Testing recovery

### Event System

System-wide event bus:

```rust
pub enum OmegaEvent {
    MemoryStored { tier, id },
    MemoryConsolidated { from_tier, to_tier, count },
    LoopCycleStarted { loop_type, cycle_id },
    LoopCycleCompleted { loop_type, cycle_id, success },
    IntelligenceCreated { id, name },
    ArchitectureEvolved { id, generation, fitness },
    HealthChanged { component, old, new },
    ErrorOccurred { component, error },
}
```

## Use Cases

### 1. Production AI Agent Deployment

```rust
use omega_runtime::{OmegaRuntime, OmegaConfig, OmegaAPI};
use std::sync::Arc;

// Configure for production
let config = OmegaConfig {
    memory: MemoryConfig {
        enable_auto_consolidation: true,
        consolidation_interval_secs: 3600, // 1 hour
        ..Default::default()
    },
    loops: LoopsConfig {
        enable_all_loops: true,
        ..Default::default()
    },
    agentdb: AgentDBConfig {
        dimension: 1536, // OpenAI embeddings
        hnsw_m: 32,
        hnsw_ef: 100,
        ..Default::default()
    },
    ..Default::default()
};

let runtime = Arc::new(OmegaRuntime::new(config).await?);
runtime.start().await?;

let api = OmegaAPI::new(runtime.clone());

// Agent runs indefinitely
loop {
    // Process user input
    let user_message = receive_user_message().await;

    // Recall relevant memories
    let memories = api.recall_memories(
        user_message.embedding.clone(),
        vec![MemoryTier::Session, MemoryTier::Semantic],
        10,
    ).await?;

    // Generate response using memories
    let response = generate_response(&user_message, &memories);

    // Store interaction as episodic memory
    api.store_memory(
        MemoryTier::Episodic,
        format!("User: {} | Response: {}", user_message.text, response),
        user_message.embedding,
        0.7,
    ).await?;

    send_response(response).await;
}
```

### 2. Health Monitoring and Alerts

```rust
use omega_runtime::{OmegaAPI, HealthStatus};
use tokio::time::{interval, Duration};

let api = OmegaAPI::new(runtime.clone());

// Monitor health every 30 seconds
let mut health_check = interval(Duration::from_secs(30));

loop {
    health_check.tick().await;

    let health = api.health_status().await?;

    match health.overall {
        HealthStatus::Healthy => {
            println!("✓ All systems operational");
        }
        HealthStatus::Degraded => {
            println!("⚠ System degraded:");
            for (component, status) in health.subsystems {
                if status != HealthStatus::Healthy {
                    println!("  {} is {:?}", component, status);
                }
            }
        }
        HealthStatus::Unhealthy => {
            println!("✗ System unhealthy - triggering alerts");
            send_alert(&health).await;
        }
    }
}
```

### 3. Multi-Agent Orchestration

```rust
use omega_runtime::{OmegaAPI, IntelligenceSpec, LoopType, CycleInput};

let api = OmegaAPI::new(runtime.clone());

// Create specialized agents
let researcher = api.create_intelligence(IntelligenceSpec {
    name: "Researcher".to_string(),
    required_capabilities: vec!["research".to_string()],
    min_capability: 0.85,
    ..Default::default()
}).await?;

let executor = api.create_intelligence(IntelligenceSpec {
    name: "Executor".to_string(),
    required_capabilities: vec!["execution".to_string()],
    max_inference_time: Some(100.0),
    ..Default::default()
}).await?;

// Coordinate through deliberative loop
let planning_input = CycleInput {
    data: get_task_data(),
    context: "multi_agent_planning".to_string(),
    objectives: vec!["coordinate_agents".to_string()],
};

let plan = api.execute_loop_cycle(LoopType::Deliberative, planning_input).await?;

println!("Coordination plan: {:?}", plan);
```

### 4. Self-Improving System

```rust
use omega_runtime::{OmegaAPI, LoopType, MemoryTier};

let api = OmegaAPI::new(runtime.clone());

// Run evolutionary loop weekly
tokio::spawn(async move {
    let mut week_timer = tokio::time::interval(Duration::from_secs(7 * 24 * 3600));

    loop {
        week_timer.tick().await;

        // Collect performance data
        let metrics = api.metrics().await.unwrap();

        // Analyze and consolidate learnings
        let input = CycleInput {
            data: metrics_to_data(&metrics),
            context: "weekly_improvement".to_string(),
            objectives: vec!["identify_improvements".to_string()],
        };

        let output = api.execute_loop_cycle(LoopType::Evolutionary, input).await.unwrap();

        // Store improvements as strategic memories
        for improvement in extract_improvements(&output) {
            api.store_memory(
                MemoryTier::Strategic,
                improvement.description,
                improvement.embedding,
                0.95,
            ).await.unwrap();
        }

        println!("Weekly evolution completed");
    }
});
```

### 5. Graceful Degradation Example

```rust
use omega_runtime::{OmegaAPI, OmegaEvent};

let api = OmegaAPI::new(runtime.clone());

// Subscribe to health events
let mut event_rx = runtime.subscribe_events().await;

tokio::spawn(async move {
    while let Some(event) = event_rx.recv().await {
        match event {
            OmegaEvent::HealthChanged { component, new, .. } => {
                match (component.as_str(), new) {
                    ("agentdb", HealthStatus::Unhealthy) => {
                        println!("AgentDB failed - falling back to exact match");
                        // Use simpler memory retrieval
                    }
                    ("meta_sona", HealthStatus::Unhealthy) => {
                        println!("META-SONA failed - using fixed architectures");
                        // Use pre-created architectures
                    }
                    ("loops", HealthStatus::Degraded) => {
                        println!("Loops degraded - reducing to essential loops only");
                        // Run only reflexive and reactive loops
                    }
                    _ => {}
                }
            }
            _ => {}
        }
    }
});
```

## Examples

### Custom Configuration

```rust
use omega_runtime::{OmegaConfig, MemoryConfig, LoopsConfig, AgentDBConfig};

let config = OmegaConfig {
    memory: MemoryConfig {
        enable_auto_consolidation: true,
        consolidation_interval_secs: 1800,
        max_memories_per_tier: 10_000,
    },
    loops: LoopsConfig {
        enable_all_loops: true,
        reflexive_interval_ms: 100,
        reactive_interval_ms: 5000,
        adaptive_interval_ms: 1_800_000, // 30 min
    },
    agentdb: AgentDBConfig {
        dimension: 4096,
        hnsw_m: 64,
        hnsw_ef: 200,
        cache_size: 500_000,
    },
    meta_sona: MetaSONAConfig {
        enable_evolution: true,
        mcts_iterations: 1000,
        ppo_steps: 100,
    },
};

let runtime = OmegaRuntime::new(config).await?;
```

### Metrics Collection

```rust
let api = OmegaAPI::new(runtime.clone());

let metrics = api.metrics().await?;

println!("Runtime Metrics:");
println!("  Uptime: {:?}", metrics.uptime);
println!("  Total memories: {}", metrics.total_memories);
println!("  Memory by tier: {:?}", metrics.memories_by_tier);
println!("  Total cycles: {}", metrics.total_cycles);
println!("  Cycles by loop: {:?}", metrics.cycles_by_loop);
println!("  Intelligences: {}", metrics.intelligence_count);
println!("  Avg response time: {:?}", metrics.avg_response_time);
println!("  Error rate: {:.2}%", metrics.error_rate * 100.0);
```

## Architecture

The runtime integrates all Omega subsystems:

```
┌──────────────────────────────────────────┐
│          OmegaAPI (Public)                │
│  - Memory operations                      │
│  - Intelligence operations                │
│  - Loop operations                        │
│  - System operations                      │
└────────────┬─────────────────────────────┘
┌──────────────────────────────────────────┐
│         OmegaRuntime (Core)               │
│  - Lifecycle management                   │
│  - State machine                          │
│  - Event bus                              │
│  - Health monitoring                      │
└──┬────────┬────────────┬─────────────┬───┘
   │        │            │             │
   ▼        ▼            ▼             ▼
┌──────┐┌────────┐┌───────────┐┌───────────┐
│Agent ││Memory  ││  Loops    ││META-SONA  │
│ DB   ││System  ││  Engine   ││  Factory  │
└──────┘└────────┘└───────────┘└───────────┘
```

## Performance

Runtime overhead is minimal:

- **API Call Overhead**: <1ms
- **Health Check**: <10ms per subsystem
- **Event Propagation**: <1ms
- **State Transitions**: <100μs

Memory usage: ~10MB base + subsystem usage

## Related Crates

### Core Infrastructure
- **[omega-core]../omega-core** - Core types (used by runtime)
- **[omega-persistence]../omega-persistence** - Storage backend

### Subsystems
- **[omega-agentdb]../omega-agentdb** - Vector database subsystem
- **[omega-memory]../omega-memory** - Memory subsystem
- **[omega-loops]../omega-loops** - Loop engine subsystem
- **[omega-meta-sona]../omega-meta-sona** - Architecture evolution subsystem

### Brain-Like Cognition
- **[omega-brain]../omega-brain** - Unified cognitive architecture
- **[omega-snn]../omega-snn** - Spiking neural networks
- **[omega-attention]../omega-attention** - Attention mechanisms
- **[omega-consciousness]../omega-consciousness** - Consciousness models
- **[omega-hippocampus]../omega-hippocampus** - Memory circuits
- **[omega-sleep]../omega-sleep** - Sleep/wake consolidation
- **[omega-strange-loops]../omega-strange-loops** - Self-awareness

## License

Licensed under the MIT License. See [LICENSE](../../LICENSE) for details.