pub struct AgentSupervisor { /* private fields */ }Expand description
Manages a pool of agents with lifecycle operations.
Responsibilities:
- Spawn / terminate agents
- Persist snapshots via
SnapshotStore - Broadcast lifecycle events
- Supervise: auto-restart on failure (configurable)
Implementations§
Source§impl AgentSupervisor
impl AgentSupervisor
Sourcepub fn new(
resolver: Arc<dyn ProviderResolver>,
snapshot_store: Arc<dyn SnapshotStore>,
) -> Self
pub fn new( resolver: Arc<dyn ProviderResolver>, snapshot_store: Arc<dyn SnapshotStore>, ) -> Self
Create a new supervisor.
Sourcepub fn with_policy(
resolver: Arc<dyn ProviderResolver>,
snapshot_store: Arc<dyn SnapshotStore>,
policy: SupervisorPolicy,
) -> Self
pub fn with_policy( resolver: Arc<dyn ProviderResolver>, snapshot_store: Arc<dyn SnapshotStore>, policy: SupervisorPolicy, ) -> Self
Create with a specific restart policy.
Sourcepub fn with_agent_decorator(
self,
oxicode: Arc<Oxicode>,
decorator: Arc<dyn AgentDecorator>,
) -> Self
pub fn with_agent_decorator( self, oxicode: Arc<Oxicode>, decorator: Arc<dyn AgentDecorator>, ) -> Self
Attach an crate::Oxicode reference and an crate::observability::AgentDecorator
to this supervisor. Subsequent Self::spawn calls will
route through Oxicode::agent(config) + decorator.decorate()
instead of the bare Agent::new() fast path, so the
decorator’s audit / authorizer / tracer / cost hooks
actually run on every spawned agent.
Both must be supplied together — the decorator is only
effective when the supervisor has an Oxicode to bind the
builder against.
Sourcepub fn subscribe(&self) -> Receiver<AgentLifecycleEvent>
pub fn subscribe(&self) -> Receiver<AgentLifecycleEvent>
Subscribe to lifecycle events from all agents.
Sourcepub fn spawn(&self, config: AgentConfig) -> Result<AgentHandle>
pub fn spawn(&self, config: AgentConfig) -> Result<AgentHandle>
Spawn a new agent.
When the supervisor was configured with both an Oxicode reference
and an crate::observability::AgentDecorator (via
with_agent_decorator or
crate::builder::SupervisorBuilder::with_agent_decorator), this routes
through Oxicode::agent(config) and lets the decorator apply
audit / authorizer / tracer / cost hooks before .build().
Otherwise it takes the legacy fast path
(Agent::new(provider, config, tools)), which leaves
observability unset.
Sourcepub fn spawn_child(
&self,
parent_id: &str,
config: AgentConfig,
) -> Result<AgentHandle>
pub fn spawn_child( &self, parent_id: &str, config: AgentConfig, ) -> Result<AgentHandle>
Spawn a child agent linked to a parent (delegation lineage).
Sourcepub fn get(&self, agent_id: &str) -> Option<AgentHandle>
pub fn get(&self, agent_id: &str) -> Option<AgentHandle>
Get a handle by agent ID.
Sourcepub fn list(&self) -> Vec<(String, AgentStatus)>
pub fn list(&self) -> Vec<(String, AgentStatus)>
List all agents and their status.
Sourcepub fn count_by_status(&self) -> HashMap<AgentStatus, usize>
pub fn count_by_status(&self) -> HashMap<AgentStatus, usize>
Count agents by status.
Sourcepub async fn suspend(&self, agent_id: &str) -> Result<AgentSnapshot>
pub async fn suspend(&self, agent_id: &str) -> Result<AgentSnapshot>
Suspend and persist snapshot.
Sourcepub async fn restore(&self, agent_id: &str) -> Result<AgentHandle>
pub async fn restore(&self, agent_id: &str) -> Result<AgentHandle>
Restore agent from persisted snapshot.
Sourcepub async fn restore_from_snapshot(
&self,
snapshot: AgentSnapshot,
) -> Result<AgentHandle>
pub async fn restore_from_snapshot( &self, snapshot: AgentSnapshot, ) -> Result<AgentHandle>
Restore from an in-memory snapshot.
Sourcepub fn terminate(&self, agent_id: &str) -> Result<()>
pub fn terminate(&self, agent_id: &str) -> Result<()>
Terminate an agent and remove from the pool.
Sourcepub fn can_restart(&self, agent_id: &str) -> bool
pub fn can_restart(&self, agent_id: &str) -> bool
Check whether an agent can be auto-restarted based on the policy.
Returns true if:
max_restarts > 0- The number of restarts within the window is less than
max_restarts
Sourcepub async fn restart(&self, agent_id: &str) -> SdkResult<AgentHandle>
pub async fn restart(&self, agent_id: &str) -> SdkResult<AgentHandle>
Restart a failed agent with the same config.
Records the restart in the restart log and applies backoff delay. Returns the new handle on success.
Trait Implementations§
Source§impl Clone for AgentSupervisor
impl Clone for AgentSupervisor
Source§fn clone(&self) -> AgentSupervisor
fn clone(&self) -> AgentSupervisor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more