Skip to main content

LiveAssembly

Struct LiveAssembly 

pub struct LiveAssembly { /* private fields */ }
Expand description

The agents of a directory, reloaded when its files change. Only with the feature dev.

§The swap and durable replay

A run is durable: its journal is keyed by step names (model:3, tool:<call id>), and a transition that is replayed (a lease lost, a stale commit) must take the same steps. The prompt is not journaled, and the model request is rebuilt on every turn, so a new prompt, new limits, a new model alias, a new tool description or a rotated token apply to every run at its next step. What would break a replay is a change to which tools exist: a replayed transition that finds a journaled tool:c1 where its code now answers “unknown tool” fails with NonDeterminism. So the rule is:

  • The tool set of an agent is its tools’ names. Agents with the same tool set are interchangeable for any run, and a reload with an unchanged tool set swaps for everyone.
  • When a reload changes the tool set of an agent, runs that already took a step of it keep the version with the tool set they started with, for as long as they live; runs that start later (and runs no process has stepped yet) get the new one. The old version stays as it was at the reload, except that a later reload that goes back to the same tool set updates it again. LiveAssembly::runs_on_previous_tools counts those runs.
  • A new agent name (a new subagent, a renamed root) cannot be served: the runtime registers its agents once, at build. Such a reload is refused as a whole with ReloadError::NeedsRestart, and the last good version stays.
  • A removed agent stays registered with its last version, for the runs that are on it and for the parents that still have the tool for it (a run pinned to the old tool set). It is listed by LiveAssembly::retired. A run never fails because a file went away.
  • A restart is a deploy: the pins are in memory, and a new process loads the files as they are and steps every run with them, as a production deploy of new code does.

The pins are dropped when a run ends (done, failed, or failed for good with a permanent error). A run that is cancelled while nobody is stepping it leaves a small entry until the process ends, and keeps an old version alive with it; that is a development tool’s price.

§Not for production

The feature is off by default, so a release build cannot watch and reload prompts unless its author turned it on; turning it on logs a warning at startup. (Reading a folder once, when the process starts, needs no feature: AgentFolder.) Tool code is Rust and changes with a rebuild. mcp.json tools are connected once, at startup (LiveBuilder::connect_mcp, feature mcp), and the connections outlive reloads: an edit of mcp.json is refused with a message that says to restart, because a tool discovered at startup is not looked up again (and a run in flight may have called it).

use std::sync::Arc;
use adam_assembly::LiveAssembly;
use adam_model::MockModel;
use adam_runtime::Runtime;

let live = LiveAssembly::builder(&root, model, "my-model").load()?;
let runtime = live.register(Runtime::builder(store)).build(); // stable names, current version
let _watch = live.watch()?; // keep it alive; dropping it stops the watching

// An edit is loaded when the files have been quiet for a moment, and `reload` does it now.
std::fs::write(root.join("agent/instructions.md"), "---\nname: helper\n---\nBe thorough.\n")?;
live.reload().map_err(|e| e.to_string())?;
assert_eq!(live.info()[0].prompt, "Be thorough.");

Implementations§

§

impl LiveAssembly

pub fn builder( dir: impl Into<PathBuf>, model: Arc<dyn ModelClient>, alias: impl Into<String>, ) -> LiveBuilder

Start describing a live assembly of the agents in dir (the directory that holds agent/ or agents/, or that directory itself), talking to model under the gateway alias alias when an agent names none: the arguments of BoundDef::model. The environment variable AGENT_DIR_ENV replaces dir when it is set.

pub fn register(&self, builder: RuntimeBuilder) -> RuntimeBuilder

Register every agent (the roots and each subagent) on a runtime builder, by the names they had when the process started. What the runtime steps is not an LlmAgent but a stand-in that takes the current version at each step.

pub fn reload(&self) -> Result<Reloaded, Arc<ReloadError>>

Load the files again now, exactly as a watched change does: on success the versions are swapped, on failure nothing changes. Either way the outcome is logged, and a failure is kept for last_error. It reads the disk on the calling thread.

§Errors

A ReloadError, shared with last_error.

pub fn watch(&self) -> Result<Watch, WatchError>

Start watching the agent directory: a change loads the files, once they have been quiet for the debounce. The watching stops when the returned [Watch] is dropped. Failures of a reload are logged and kept for last_error.

§Errors

[WatchError] when there is nothing to watch or the platform refuses.

pub fn schedules(&self) -> Vec<Schedule>

The schedules of the roots in force (ADR 0060): those of the first load, then of each reload that swapped (a refused reload keeps them). LiveAssembly runs none of them: a host that runs schedules registers adam_schedule::SchedulerAgent::new(root) for each root on its runtime, and after a reload (when generation moves) calls adam_schedule::reconcile with these for every root of the first load, the retired ones included: a root a reload removed has none here, and its empty list cancels its schedulers (a reload cannot add a root, so the set is the startup one). reconcile is idempotent, so a reload between reading the generation and these is harmless; it can still refuse a schedule the loader took (ReconcileError::Schedule), and the scheduler runs then stay as they were.

pub fn generation(&self) -> u64

The number of loads that succeeded: 1 after startup, and one more for each reload that swapped. A reload that was refused leaves it as it was.

pub fn last_error(&self) -> Option<Arc<ReloadError>>

Why the last reload was refused; None when it succeeded (or none has run). The diagnostics are in ReloadError::diagnostics.

pub fn info(&self) -> Vec<AgentInfo>

What the agents in force were made from: the root of each package, then its subagents. Retired agents are not listed.

pub fn retired(&self) -> Vec<String>

Agents that are registered but no longer in the files: they keep their last version.

pub fn runs_on_previous_tools(&self) -> usize

How many runs are being stepped with a tool set that a reload has replaced.

pub fn dir(&self) -> &Path

The directory being read.

Trait Implementations§

§

impl Clone for LiveAssembly

§

fn clone(&self) -> LiveAssembly

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for LiveAssembly

§

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

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

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

§

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
§

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> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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