Sagents.SubAgentsDynamicSupervisor (Sagents v0.8.0-rc.6)

Copy Markdown

DynamicSupervisor for managing ephemeral sub-agent processes.

SubAgentsDynamicSupervisor provides isolated execution environments for sub-agents spawned during task delegation. Each sub-agent runs independently with its own conversation context while sharing the parent's filesystem.

Purpose

  • Dynamic spawning: Creates sub-agent processes on-demand
  • Isolation: Each sub-agent runs in its own process
  • Clean lifecycle: Sub-agents are automatically cleaned up after completion
  • Fault tolerance: Sub-agent crashes don't affect parent agent

Usage

This supervisor is automatically started by AgentSupervisor and typically not used directly. The SubAgent middleware interacts with it to spawn sub-agent processes.

Examples

# Started automatically by AgentSupervisor
{:ok, sup_pid} = AgentSupervisor.start_link(agent: agent)

# SubAgent middleware will use this supervisor internally
# to spawn ephemeral sub-agent processes

Summary

Functions

Returns a specification to start this module under a supervisor.

Get the name of the SubAgentsDynamicSupervisor process for a specific agent.

Start the SubAgentsDynamicSupervisor.

Get the SubAgentsDynamicSupervisor PID for an agent.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_name(agent_id)

Get the name of the SubAgentsDynamicSupervisor process for a specific agent.

Examples

name = SubAgentsDynamicSupervisor.get_name("agent-123")
# => {:via, Registry, {Sagents.Registry, {:sub_agents_supervisor, "agent-123"}}}

start_link(opts)

@spec start_link(keyword()) :: Supervisor.on_start()

Start the SubAgentsDynamicSupervisor.

Options

  • :agent_id - The parent agent's ID (required)
  • :name - Supervisor name registration (optional)

Examples

{:ok, pid} = SubAgentsDynamicSupervisor.start_link(agent_id: "agent-123")

{:ok, pid} = SubAgentsDynamicSupervisor.start_link(
  agent_id: "agent-123",
  name: SubAgentsDynamicSupervisor.get_name("agent-123")
)

whereis(agent_id)

@spec whereis(String.t()) :: pid() | nil

Get the SubAgentsDynamicSupervisor PID for an agent.

Returns the PID if found, nil otherwise.

Examples

pid = SubAgentsDynamicSupervisor.whereis("agent-123")