[建议 / Feature] Nested subagents — let subagents spawn their own subagents (bounded depth)
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 22
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
提交前确认 · Pre-submission checklist
- I searched existing issues and Discussions and confirmed this isn't a duplicate. The nearest requests — #100 (concurrent agents + decision-maker) and #299 (cost-tiered executor fan-out) — both orchestrate from the main conversation; neither asks for subagent-initiated spawning. The other subagent issues I found are bugs (MCP access, config inheritance, permission prompts).
- I've read CONTRIBUTING.md.
ℹ️ The dropdown fields below could not be set via the
ghCLI. Please select them when reviewing:
- Category:
对话 / Agent 交互 · Agent chat / interaction- Agent framework:
ZCode Agent(自研)
Environment: Windows 11 x64 · ZCode desktop 3.7.7 · engine zcode.cjs 0.16.3 (build 81fa9054) · GLM Coding Plan channel.
使用场景 · Use case
Subagents today are strictly leaves: only the main conversation can dispatch subagents — a subagent cannot spawn further subagents, so a delegated task can never delegate.
This blocks three real workflow shapes:
- Orchestrator-as-subagent. Move an entire pipeline (plan → implement → review) into one coordinator subagent that owns and sequences specialist children, keeping the main conversation clean. Today the coordinator must be the main conversation itself — every intermediate result lands in the context the user actually reads, which is exactly the problem subagents exist to solve.
- Fan-out inside a delegated task. A reviewer subagent that spawns one fresh verifier per finding: each verification runs in a clean context and none of that noise reaches the main thread.
- Specialist lookup agents owned by worker subagents. For example a planning or implementation subagent that dispatches read-only code-graph verification subagents (the scout/verify/auditor tiers of codebase-memory-mcp).
Current workaround: flatten the pipeline into the main conversation (context bloat), or split it across manually created sessions (loses programmatic handoff).
建议方案 · Proposal
Make the dispatch tool grantable per subagent definition, with guards:
- Per-definition grant — allow the Agent (dispatch) tool in a subagent's
toolslist; omitting it keeps today's leaf behavior. At the depth limit, the tool is simply withheld from the child. - Bounded, configurable depth — conservative default (e.g. one nested layer below a top-level subagent), raised via a setting or env var.
- Runaway caps — max subagents per session and max concurrent subagents.
- Inheritance & safety — children inherit the parent's permission mode and tool allowlists; interactive approval stays at the main-conversation boundary (a nested agent must not be able to prompt the user).
- Observability — lineage on child sessions (ancestry marker in the session id,
parent_agent_idin payloads/spans) and a tree view in the subagent panel.
预期价值 · Value
Context management is the core value of subagents — as the Claude Code lead put it when shipping nesting there, "agents kicking off agents as a way to better manage context." Nesting pushes noisy intermediate work further from the conversation the user cares about: a deep run costs the main thread one summary regardless of how many children ran. It also composes with what ZCode already has or has requested — per-subagent model selection (#177, shipped) and cost-tiered executors (#299) become strictly more useful when a coordinator subagent can own them instead of the main conversation.
Parity
- Claude Code — nested subagents shipped in v2.1.172 (initially 5 levels); depth later made configurable (
CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH, current default 3 layers), with per-session (200) and concurrency (20) caps; the subagent panel renders the tree. Their defaults moved around (nesting off in 2.1.217–218, re-raised in 2.1.219), which suggests conservative default + knob is the workable middle ground. Docs: code.claude.com/docs/en/sub-agents, "Let subagents spawn their own subagents". - OpenAI Codex — supports nested agents with a user-configurable
max_depth(default 1).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the dispatch tool, subagent definitions, and related session or panel code in the repository; zcode.cjs and CONTRIBUTING.md are the only named files. Trace how top-level subagents receive tools and permissions before evaluating bounded depth, caps, inheritance, lineage, and tree display. Done means nested spawning is safely bounded, non-interactive, observable, and covered by appropriate tests.
Written by the indexing model from the issue text.
Assessment
- Domain
- ai-infra-agents
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100