Rust port of Microsoft's Agent Lightning reinforcement learning framework.
Agent Lightning provides environment-independent RL training through structured span recording. This Rust implementation eliminates Python fragility and enables single-binary deployment.
- ๐ฏ 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
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(())
}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
- Default: Core Lightning functionality with composable crate boundaries.
[dependencies]
agentlightning = { path = "crates/agentlightning" }# Run all tests across the workspace
cargo test --workspace
# Run specific module tests in the core crate
cargo test -p agentlightning-core span::testsThe test suite covers span types, storage, algorithms, and training across the workspace crates.