CMDC.SubAgent.Supervisor (cmdc v0.4.1)

Copy Markdown View Source

子代理进程树动态监督者。

使用 DynamicSupervisor 管理子代理进程的生命周期。 每个子代理对应一个独立的 CMDC.Agent 进程,崩溃不传染父 Agent。

进程树位置

CMDC.SessionServer (:one_for_one)
 CMDC.SubAgent.Supervisor    此模块
    CMDC.Agent (sub-coder)
    CMDC.Agent (sub-researcher)
    ...
 CMDC.Agent (main)

示例

{:ok, sup} = CMDC.SubAgent.Supervisor.start_link([])
{:ok, pid} = CMDC.SubAgent.Supervisor.start_child(sup, agent_opts)
:ok = CMDC.SubAgent.Supervisor.stop_child(sup, pid)
[pid1, pid2] = CMDC.SubAgent.Supervisor.list_children(sup)

Summary

Functions

Returns a specification to start this module under a supervisor.

返回活跃子代理数量。

列出此监督者下所有活跃子代理 pid。

在此监督者下启动一个子代理进程。

启动 SubAgent 动态监督者。

停止指定 pid 的子代理进程。

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

count(supervisor)

@spec count(pid() | atom()) :: non_neg_integer()

返回活跃子代理数量。

list_children(supervisor)

@spec list_children(pid() | atom()) :: [pid()]

列出此监督者下所有活跃子代理 pid。

start_child(supervisor, agent_opts)

@spec start_child(
  pid() | atom(),
  keyword()
) :: DynamicSupervisor.on_start_child()

在此监督者下启动一个子代理进程。

agent_opts 为传递给 CMDC.Agent.start_link/1 的选项列表, 必须包含 :session_id 字段。

返回 {:ok, pid}{:error, reason}

start_link(opts)

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

启动 SubAgent 动态监督者。

stop_child(supervisor, child_pid)

@spec stop_child(pid() | atom(), pid()) :: :ok | {:error, :not_found}

停止指定 pid 的子代理进程。

进程不存在时返回 :ok(幂等)。