micro_swarm
Swarm orchestration and coordination for micro-neural networks
The micro_swarm
crate provides high-level orchestration, coordination, and lifecycle management for swarms of micro-neural networks in the Semantic Cartan Matrix system. It handles agent spawning, task scheduling, memory management, and inter-agent communication.
๐ Features
- Agent Lifecycle Management: Spawn, monitor, and terminate micro-network agents
- Parallel Execution: Multi-threaded task scheduling with work-stealing
- Memory Pooling: Efficient allocation and reuse of neural network resources
- Dashboard Server: Real-time monitoring with REST API and WebSocket support
- Plugin Architecture: Extensible integration with rUv-FANN and other systems
- Load Balancing: Dynamic workload distribution across agents
- Fault Tolerance: Automatic agent recovery and error handling
- Cross-Platform: Native, WebAssembly, and embedded deployment
๐ฆ Installation
Add this to your Cargo.toml
:
[]
= "0.1.0"
= "0.1.0"
= "0.1.0"
# Optional features
= { = "0.1.0", = ["std", "dashboard", "parallel"] }
๐๏ธ Core Components
SwarmOrchestrator
Central coordination hub for all micro-network agents:
use ;
use ;
let config = SwarmConfig ;
let mut orchestrator = new;
// Spawn specialized agents
orchestrator.spawn_agent;
// Process inputs through the swarm
let input = from_slice;
let result = orchestrator.process.await?;
println!;
Agent Management
Dynamic agent lifecycle with health monitoring:
use ;
// Create and configure agents
let mut agent = new;
// Start agent with health monitoring
agent.start.await?;
// Monitor agent health
let health = agent.check_health.await;
match health.state
// Graceful shutdown
agent.shutdown.await?;
Task Scheduling
Priority-based task scheduling with parallel execution:
use ;
let mut scheduler = new; // 8 worker threads
// Schedule high-priority task
let task = new
.name
.priority
.input
.target_agents
.execution_strategy;
let task_id = scheduler.schedule.await?;
// Wait for completion
let result = scheduler.wait_for_completion.await?;
// Or use async processing
let handle = scheduler.schedule_async.await?;
spawn;
๐ง Agent Types
Specialized Agent Implementations
The swarm supports multiple agent types with distinct capabilities:
use ;
// Quantum agents for quantum-inspired computation
let quantum_agent = AgentSpec ;
// Neural agents for deep learning tasks
let neural_agent = AgentSpec ;
// Visualization agents for real-time monitoring
let viz_agent = AgentSpec ;
// Spawn all agent types
orchestrator.spawn_agents.await?;
Agent Communication
Inter-agent message passing and coordination:
use ;
// Send message between agents
let message = Message ;
orchestrator.send_message.await?;
// Broadcast to all agents
let broadcast = Message ;
orchestrator.broadcast_message.await?;
// Set up message handlers
orchestrator.on_message;
๐พ Memory Management
Memory Pooling
Efficient memory allocation with region-based management:
use ;
let memory_config = MemoryConfig ;
let memory_manager = new;
// Allocate memory for agents
let agent_memory = memory_manager.allocate_for_agent?;
// Zero-copy data transfer between agents
let data_region = memory_manager.create_shared_region?;
memory_manager.share_region?;
// Automatic garbage collection
memory_manager.collect_garbage.await;
// Memory usage statistics
let stats = memory_manager.get_statistics;
println!;
Resource Monitoring
Track resource usage across the swarm:
use ;
let mut monitor = new;
// Set resource thresholds
monitor.set_threshold;
monitor.set_threshold;
// Monitor continuously
spawn;
๐ Dashboard and Monitoring
Real-Time Dashboard
Web-based monitoring interface with REST API and WebSocket support:
use ;
let dashboard_config = DashboardConfig ;
let dashboard = new;
// Start dashboard server
dashboard.start.await?;
// Dashboard provides:
// - Real-time agent status and health
// - Performance metrics and graphs
// - Memory usage visualization
// - Task queue monitoring
// - Interactive swarm topology view
// - Export capabilities (JSON, CSV, PNG)
println!;
REST API Endpoints
The dashboard exposes comprehensive REST API:
// GET /api/swarm/status - Overall swarm status
// GET /api/agents - List all agents
// GET /api/agents/{id} - Specific agent details
// GET /api/agents/{id}/health - Agent health check
// POST /api/agents/{id}/restart - Restart agent
// GET /api/tasks - List active tasks
// GET /api/tasks/{id} - Task details
// GET /api/metrics - Performance metrics
// GET /api/memory - Memory usage statistics
// WebSocket /ws/live - Real-time updates
// Example API usage:
use reqwest;
let response = get.await?;
let status: SwarmStatus = response.json.await?;
println!;
println!;
println!;
Metrics Export
Export metrics in multiple formats:
use ;
let exporter = new;
// Export as JSON for dashboards
let json_metrics = exporter.export.await?;
// Export as Prometheus format
let prometheus_metrics = exporter.export.await?;
// Export as CSV for analysis
let csv_metrics = exporter.export.await?;
// Automatic export to external systems
exporter.configure_auto_export;
๐ง Integration Points
rUv-FANN Integration
Seamless integration with the rUv-FANN neuro-synaptic simulator:
use ;
let plugin_config = PluginConfig ;
let ruv_fann_plugin = new;
orchestrator.add_plugin.await?;
// Agents can now interface directly with neuro-synaptic chip
let spike_data = vec!;
let result = orchestrator.process_spikes.await?;
Plugin Architecture
Extensible plugin system for custom integrations:
use ;
// Register plugin
let plugin = CustomPlugin ;
orchestrator.add_plugin.await?;
โก Performance Optimization
Load Balancing
Dynamic workload distribution:
use ;
let load_balancer = new;
// Automatically distributes tasks based on:
// - Agent current load
// - Agent capabilities
// - Task priority
// - Historical performance
// - Resource availability
// Manual load balancing
let optimal_agent = load_balancer.select_agent_for_task.await?;
orchestrator.assign_task.await?;
// Automatic rebalancing
load_balancer.enable_auto_rebalancing;
Parallel Execution
Multi-threaded task processing:
use ;
let config = ExecutionConfig ;
let executor = new;
// Process multiple tasks in parallel
let tasks = vec!;
let results = executor.execute_parallel.await?;
// Pipeline processing
let pipeline_results = executor.execute_pipeline.await?;
๐งช Testing and Development
Integration Testing
Comprehensive testing framework:
# Test basic orchestration
# Test agent lifecycle
# Test parallel execution
# Test dashboard API
# Stress testing
Development Tools
Built-in development and debugging tools:
use ;
let debug_config = DebugConfig ;
let debugger = new;
orchestrator.attach_debugger;
// Debug specific agents
orchestrator.enable_agent_debugging;
// Trace message flow
orchestrator.trace_message_flow;
// Export debug information
let debug_info = orchestrator.export_debug_info.await?;
๐ง Configuration
Feature Flags
[]
= ["std", "dashboard"]
= ["dep:std", "tokio"]
= ["dep:axum", "dep:serde_json", "dep:tokio-tungstenite"]
= ["dep:rayon", "dep:crossbeam"]
= ["dep:prometheus", "micro_metrics/prometheus"]
= ["dep:libloading"]
= ["dep:qiskit-rust"]
Runtime Configuration
use ;
let config = SwarmConfig ;
set_swarm;
๐ Examples
See the examples/
directory for:
- Basic Orchestration: Simple swarm setup and usage
- Multi-Agent Coordination: Complex agent interactions
- Dashboard Integration: Real-time monitoring setup
- Plugin Development: Creating custom plugins
- Performance Optimization: Load balancing and parallel execution
- Integration Examples: rUv-FANN and other system integrations
๐ License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
๐ Related Crates
micro_core
: Core types and neural network primitivesmicro_routing
: Intelligent agent routing and selectionmicro_cartan_attn
: Attention mechanisms for coordinationmicro_metrics
: Performance monitoring and analytics
Part of the rUv-FANN Semantic Cartan Matrix system ๐ง ๐ค