pub struct ManagedRuntime { /* private fields */ }Expand description
Unified container orchestrating AgentRuntime,
ComponentRegistry, and a root ShutdownToken.
Construct via the facade AgentConfigBuilder::build_managed helper or
ManagedRuntime::new.
§Lifecycle
new() → init_all → start_all → serve → signal_shutdown → stop_all§Hot-reload
ManagedRuntime::reload walks the drain-aware replace protocol:
old instance drains in-flight references, new instance is
constructed and started, then swapped in atomically.
Implementations§
Source§impl ManagedRuntime
impl ManagedRuntime
Sourcepub fn new(
runtime: AgentRuntime,
registry: ComponentRegistry,
shutdown: ShutdownToken,
) -> Self
pub fn new( runtime: AgentRuntime, registry: ComponentRegistry, shutdown: ShutdownToken, ) -> Self
Construct a new managed runtime from its constituent parts.
The caller is responsible for ensuring that the extensions
backing runtime and the registry are consistent (i.e. the
registry’s initialized components have already been applied to
the extensions).
Sourcepub fn runtime(&self) -> &AgentRuntime
pub fn runtime(&self) -> &AgentRuntime
Borrow the underlying AgentRuntime.
Sourcepub fn registry(&self) -> &ComponentRegistry
pub fn registry(&self) -> &ComponentRegistry
Borrow the ComponentRegistry.
Sourcepub fn shutdown_token(&self) -> ShutdownToken
pub fn shutdown_token(&self) -> ShutdownToken
Clone the root ShutdownToken.
Sourcepub fn extensions(&self) -> Arc<Extensions> ⓘ
pub fn extensions(&self) -> Arc<Extensions> ⓘ
Clone the Extensions facade from the underlying runtime.
Sourcepub fn component<T: Component>(
&self,
name: &str,
) -> Result<Arc<T>, ManagedError>
pub fn component<T: Component>( &self, name: &str, ) -> Result<Arc<T>, ManagedError>
Look up an initialized component by name, downcasting to a
concrete Arc<T>.
§Errors
ManagedError::ComponentNotFoundif the name is not registered or not yet initialized.ManagedError::Registryon type mismatch.
Sourcepub async fn serve(&self) -> Result<(), ManagedError>
pub async fn serve(&self) -> Result<(), ManagedError>
Serve until the root shutdown token fires.
Components are stopped in reverse dependency order after the shutdown signal is received.
§Errors
Returns the first error from component stop.
Sourcepub async fn health(&self) -> HashMap<String, HealthStatus>
pub async fn health(&self) -> HashMap<String, HealthStatus>
Aggregate health of every initialized component.
Sourcepub async fn is_healthy(&self) -> bool
pub async fn is_healthy(&self) -> bool
Returns true if every component reports healthy.
Sourcepub async fn overall_health(&self) -> HealthStatus
pub async fn overall_health(&self) -> HealthStatus
Aggregate all component health into a single
HealthStatus using worst-case semantics.
Returns Unhealthy if any component is unhealthy, Degraded
if any is degraded, Healthy otherwise (including empty).
Sourcepub async fn is_ready(&self) -> bool
pub async fn is_ready(&self) -> bool
Returns true if every component is at least operational
(healthy or degraded). This is the readiness gate suitable
for load-balancer probes.
Sourcepub async fn healthz_json(&self) -> Value
pub async fn healthz_json(&self) -> Value
Build a JSON /healthz response body containing the overall
status and per-component breakdown.
Sourcepub async fn reload<T: Component>(
&self,
name: &str,
new_instance: T,
) -> Result<Arc<T>, ManagedError>
pub async fn reload<T: Component>( &self, name: &str, new_instance: T, ) -> Result<Arc<T>, ManagedError>
Hot-reload a running component by replacing it with a new instance of the same type.
The drain-aware protocol:
- Calls
pre_replace_hookon the old instance. - Starts the new instance. If this fails, the old instance remains in place.
- Atomically swaps the instance in the registry. Existing
Arc<T>clones held by other tasks keep the old instance alive until dropped (natural drain). - Calls
post_replace_hookon the old instance (best-effort).
Returns the old Arc<T> so the caller can await explicit
cleanup or hold it for drain purposes.
§Errors
ManagedError::ComponentNotFoundif the name is not registered.ManagedError::Reloadif the component is not running, or if any phase of the replace protocol fails.
Sourcepub async fn reload_raw(
&self,
name: &str,
new_instance: Box<dyn AnyComponent>,
) -> Result<Arc<dyn AnyComponent>, ManagedError>
pub async fn reload_raw( &self, name: &str, new_instance: Box<dyn AnyComponent>, ) -> Result<Arc<dyn AnyComponent>, ManagedError>
Low-level hot-reload using a type-erased replacement.
This is the untyped counterpart of ManagedRuntime::reload:
the caller supplies a fully constructed Box<dyn AnyComponent>
instead of a typed T. Useful when the replacement was built
through a factory or configuration-driven path.