damienstanton/agentlightning-rs

โ˜… 0Forks 0RustGitHub โ†—Compare

README

agentlightning

Rust port of Microsoft's Agent Lightning reinforcement learning framework.

Overview

Agent Lightning provides environment-independent RL training through structured span recording. This Rust implementation eliminates Python fragility and enables single-binary deployment.

Features

  • ๐ŸŽฏ Span Collection: Structured recording of agent interactions (Observations, Actions, Rewards)
  • ๐Ÿ’พ Lightning Store: Embedded Sled-based persistent storage with automatic indexing
  • ๐Ÿง  Algorithm Interface: Trait-based RL algorithm abstraction
  • ๐Ÿ”„ Async Trainer: Configurable training loop with batching and metrics

Quick Start

use agentlightning::{
    LightningStore, ObservationSpan, RewardSpan, Span,
    algorithm::RewardAggregator, Trainer, TrainerConfig,
};
use serde_json::json;
use std::{env, sync::Arc};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize store
    let store_path = env::temp_dir().join("agentlightning");
    let store = Arc::new(LightningStore::open(store_path)?);
    
    // Emit spans
    let obs = Span::Observation(
        ObservationSpan::new(json!({"step": 1}))
            .with_task("demo")
            .with_agent("agent-1")
    );
    store.insert_span(&obs)?;
    
    // Train
    let config = TrainerConfig {
        task_id: Some("demo".into()),
        batch_size: 50,
        ..Default::default()
    };
    
    let mut trainer = Trainer::new(store.clone(), config);
    let mut algo = RewardAggregator::default();
    let results = trainer.run(&mut algo).await?;
    
    Ok(())
}

Architecture

agentlightning/
โ”œโ”€โ”€ span.rs        # Span types (Observation, Action, Reward)
โ”œโ”€โ”€ collector.rs   # SpanCollector trait + implementations
โ”œโ”€โ”€ store.rs       # Sled-based persistent storage
โ”œโ”€โ”€ algorithm.rs   # LightningAlgorithm trait
โ”œโ”€โ”€ trainer.rs     # Training loop orchestration

Features

  • Default: Core Lightning functionality with composable crate boundaries.
[dependencies]
agentlightning = { path = "crates/agentlightning" }

Testing

# Run all tests across the workspace
cargo test --workspace

# Run specific module tests in the core crate
cargo test -p agentlightning-core span::tests

The test suite covers span types, storage, algorithms, and training across the workspace crates.

References

Contributors

qpvky2dyb6-hueCopilot

Issues