Jido.Agent.Directive.SpawnAgent (Jido v2.0.0-rc.1)
View SourceSpawn a child agent with parent-child hierarchy tracking.
Unlike Spawn, this directive specifically spawns another Jido agent
and sets up the logical parent-child relationship:
- Child's parent reference points to the spawning agent
- Parent monitors the child process
- Parent tracks child in its children map by tag
- Child exit signals are delivered to parent as
jido.agent.child.exit
Fields
agent- Agent module (atom) or pre-built agent struct to spawntag- Tag for tracking this child (used as key in children map)opts- Additional options passed to child AgentServermeta- Metadata to pass to child via parent reference
Examples
# Spawn a worker agent
%SpawnAgent{agent: MyWorkerAgent, tag: :worker_1}
# Spawn with custom ID and initial state
%SpawnAgent{
agent: MyWorkerAgent,
tag: :processor,
opts: %{id: "custom-id", initial_state: %{batch_size: 100}}
}
# Spawn with metadata for the child
%SpawnAgent{
agent: MyWorkerAgent,
tag: :handler,
meta: %{assigned_topic: "events.user"}
}
Summary
Types
Functions
@spec schema() :: Zoi.schema()
Returns the Zoi schema for SpawnAgent.