Jido.Agent.Directive.SpawnAgent (Jido v2.0.0-rc.0)

View Source

Spawn 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 spawn
  • tag - Tag for tracking this child (used as key in children map)
  • opts - Additional options passed to child AgentServer
  • meta - 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

Functions

Returns the Zoi schema for SpawnAgent.

Types

t()

@type t() :: %Jido.Agent.Directive.SpawnAgent{
  agent: any(),
  meta: map(),
  opts: map(),
  tag: any()
}

Functions

schema()

@spec schema() :: Zoi.schema()

Returns the Zoi schema for SpawnAgent.