Skip to main content

OperatorSpawnerFactory

Struct OperatorSpawnerFactory 

Source
pub struct OperatorSpawnerFactory { /* private fields */ }
Expand description

Factory for AgentKind::Operator. Looks up the Arc<dyn Operator> pre-registered under spec.operator_ref and wraps it in an OperatorSpawner. Also resolves AgentDef.profile.worker_binding into a WorkerBinding at compile time and fails loud (CompileError::InvalidSpec) when the resolved operator’s Operator::requires_worker_binding is true and no binding was declared.

Spec shape:

{ "operator_ref": "main_ai" }     // Operator id pre-registered with the factory

§The only axis that reaches an Operator

This factory (OperatorSpawnerFactoryOperatorSpawner) is the AgentSpec axis: a kind = Operator AgentDef names its seat through spec.operator_ref, and at compile() time an Arc<dyn Operator> for that seat is placed in routes[agent_name]. Because the agent.md loader (agent_md_loader) defaults kind to Operator, agents that flow in through external agent.md files land here.

There was a second axis until recently: OperatorDelegateMiddleware, opted into with spawner_hints.layers = ["operator_delegate"], which ignored ctx.agent and handed every spawn in the session to one backend named at launch. When both were effective it sat at the outer end of the stack and bypassed inner.spawn entirely, leaving this factory’s routes entry inert — so the two axes needed an exclusivity story, and an author needed to know which one a given Blueprint was actually running on.

That axis was removed (it resolved its destination from the launch record rather than the Run’s seat, so a handover could not move it, and it had no per-agent spawner with which to render an agent’s system_prompt). Declaring its key is now a CompileError::RemovedSpawnerHint. One axis remains, so there is no exclusivity rule left to get wrong: if a dispatch reaches an Operator, it reached it through the agent’s declared seat.

§Who answers spec.operator_ref — resolver first, registry second

spec.operator_ref names a Blueprint-declared seat (Blueprint.operators[]), and a seat’s holder is per-Run, mutable state. Two ways to answer it:

  • A OperatorSlotResolver installed via Self::set_slot_resolver — the host hands back an indirection that resolves the seat’s current holder on every dispatch (mlua-swarm-server’s AssigneeRouter). What this factory bakes into routes[agent_name] is then “the seat”, not “the session that held it when the Blueprint compiled” — model §4.3 A10. This is the wiring mse serve uses.
  • This factory’s own id → Arc<dyn Operator> map (no resolver installed) — the direct binding used by hosts with no Run store to resolve holders against: mse bp doctor’s lint stubs, in-process embeddings, tests.

The two never mix within one build: an installed resolver that cannot serve a seat fails the compile rather than falling through to the map, because falling through is exactly how a dispatch ends up at a backend the caller never named.

Interior mutability is provided by Arc<RwLock>s. Even after the factory has been stored as Arc<dyn SpawnerFactory> in SpawnerRegistry, a caller holding an Arc clone can still add Operator backends dynamically via register_operator(&self, id, op) or install the resolver. build() performs a read() lookup each time.

Implementations§

Source§

impl OperatorSpawnerFactory

Source

pub fn new() -> Self

Start with no registered Operator backends and no slot resolver.

Source

pub fn set_slot_resolver( &self, resolver: Arc<dyn OperatorSlotResolver>, ) -> &Self

Install the OperatorSlotResolver every kind = Operator agent’s spec.operator_ref is answered through from now on (see the struct doc). Installing replaces any previous resolver.

Takes &self on purpose: the host builds its factory before it has a RunStore to resolve holders against (the router builder resolves the store), and the same Arc is already inside a SpawnerRegistry by then.

Source

pub fn resolve_operator( &self, slot: &str, agent: &str, ) -> Result<Arc<dyn Operator>, CompileError>

The Arc<dyn Operator> a kind = Operator agent declaring operator_ref = slot dispatches through — the single lookup SpawnerFactory::build performs, exposed so a host can assert what its wiring resolves to without standing up a compile.

agent only shapes the error message (CompileError::InvalidSpec is keyed by agent name).

Source

pub fn register_operator( &self, id: impl Into<String>, op: Arc<dyn Operator>, ) -> &Self

Register an Operator backend dynamically through &self. Overwrites are allowed — later wins. Callers can still reach this after the factory has been stored as Arc<dyn SpawnerFactory> in SpawnerRegistry, as long as they hold an Arc clone; interior mutability is provided by the inner RwLock.

Source

pub fn unregister_operator(&self, id: &str) -> &Self

Dynamically unregister an id (used to clean up when a WebSocket disconnects, for example). A missing id is a no-op.

Trait Implementations§

Source§

impl Default for OperatorSpawnerFactory

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl SpawnerFactory for OperatorSpawnerFactory

Source§

fn build( &self, agent_def: &AgentDef, _hint: Option<&Value>, ) -> Result<Arc<dyn SpawnerAdapter>, CompileError>

No build hint is read here: an Operator agent’s whole input is its declared seat (spec.operator_ref) plus its profile. The hint slot used to carry a launch-scoped session pin, which was the compile baking a destination — see the struct doc.

Source§

impl SpawnerFactoryKind for OperatorSpawnerFactory

Source§

const KIND: AgentKind = AgentKind::Operator

The AgentKind this factory handles — used as the HashMap key by SpawnerRegistry::register.
Source§

type Worker = OperatorWorker

The concrete Worker type produced by this AgentKind — this binds the type chain all the way from AgentKind down to Worker. Every factory declares it so the AgentKind → Worker mapping is explicit across all four layers. It is the source of truth for preserving the concrete type right up until SpawnerAdapter::spawn erases it into Box<dyn Worker>.

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> 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
Source§

impl<T> MaybeSend for T

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

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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