Skip to main content

AgentSpawner

Struct AgentSpawner 

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

Factory for creating agents at runtime from YAML, specs, or templates.

Implementations§

Source§

impl AgentSpawner

Source

pub fn new() -> AgentSpawner

Source

pub fn with_shared_llms(self, registry: LLMRegistry) -> AgentSpawner

Share LLM connections across all spawned agents.

Source

pub fn with_shared_storage(self, storage: Arc<dyn AgentStorage>) -> AgentSpawner

Share a storage backend (e.g. one SQLite DB for all NPCs).

Source

pub fn with_shared_context( self, key: impl Into<String>, value: Value, ) -> AgentSpawner

Inject a context value available to all spawned agents.

Source

pub fn with_shared_context_map( self, ctx: HashMap<String, Value>, ) -> AgentSpawner

Inject an entire map of shared context values.

Source

pub fn with_max_agents(self, max: usize) -> AgentSpawner

Limit total spawned agents.

Source

pub fn with_name_prefix(self, prefix: impl Into<String>) -> AgentSpawner

Auto-name agents with prefix + zero-padded counter.

Source

pub fn with_template( self, name: impl Into<String>, yaml_template: impl Into<String>, ) -> AgentSpawner

Register a named template from a plain YAML string (no metadata).

Source

pub fn with_templates( self, templates: HashMap<String, ResolvedTemplate>, ) -> AgentSpawner

Bulk-register resolved templates (with metadata already extracted).

Source

pub fn with_allowed_tools(self, tools: Vec<String>) -> AgentSpawner

Set the tool allowlist for spawned agents.

Source

pub async fn spawn_from_yaml( &self, yaml: &str, ) -> Result<SpawnedAgent, AgentError>

Spawn an agent from a YAML string.

Source

pub async fn spawn_from_spec( &self, spec: AgentSpec, ) -> Result<SpawnedAgent, AgentError>

Spawn an agent from a pre-built AgentSpec.

Source

pub async fn spawn_with_id( &self, id: String, spec: AgentSpec, ) -> Result<SpawnedAgent, AgentError>

Spawn an agent with a specific ID, used for session restore.

Source

pub async fn spawn_from_template( &self, template_name: &str, variables: HashMap<String, String>, ) -> Result<SpawnedAgent, AgentError>

Spawn from a named template with caller-provided variables.

Template rendering merges two namespaces:

  • Caller variables: top-level ({{ name }}, {{ role }})
  • Shared context: under context. prefix ({{ context.world_name }})
Source

pub fn spawned_count(&self) -> u32

Returns the current number of agents that have been spawned.

Source

pub fn notify_agent_removed(&self)

Decrement the agent count (called when an agent is removed from the registry).

Source

pub fn llm_registry(&self) -> Option<&LLMRegistry>

Returns a reference to the shared LLM registry, if configured.

Source

pub fn shared_storage(&self) -> Option<&Arc<dyn AgentStorage>>

Returns a reference to the shared storage, if configured.

Source

pub fn templates(&self) -> &HashMap<String, ResolvedTemplate>

Returns a reference to the resolved template map.

Trait Implementations§

Source§

impl Default for AgentSpawner

Source§

fn default() -> AgentSpawner

Returns the “default value” for a type. 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> 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<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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
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