Skip to content

Commit e36b3e2

Browse files
feat(rust): add execution rings and lifecycle management to Rust SDK
Add two new modules to the agentmesh Rust crate: - rings.rs: Four-level execution privilege ring model (Admin/Standard/ Restricted/Sandboxed) with per-agent assignment and per-ring action permissions, ported from the Python hypervisor enforcer. - lifecycle.rs: Eight-state agent lifecycle manager (Provisioning through Decommissioned) with validated state transitions and event history, matching the lifecycle model used across other SDK languages. Both modules include comprehensive unit tests and are re-exported from the crate root. README updated with API tables and usage examples. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2981952 commit e36b3e2

4 files changed

Lines changed: 650 additions & 0 deletions

File tree

packages/agent-mesh/sdks/rust/agentmesh/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,70 @@ policies:
195195
window: "60s"
196196
```
197197
198+
### Execution Rings (`rings.rs`)
199+
200+
Four-level privilege model inspired by hardware protection rings.
201+
202+
| Function / Method | Description |
203+
|---|---|
204+
| `RingEnforcer::new()` | Create a new enforcer with no assignments |
205+
| `enforcer.assign(agent_id, ring)` | Assign an agent to a ring |
206+
| `enforcer.get_ring(agent_id)` | Get assigned ring (if any) |
207+
| `enforcer.check_access(agent_id, action)` | Check if action is permitted |
208+
| `enforcer.set_ring_permissions(ring, actions)` | Configure allowed actions for a ring |
209+
210+
Ring levels:
211+
212+
| Ring | Level | Access |
213+
|------|-------|--------|
214+
| `Admin` | 0 | All actions allowed |
215+
| `Standard` | 1 | Configurable actions |
216+
| `Restricted` | 2 | Configurable actions |
217+
| `Sandboxed` | 3 | All actions denied |
218+
219+
```rust
220+
use agentmesh::{RingEnforcer, Ring};
221+
222+
let mut enforcer = RingEnforcer::new();
223+
enforcer.set_ring_permissions(Ring::Standard, vec!["data.read".into(), "data.write".into()]);
224+
enforcer.assign("my-agent", Ring::Standard);
225+
226+
assert!(enforcer.check_access("my-agent", "data.read"));
227+
assert!(!enforcer.check_access("my-agent", "shell:rm"));
228+
```
229+
230+
### Agent Lifecycle (`lifecycle.rs`)
231+
232+
Eight-state lifecycle model tracking an agent from provisioning through decommissioning.
233+
234+
| Function / Method | Description |
235+
|---|---|
236+
| `LifecycleManager::new(agent_id)` | Create a new manager (starts in `Provisioning`) |
237+
| `manager.state()` | Get current lifecycle state |
238+
| `manager.events()` | Get recorded transition events |
239+
| `manager.transition(to, reason, initiated_by)` | Transition to a new state |
240+
| `manager.can_transition(to)` | Check if a transition is valid |
241+
| `manager.activate(reason)` | Convenience: transition to `Active` |
242+
| `manager.suspend(reason)` | Convenience: transition to `Suspended` |
243+
| `manager.quarantine(reason)` | Convenience: transition to `Quarantined` |
244+
| `manager.decommission(reason)` | Convenience: transition to `Decommissioning` |
245+
246+
Lifecycle states: `Provisioning` -> `Active` <-> `Suspended` / `Rotating` / `Degraded` -> `Quarantined` -> `Decommissioning` -> `Decommissioned`
247+
248+
```rust
249+
use agentmesh::{LifecycleManager, LifecycleState};
250+
251+
let mut mgr = LifecycleManager::new("my-agent");
252+
mgr.activate("initial boot").unwrap();
253+
assert_eq!(mgr.state(), LifecycleState::Active);
254+
255+
mgr.suspend("maintenance window").unwrap();
256+
assert_eq!(mgr.state(), LifecycleState::Suspended);
257+
258+
mgr.activate("maintenance complete").unwrap();
259+
assert_eq!(mgr.events().len(), 3);
260+
```
261+
198262
## License
199263

200264
See repository root [LICENSE](../../../../LICENSE).

packages/agent-mesh/sdks/rust/agentmesh/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@
2020
2121
pub mod audit;
2222
pub mod identity;
23+
pub mod lifecycle;
2324
pub mod mcp;
2425
pub mod policy;
26+
pub mod rings;
2527
pub mod trust;
2628
pub mod types;
2729

2830
pub use audit::AuditLogger;
2931
pub use identity::{AgentIdentity, PublicIdentity};
32+
pub use lifecycle::{LifecycleEvent, LifecycleManager, LifecycleState};
3033
pub use mcp::*;
3134
pub use policy::{PolicyEngine, PolicyError};
35+
pub use rings::{Ring, RingEnforcer};
3236
pub use trust::{TrustConfig, TrustManager};
3337
pub use types::{
3438
AuditEntry, AuditFilter, CandidateDecision, ConflictResolutionStrategy, GovernanceResult,

0 commit comments

Comments
 (0)