子代理声明式规格 struct,对标 DeepAgents SubAgent TypedDict。
在创建父 Agent 时通过 CMDC.Options 的 :subagents 字段声明。
字段值为 nil 表示继承父 Agent 的对应配置。
快速开始
subagent = CMDC.SubAgent.new!(
name: "coder",
description: "专门负责写代码的子代理",
model: "anthropic:claude-opus-4-5",
tools: [CMDC.Tool.ReadFile, CMDC.Tool.WriteFile, CMDC.Tool.Shell]
)
CMDC.Options.new!(
model: "anthropic:claude-sonnet-4-5",
subagents: [subagent]
)字段说明
:name— 必填,子代理唯一标识名,用于tool_task调用时指定目标:description— 对父 Agent 可见的描述,用于 Task Tool 的工具描述生成:system_prompt— 子代理的系统提示词;nil 则继承父 Agent 的系统提示词:model— 子代理使用的模型;nil 则继承父 Agent 的 model:tools— 子代理可用工具列表;nil 则继承父 Agent 的 tools:plugins— 子代理的 Plugin 列表;nil 则继承父 Agent 的 plugins:skills_dirs— 子代理的 Skills 目录;nil 则继承父 Agent 的 skills_dirs:user_data— 子代理的业务上下文 map;nil 则继承父 Agent 的 user_data:prompt_mode— 系统提示词模式(v0.2 Phase 10B);默认:task(SubAgent 默认省 token), 可显式传入:full | :task | :minimal | :none覆盖,或传nil继承父 Agent
Summary
Functions
从 keyword list 构建 SubAgent struct,返回 {:ok, t()} 或 {:error, ...}。
从 keyword list 构建 SubAgent struct,校验失败时抛出异常。
将子代理规格与父 Agent Options 合并,nil 字段自动继承父值。
Types
@type t() :: %CMDC.SubAgent{ description: String.t() | nil, model: String.t() | nil, name: String.t(), plugins: [plugin_spec()] | nil, prompt_mode: CMDC.Options.prompt_mode() | nil, skills_dirs: [String.t()] | nil, system_prompt: String.t() | nil, tools: [module()] | nil, user_data: map() | nil }
Functions
@spec new(keyword()) :: {:ok, t()} | {:error, NimbleOptions.ValidationError.t()}
从 keyword list 构建 SubAgent struct,返回 {:ok, t()} 或 {:error, ...}。
从 keyword list 构建 SubAgent struct,校验失败时抛出异常。
示例
iex> CMDC.SubAgent.new!(name: "researcher", description: "负责信息收集")
%CMDC.SubAgent{name: "researcher", description: "负责信息收集", model: nil, ...}
@spec to_options(t(), CMDC.Options.t()) :: CMDC.Options.t()
将子代理规格与父 Agent Options 合并,nil 字段自动继承父值。
用于 Task Tool 启动子代理进程时构建完整 Options。