pub struct AgentSpawner { /* private fields */ }Expand description
Factory for creating agents at runtime from YAML, specs, or templates.
Implementations§
Source§impl AgentSpawner
impl AgentSpawner
pub fn new() -> AgentSpawner
Share LLM connections across all spawned agents.
Share a storage backend (e.g. one SQLite DB for all NPCs).
Inject a context value available to all spawned agents.
Inject an entire map of shared context values.
Sourcepub fn with_max_agents(self, max: usize) -> AgentSpawner
pub fn with_max_agents(self, max: usize) -> AgentSpawner
Limit total spawned agents.
Sourcepub fn with_name_prefix(self, prefix: impl Into<String>) -> AgentSpawner
pub fn with_name_prefix(self, prefix: impl Into<String>) -> AgentSpawner
Auto-name agents with prefix + zero-padded counter.
Sourcepub fn with_template(
self,
name: impl Into<String>,
yaml_template: impl Into<String>,
) -> AgentSpawner
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).
Sourcepub fn with_templates(
self,
templates: HashMap<String, ResolvedTemplate>,
) -> AgentSpawner
pub fn with_templates( self, templates: HashMap<String, ResolvedTemplate>, ) -> AgentSpawner
Bulk-register resolved templates (with metadata already extracted).
Sourcepub fn with_allowed_tools(self, tools: Vec<String>) -> AgentSpawner
pub fn with_allowed_tools(self, tools: Vec<String>) -> AgentSpawner
Set the tool allowlist for spawned agents.
Sourcepub async fn spawn_from_yaml(
&self,
yaml: &str,
) -> Result<SpawnedAgent, AgentError>
pub async fn spawn_from_yaml( &self, yaml: &str, ) -> Result<SpawnedAgent, AgentError>
Spawn an agent from a YAML string.
Sourcepub async fn spawn_from_spec(
&self,
spec: AgentSpec,
) -> Result<SpawnedAgent, AgentError>
pub async fn spawn_from_spec( &self, spec: AgentSpec, ) -> Result<SpawnedAgent, AgentError>
Spawn an agent from a pre-built AgentSpec.
Sourcepub async fn spawn_with_id(
&self,
id: String,
spec: AgentSpec,
) -> Result<SpawnedAgent, AgentError>
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.
Sourcepub async fn spawn_from_template(
&self,
template_name: &str,
variables: HashMap<String, String>,
) -> Result<SpawnedAgent, AgentError>
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 }})
Sourcepub fn spawned_count(&self) -> u32
pub fn spawned_count(&self) -> u32
Returns the current number of agents that have been spawned.
Sourcepub fn notify_agent_removed(&self)
pub fn notify_agent_removed(&self)
Decrement the agent count (called when an agent is removed from the registry).
Sourcepub fn llm_registry(&self) -> Option<&LLMRegistry>
pub fn llm_registry(&self) -> Option<&LLMRegistry>
Returns a reference to the shared LLM registry, if configured.
Returns a reference to the shared storage, if configured.
Sourcepub fn templates(&self) -> &HashMap<String, ResolvedTemplate>
pub fn templates(&self) -> &HashMap<String, ResolvedTemplate>
Returns a reference to the resolved template map.
Trait Implementations§
Source§impl Default for AgentSpawner
impl Default for AgentSpawner
Source§fn default() -> AgentSpawner
fn default() -> AgentSpawner
Auto Trait Implementations§
impl !Freeze for AgentSpawner
impl !RefUnwindSafe for AgentSpawner
impl Send for AgentSpawner
impl Sync for AgentSpawner
impl Unpin for AgentSpawner
impl UnsafeUnpin for AgentSpawner
impl !UnwindSafe for AgentSpawner
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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