Skip to main content

ManagedRuntime

Struct ManagedRuntime 

Source
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

Source

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).

Source

pub fn runtime(&self) -> &AgentRuntime

Borrow the underlying AgentRuntime.

Source

pub fn registry(&self) -> &ComponentRegistry

Borrow the ComponentRegistry.

Source

pub fn shutdown_token(&self) -> ShutdownToken

Clone the root ShutdownToken.

Source

pub fn extensions(&self) -> Arc<Extensions>

Clone the Extensions facade from the underlying runtime.

Source

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
Source

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.

Source

pub async fn health(&self) -> HashMap<String, HealthStatus>

Aggregate health of every initialized component.

Source

pub async fn is_healthy(&self) -> bool

Returns true if every component reports healthy.

Source

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).

Source

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.

Source

pub async fn healthz_json(&self) -> Value

Build a JSON /healthz response body containing the overall status and per-component breakdown.

Source

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:

  1. Calls pre_replace_hook on the old instance.
  2. Starts the new instance. If this fails, the old instance remains in place.
  3. Atomically swaps the instance in the registry. Existing Arc<T> clones held by other tasks keep the old instance alive until dropped (natural drain).
  4. Calls post_replace_hook on the old instance (best-effort).

Returns the old Arc<T> so the caller can await explicit cleanup or hold it for drain purposes.

§Errors
Source

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.

§Errors

See ManagedRuntime::reload.

Trait Implementations§

Source§

impl Debug for ManagedRuntime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more