sdk

Rust SDK

Build incredibly fast multi-agent frameworks using Klock-Core directly.

If you are building the next generation of AI agent frameworks, you should build it on top of klock-core. It allows you to natively embed the Wait-Die queuing system into your Rust binaries with zero FFI overhead.

Installation

cargo add klock-core

Internal Architecture

The Rust kernel is divided into three primary components:

  1. The Conflict Engine: A 6×6 predicate compatibility matrix evaluated in O(1) time.
  2. The Wait-Die Scheduler: A priority queue system that handles DIE signals and enforces topological ordering based on session ticks.
  3. The Lease Store: An atomic storage engine (either in-memory via Arc<RwLock> or persistent via SQLite) representing active resources.

Example Usage

use klock_core::{KlockCore, LeaseRequest, Predicate, ResourceType};
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 1. Initialize the embedded Kernel
    let klock = KlockCore::new();
    
    // 2. Register Agents
    klock.register_agent("crawler-1", 100).await?;
    
    // 3. Create an Intent Manifest (KLIS)
    let request = LeaseRequest {
        agent_id: "crawler-1".to_string(),
        session_id: "sess-abc".to_string(),
        resource_type: ResourceType::File,
        resource_path: "/data/output.json".to_string(),
        predicate: Predicate::Mutates,
        ttl_ms: 60000,
    };
    
    // 4. Acquire the Lease
    let result = klock.acquire_lease(request).await?;
    
    if result.success {
        println!("Granted Lease: {}", result.lease_id.unwrap());
        // Do Work ...
    } else {
        println!("Blocked: Wait {}ms", result.wait_time.unwrap_or(0));
    }
    
    Ok(())
}

Performance Metrics

Because you bypass PyO3 and N-API bindings, the native execution speed on M-series silicon is staggering:

  • Single Pair Conflict Check: ~1 ns
  • 1000 Active Lease Matrix Check: ~339 ns
  • Full Acquire + Release Cycle: ~670 ns