strange_loop/
lib.rs

1//! Strange Loop - Ultra-low-latency agent framework
2//!
3//! Strange Loop is a Rust-based agent framework designed for nanosecond-precision
4//! coordination and ultra-low-latency systems. It provides deterministic agent
5//! execution with sub-microsecond timing guarantees.
6//!
7//! # Features
8//!
9//! - **Nano-agent system**: Deterministic agents with budget enforcement
10//! - **Temporal prediction**: Computing solutions before data arrives
11//! - **Lock-free communication**: High-performance message passing
12//! - **SIMD optimizations**: Cache-aligned data structures
13//! - **Nanosecond precision**: TSC-based timing for accuracy
14//!
15//! # Quick Start
16//!
17//! ```rust
18//! use strange_loop::nano_agent::{NanoScheduler, SchedulerConfig, SchedulerTopology};
19//!
20//! let config = SchedulerConfig {
21//!     topology: SchedulerTopology::Mesh,
22//!     run_duration_ns: 100_000_000, // 100ms
23//!     tick_duration_ns: 50_000,     // 50μs
24//!     max_agents: 10,
25//!     bus_capacity: 1000,
26//!     enable_tracing: false,
27//! };
28//!
29//! let mut scheduler = NanoScheduler::new(config);
30//! // Add agents and run...
31//! ```
32//!
33//! # Performance
34//!
35//! - **Sub-microsecond execution**: Agents execute in <1μs
36//! - **20,000+ Hz coordination**: Multi-agent synchronization
37//! - **Zero allocations**: Lock-free, allocation-free hot paths
38//! - **SIMD acceleration**: AVX2-optimized vector operations
39//!
40//! # Architecture
41//!
42//! Strange Loop implements a hierarchical agent system where nano-agents
43//! operate with strict timing budgets and communicate through lock-free
44//! message buses. The system is designed for real-time applications
45//! requiring deterministic behavior.
46
47#![warn(missing_docs)]
48#![warn(clippy::all)]
49#![allow(clippy::module_name_repetitions, clippy::must_use_candidate)]
50
51pub mod consciousness;
52pub mod error;
53pub mod types;
54pub mod vector3d;
55
56// Nano-agent system (working)
57pub mod nano_agent;
58
59// Exotic features (working)
60pub mod temporal_lead;
61pub mod strange_attractor;
62
63// Complex modules (re-enabled with namespace fixes)
64#[cfg(feature = "quantum")]
65pub mod quantum_container;
66#[cfg(feature = "consciousness")]
67pub mod temporal_consciousness;
68pub mod lipschitz_loop;
69pub mod retrocausal;
70pub mod self_modifying;
71
72// Re-exports for convenience
73pub use error::{LoopError, Result};
74pub use nano_agent::{NanoAgent, NanoScheduler, SchedulerConfig, SchedulerTopology, TickResult};
75pub use temporal_lead::TemporalLeadPredictor;
76pub use types::{Context, LoopConfig, Policy, ScalarReasoner, SimpleCritic, SafeReflector, StrangeLoop};
77pub use vector3d::Vector3D;
78
79/// Version information
80pub const VERSION: &str = env!("CARGO_PKG_VERSION");
81
82/// Build timestamp
83pub const BUILD_TIME: &str = "unknown";
84
85/// Git commit hash
86pub const GIT_SHA: &str = "unknown";
87
88/// Build information
89pub const BUILD_INFO: &str = concat!(
90    "Strange Loop v", env!("CARGO_PKG_VERSION"),
91    " built for framework with thousands of tiny agents"
92);
93
94#[cfg(test)]
95mod tests {
96    use super::*;
97    use std::collections::HashMap;
98
99    #[test]
100    fn test_basic_strange_loop() {
101        let mut context = HashMap::from([("x".to_string(), 10.0)]);
102        let reasoner = ScalarReasoner::new(0.0, 0.1);
103        let critic = SimpleCritic::new();
104        let reflector = SafeReflector::new();
105
106        let config = LoopConfig {
107            max_iterations: 100,
108            max_duration_ns: 1_000_000, // 1ms
109            convergence_threshold: 1e-6,
110            lipschitz_constant: 0.8,
111            enable_consciousness: false,
112            enable_quantum: false,
113            enable_simd: false,
114        };
115
116        let mut loop_engine = StrangeLoop::new(reasoner, critic, reflector, config);
117        let result = loop_engine.run(&mut context);
118
119        assert!(result.is_ok());
120        let final_x = context.get("x").unwrap();
121        assert!(*final_x < 1.0); // Should converge toward target 0.0
122    }
123
124    #[test]
125    fn test_nano_agent_system() {
126        let config = SchedulerConfig {
127            topology: SchedulerTopology::RoundRobin,
128            run_duration_ns: 1_000_000, // 1ms
129            tick_duration_ns: 100_000,  // 100μs
130            max_agents: 5,
131            bus_capacity: 100,
132            enable_tracing: false,
133        };
134
135        let scheduler = NanoScheduler::new(config);
136        assert_eq!(scheduler.agent_count(), 0);
137    }
138
139    #[test]
140    fn test_temporal_prediction() {
141        let mut predictor = TemporalLeadPredictor::new(1_000_000, 100); // 1ms horizon
142
143        // Test prediction capability
144        let prediction = predictor.predict_future(vec![1.0, 2.0, 3.0]);
145        assert_eq!(prediction.len(), 3);
146
147        // Predictions should be reasonable extrapolations
148        for &pred in &prediction {
149            assert!(pred.is_finite());
150        }
151    }
152
153    #[test]
154    fn test_version_info() {
155        assert!(!VERSION.is_empty());
156        assert!(!BUILD_TIME.is_empty());
157        assert!(!GIT_SHA.is_empty());
158    }
159}