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_toolscounts 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
impl LiveAssembly
pub fn builder(
dir: impl Into<PathBuf>,
model: Arc<dyn ModelClient>,
alias: impl Into<String>,
) -> LiveBuilder
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
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>>
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>
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>
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
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>>
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>
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>
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
pub fn runs_on_previous_tools(&self) -> usize
How many runs are being stepped with a tool set that a reload has replaced.
Trait Implementations§
§impl Clone for LiveAssembly
impl Clone for LiveAssembly
§fn clone(&self) -> LiveAssembly
fn clone(&self) -> LiveAssembly
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for LiveAssembly
impl !UnwindSafe for LiveAssembly
impl Freeze for LiveAssembly
impl Send for LiveAssembly
impl Sync for LiveAssembly
impl Unpin for LiveAssembly
impl UnsafeUnpin for LiveAssembly
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].