LemonAgent. SubagentSupervisor
(lemon_agent v0.1.0)
View Source
Dynamic supervisor for managing subagent processes.
This module provides a DynamicSupervisor for starting and managing subagent processes. Subagents are started as temporary children (no automatic restart on failure) since they are typically short-lived task-oriented processes.
Usage
# Start a subagent with LemonAgent.Agent options
{:ok, pid} = SubagentSupervisor.start_subagent(
model: model,
tools: tools,
system_prompt: "You are a research agent..."
)
# Stop a subagent
:ok = SubagentSupervisor.stop_subagent(pid)
# List all subagents
pids = SubagentSupervisor.list_subagents()
Summary
Functions
Returns a specification to start this module under a supervisor.
Count the number of active subagents.
List all subagent PIDs under this supervisor.
Start a subagent with a specific child spec.
Start the subagent supervisor.
Start a new subagent under the supervisor.
Stop all subagents.
Stop a subagent by PID.
Stop a subagent by its registry key.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec count() :: non_neg_integer()
Count the number of active subagents.
@spec list_subagents() :: [pid()]
List all subagent PIDs under this supervisor.
Examples
pids = SubagentSupervisor.list_subagents()
@spec start_child(Supervisor.child_spec() | {module(), term()} | module()) :: DynamicSupervisor.on_start_child()
Start a subagent with a specific child spec.
This allows more control over the child specification.
Examples
child_spec = %{
id: :my_subagent,
start: {LemonAgent.Agent, :start_link, [opts]},
restart: :temporary
}
{:ok, pid} = SubagentSupervisor.start_child(child_spec)
@spec start_link(keyword()) :: Supervisor.on_start()
Start the subagent supervisor.
This is typically called by the application supervisor.
@spec start_subagent(keyword()) :: DynamicSupervisor.on_start_child()
Start a new subagent under the supervisor.
The subagent is started as a temporary child (not restarted on failure).
Options are passed directly to LemonAgent.Agent.start_link/1.
Options
All options supported by LemonAgent.Agent.start_link/1:
:model- The AI model to use:tools- List of available tools:system_prompt- The system prompt:messages- Initial messages- etc.
Additional options:
:registry_key- Optional{session_id, role, index}key for registration
Examples
{:ok, pid} = SubagentSupervisor.start_subagent(
model: model,
tools: tools,
system_prompt: "You are a research agent..."
)
@spec stop_all() :: :ok
Stop all subagents.
This terminates all children of the supervisor.
Examples
:ok = SubagentSupervisor.stop_all()
@spec stop_subagent(pid()) :: :ok | {:error, :not_found}
Stop a subagent by PID.
Returns :ok on success or {:error, :not_found} if the process
is not a child of this supervisor.
Examples
:ok = SubagentSupervisor.stop_subagent(pid)
@spec stop_subagent_by_key(LemonAgent.AgentRegistry.key()) :: :ok | {:error, :not_found}
Stop a subagent by its registry key.
Examples
:ok = SubagentSupervisor.stop_subagent_by_key({session_id, :research, 0})