| Crates.io | sw4rm-sdk |
| lib.rs | sw4rm-sdk |
| version | 0.4.0 |
| created_at | 2025-09-01 02:17:01.795477+00 |
| updated_at | 2026-01-03 23:37:49.963025+00 |
| description | SW4RM Agentic Protocol - Reference Rust SDK |
| homepage | https://sw4rm.ai |
| repository | https://github.com/rahulrajaram/sw4rm |
| max_upload_size | |
| id | 1819038 |
| size | 747,933 |
Reference Rust SDK for the SW4RM Agentic Protocol. This is one of three SDKs in this repository (Python, Rust, JavaScript) and provides high-performance gRPC clients and runtime utilities for building distributed autonomous agents.
Add to your Cargo.toml:
[dependencies]
sw4rm-sdk = "0.4.0"
tokio = { version = "1.0", features = ["full"] }
🎉 NEW: Complete working example with services included! You can now run a full SW4RM setup locally.
Option A: Python Services (Recommended for getting started)
cd ../../examples/reference-services/
./start_services_local.sh
Option B: Rust Services
cd ../../examples/reference-services/rust/
cargo run --bin start-services
cargo run --example echo_agent
You should see:
✅ Registered agent successfully
🚀 Starting message loop for echo-agent
# In another terminal
cd ../../examples/reference-services/
python test_complete_setup.py
This will send a test message that your agent will receive and process!
use sw4rm_sdk::*;
use async_trait::async_trait;
struct EchoAgent {
config: AgentConfig,
preemption: PreemptionManager,
}
impl EchoAgent {
fn new(config: AgentConfig) -> Self {
Self {
config,
preemption: PreemptionManager::new(),
}
}
}
#[async_trait]
impl Agent for EchoAgent {
async fn on_message(&mut self, envelope: EnvelopeData) -> Result<()> {
if let Ok(text) = envelope.string_payload() {
println!("Echo: {}", text);
}
Ok(())
}
fn config(&self) -> &AgentConfig {
&self.config
}
fn preemption_manager(&self) -> &PreemptionManager {
&self.preemption
}
}
#[tokio::main]
async fn main() -> Result<()> {
let config = AgentConfig::new(
"echo-agent-1".to_string(),
"Echo Agent".to_string()
);
let agent = EchoAgent::new(config.clone());
let mut runtime = AgentRuntime::new(config);
runtime.run(agent).await
}
The SDK is organized into several key modules:
clients/ - Type-safe gRPC clients for each serviceruntime/ - Agent runtime and preemption managementenvelope/ - Message envelope builders and utilitiesconfig/ - Configuration structures and defaultstypes/ - Common types and utilitieserror/ - Error types and result handlingThe SDK provides clients for all SW4RM protocol services:
Configure service endpoints via the Endpoints struct:
use sw4rm_sdk::*;
let endpoints = Endpoints {
registry: "http://localhost:50051".to_string(),
router: "http://localhost:50052".to_string(),
// ... other services
..Default::default()
};
let config = AgentConfig::new("my-agent".to_string(), "My Agent".to_string())
.with_endpoints(endpoints);
../../README.md../../QUICKSTART.md../py_sdk/README.md../js_sdk/README.mdThe SDK requires protobuf compilation. Ensure you have the protocol buffer compiler installed:
# On macOS
brew install protobuf
# On Ubuntu/Debian
sudo apt-get install protobuf-compiler
# On other systems, see: https://grpc.io/docs/protoc-installation/
Then build:
cargo build --release
See the examples/ directory for more comprehensive usage examples including:
use sw4rm_sdk::{EnvelopeBuilder, constants, control::{SchedulerCommandV1, SchedulerStage, CT_SCHEDULER_COMMAND_V1}};
let cmd = SchedulerCommandV1::new(SchedulerStage::Run)
.with_input(serde_json::json!({"repo":"demo"}));
let payload = cmd.to_bytes().unwrap();
let env = EnvelopeBuilder::new("frontend-agent".into(), constants::message_type::CONTROL)
.with_payload(payload)
.with_content_type(CT_SCHEDULER_COMMAND_V1.to_string())
.build();
// send `env` via Router client
Run the test suite:
cargo test
For integration tests with a running SW4RM cluster:
cargo test --features integration-tests
This SDK follows the SW4RM protocol specification. When contributing:
MIT License - see LICENSE file for details.