mielin-cells
Agent SDK - The Neurotransmitter (Layer 2)
Comprehensive SDK for creating, managing, and migrating autonomous AI agents in the MielinOS ecosystem. Mielin Cells provides the core abstractions that enable agents to traverse seamlessly across heterogeneous hardware—the computational "neurotransmitters" of the system.
Overview
Mielin Cells implements Layer 2 of the MielinOS architecture, providing complete agent lifecycle management, stateful migration capabilities, policy enforcement, and DNA (WebAssembly binary) management.
Current Status: v0.1.0-rc.1 "Oligodendrocyte" (Released 2026-01-18)
Features
- Agent Lifecycle: Complete state management from creation to termination
- Stateful Migration: Snapshot, serialize, transmit, and restore running agents
- DNA Management: Content-addressable WASM binaries with cryptographic verification
- Policy Engine: Flexible execution policies (battery, latency, architecture preferences)
- Type-Safe: Strong typing for agent IDs, states, and operations
- Lightweight: Minimal overhead suitable for embedded to cloud deployments
Architecture
Layer 2 in the 5-layer neural architecture:
┌─────────────────────────────────────────────────────────────┐
│ Layer 2: Mielin Cells (The Neurotransmitter) │
│ • Agent Lifecycle Manager │
│ • DNA (WASM) Management │
│ • Migration Snapshot/Restore │
│ • Policy Enforcement Engine │
└─────────────────────────────────────────────────────────────┘
File Structure
mielin-cells/
├── src/
│ ├── agent.rs # Agent lifecycle and state management
│ ├── dna.rs # WebAssembly binary (DNA) management
│ ├── migration.rs # Snapshot/restore and migration logic
│ ├── policy.rs # Execution policy definitions
│ └── lib.rs # Public API and error types
└── Cargo.toml
Quick Start
Add to your Cargo.toml:
[]
= { = "../mielin-cells" }
Creating an Agent
use Agent;
// Create agent with WASM binary
let wasm_binary = vec!;
let agent = new;
println!;
println!;
println!;
Migrating an Agent (Saltatory Conduction)
use ;
let mut manager = new;
// Phase 1: Initiate migration
let snapshot = manager.initiate_migration?;
// Phase 2: Serialize for network transfer
let bytes = snapshot.serialize?;
println!;
// ... send over network (QUIC) ...
// Phase 3: Restore on target node
let restored_snapshot = deserialize?;
let restored_agent = restored_snapshot.restore?;
// Verify integrity
assert_eq!;
Core Components
Agent
The fundamental unit of computation in MielinOS—autonomous entities that can execute and migrate.
use ;
let mut agent = new;
// Lifecycle management
agent.set_state;
agent.set_state;
agent.set_state;
agent.set_state;
// Access components
let dna = agent.dna; // Immutable WASM bytecode
let policy = agent.policy; // Execution constraints
let id = agent.id; // Content-addressable ID
Agent States
State transitions:
Created → Running → Migrating → Running (on new node)
↓ ↓ ↓
Terminated ← Suspended → Running
DNA (WebAssembly Binary)
Immutable code representation with content addressing for verification and deduplication.
use Dna;
let dna = new;
// Get binary content
let binary = dna.binary;
println!;
// Get content hash (SHA-256)
let hash = dna.hash;
println!;
// Verify integrity after migration
DNA Features:
- Content-Addressable: Hash-based identification
- Immutable: Bytecode cannot be modified
- Verifiable: Cryptographic hash for integrity
- Deduplic able: Identical code shares same DNA
Migration System
Complete migration workflow with checkpoint/restore support.
use ;
// Capture agent state
let snapshot = capture?;
// Snapshot components
println!;
println!;
println!;
println!;
println!;
// Serialize to bytes (network transfer format)
let serialized = snapshot.serialize?;
println!;
// Deserialize on remote node
let restored = deserialize?;
// Restore agent
let new_agent = restored.restore?;
assert_eq!;
Migration Performance:
- Small agent (1MB state): ~5ms over LAN
- Large agent (100MB state): ~200ms over LAN
- Compression: 80-90% reduction with LZ4 (Phase 2)
- Delta encoding: Only changed pages (Phase 3)
Migration Manager
Tracks and manages pending migrations across the mesh:
let mut manager = new;
// Start migration
let snapshot = manager.initiate_migration?;
// Check status
println!;
// Complete migration (cleanup source)
manager.complete_migration;
// Or cancel if failed
manager.cancel_migration;
Policy Engine
Define execution constraints and migration triggers for intelligent agent placement.
use Policy;
let policy = Policy ;
let mut agent = new;
agent.set_policy;
// Check policy compliance
Policy Use Cases:
- Battery Protection: Migrate before power failure
- Latency Optimization: Stay near data sources
- Architecture Affinity: Prefer hardware with accelerators
- Resource Constraints: Avoid overloaded nodes
API Reference
Agent
Dna
MigrationSnapshot
MigrationManager
Policy
Examples
Complete Migration Workflow
use ;
use ;
// === Source Node ===
let wasm = vec!;
let mut agent = new;
agent.set_state;
// Trigger migration (e.g., low battery)
let mut manager = new;
let snapshot = manager.initiate_migration?;
agent.set_state;
// Serialize for network
let bytes = snapshot.serialize?;
// === Network Transfer (QUIC) ===
// send_over_quic(bytes)?;
// === Target Node ===
let received_snapshot = deserialize?;
let mut migrated_agent = received_snapshot.restore?;
migrated_agent.set_state;
// Verify integrity
assert_eq!;
// === Source Node (Cleanup) ===
manager.complete_migration;
agent.set_state;
Policy-Based Execution
use ;
// Define strict policy for production agent
let policy = Policy ;
let mut agent = new;
agent.set_policy;
// Node selection based on policy
Snapshot Size Optimization
let snapshot = capture?;
println!;
println!;
println!;
println!;
println!;
println!;
println!;
// Optimization strategies:
// 1. Minimize agent state (keep memory usage low)
// 2. Share DNA across agents (deduplicate bytecode)
// 3. Compress state (LZ4, coming in Phase 2)
// 4. Delta encoding (only changed pages, Phase 3)
Error Handling
All operations return Result<T, CellError> for explicit error handling.
Testing
Run the comprehensive test suite:
# All tests
# Specific test
# With output
Test Coverage (39 tests, 100% pass rate):
- Agent creation and state transitions
- DNA hashing and verification
- Migration snapshot creation and restoration
- Policy validation and enforcement
- Serialization round-trips
- Error conditions and edge cases
- Concurrent agent operations
Performance
Typical measurements on x86_64 (3.5 GHz):
| Operation | Time | Size | Notes |
|---|---|---|---|
| Agent creation | ~1 μs | 64 bytes | Overhead only |
| DNA hash (SHA-256) | ~0.5 μs/KB | - | For 1KB WASM |
| Snapshot creation | ~10 μs | Variable | Excludes WASM copy |
| Serialization | ~5 μs | +24 bytes | Overhead |
| Deserialization | ~5 μs | - | Plus allocation |
| Restoration | ~1 μs | - | Struct creation |
Snapshot Sizes:
- Minimal (empty WASM): ~78 bytes
- Typical (small agent): ~1-10 KB
- Medium (with state): ~100 KB
- Large (complex agent): ~1 MB
- Maximum (v1.0 target): <100 MB
Best Practices
1. Minimize Agent State
// Good: Small, focused agents
// Avoid: Large, stateful agents
2. Use Policies Wisely
// Define clear policies
let policy = Policy ;
// Not overly restrictive
let bad_policy = Policy ;
3. Verify After Migration
// Always verify DNA integrity
if !verify_migration
4. Handle Errors Gracefully
match snapshot.restore
5. Monitor Snapshot Age
let snapshot = capture?;
if snapshot.age_seconds > 60
Roadmap
Phase 1 (v0.1 "Ranvier") ✅ Complete
- ✅ Agent lifecycle management
- ✅ DNA content addressing
- ✅ Snapshot/restore mechanism
- ✅ Policy framework
- ✅ Migration manager
Phase 2 (v0.2 "Oligodendrocyte") - Q1-Q2 2026
- LZ4 compression for snapshots
- Incremental state snapshots
- Migration telemetry and metrics
- Enhanced error recovery
Phase 3 (v0.3 "Schwann") - Q2-Q3 2026
- Delta encoding (changed pages only)
- Encrypted agent state (AES-256-GCM)
- Advanced policies (thermal, load-based)
- Multi-agent coordination primitives
Phase 4 (v1.0 "Saltatory") - Q4 2026
- Signed DNA verification (Ed25519)
- Agent versioning and upgrades
- Capability attestation
- Production hardening
See TODO.md for detailed roadmap.
Contributing
See CONTRIBUTING.md for guidelines.
Key areas for contribution:
- Snapshot compression algorithms
- Policy DSL design
- Migration optimization strategies
- Agent coordination patterns
- Performance benchmarking
Resources
- Main Documentation - Complete technical whitepaper
- TODO & Roadmap - Development plan
- Examples - Reference implementations
- mielin-wasm - WASM runtime integration
Contact
- Repository: https://github.com/cool-japan/mielin
- Issues: https://github.com/cool-japan/mielin/issues
- Email: contact@cooljapan.tech
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Mielin Cells - The neurotransmitters enabling autonomous agents to traverse the computational nervous system 🧠⚡
Current Version: v0.1.0-rc.1 "Oligodendrocyte" | Released 2026-01-18