nested-subagents
Skill này làm gì
Skill này hướng dẫn agent xây dựng một cây sub-agent sâu tới năm tầng, cho các bài toán lớn mà một agent sẽ bị quá tải bộ nhớ. Phù hợp với người có tác vụ phức tạp chia thành nhiều lớp.
Khi nào nên dùng
- ✓Khi một bài toán chia thành các lớp như nghiên cứu, mở rộng, kiểm tra và tóm tắt.
- ✓Khi ngữ cảnh của một agent không thể chứa hết các công việc trung gian.
- ✓Khi các phần khác nhau của công việc cần những vai trò chuyên gia khác nhau.
Liên kết skill
https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-agent/skills/nested-subagents/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Chia nghiên cứu thị trường này thành các lớp, với các sub-agent nghiên cứu, kiểm chứng và sau đó tóm tắt từng phần.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent khởi động một điều phối viên, điều phối viên này lên kế hoạch cho cây tác vụ trước, rồi tạo các agent con có thể tạo ra agent con của riêng chúng trong giới hạn độ sâu.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Nested Sub-Agents
Spawn a tree of sub-agents where each child can itself spawn children, up to 5 levels deep. The motivation is context management, not parallelism: each level gets a fresh context window so deep work doesn't blow the top-level agent's context budget.
When to use
- The problem decomposes into nested layers (research → expand → verify → synthesize), each of which would otherwise pollute the parent's context.
- A single agent's context window would not be enough to hold all the intermediate state.
- The leaves of the tree are different
subagent_types and need their own specialized prompts (e.g.,pii-detectorat one leaf,testerat another).
Skip this skill when flat fan-out (Task × N in one message) suffices — nesting adds latency.
Steps
Invoke the coordinator — spawn
nested-coordinatoras your top-level agent:Task({ subagent_type: "nested-coordinator", name: "root-coordinator", description: "Decompose and delegate <problem>", prompt: "<problem statement, with constraints and expected output shape>" })The coordinator decomposes first — it lays out the spawn tree via
TodoWritebefore anyTaskcall. Inspect the tree before approving deep work.Children spawn children — any
nested-coordinator(or any other agent whose YAML frontmatter declarestools: [..., Task]) can itself callTaskto spawn the next level. Leaf agents (withoutTaskin their tools list) cannot.Each level reports a summary — children return ~200-token structured summaries, not full transcripts. The whole point is to keep the parent's context clean.
Tree shape is persisted — the
post-taskhook writesparent_agent_idanddepthto AgentDB on every spawn (ADR-147 P2). Query after the run for cost attribution and pattern learning.
Depth budget
| Source | Limit |
|---|---|
| Anthropic API | 5 levels (announced 2026-06-09) |
Ruflo default (pre-task hook) |
4 levels — one-level guard band, configurable in claude-flow.config.json |
| Strict-mode env var | CLAUDE_FLOW_STRICT_NESTING=true to enforce the ruflo cap |
The hook returns a typed NESTING_DEPTH_EXCEEDED error at the cap, with the full chain in the payload so the parent can decide to summarize, hand off, or abort.
Benefits
- Context isolation per level — top-level coordinator never sees inner chatter; leaf summaries climb back up.
- Deeper delegation without re-summarization — eliminates the "summarize at level 1 to fit it all" anti-pattern that flat fan-out forces.
- Tree-shaped cost attribution —
parent_agent_idlineage gives accurate per-tree spend, not just flat per-agent. - Maps cleanly onto ruflo's existing orchestrators —
ruflo-sparc:sparc-orchestrator(5 phases ≈ 5 levels),ruflo-goals:dossier-investigator(recursive entity expansion),v3-queen-coordinator(hierarchical-mesh top).
Anti-patterns (do NOT)
- Pass
Taskto leaf agents. Leaves must not spawn. Add the leaf'ssubagent_typedirectly under the coordinator instead. - Wrap a Tier-1 codemod in a coordinator. Codemods (
hooks_codemod) are depth-0 deterministic transforms — never put them inside a spawn tree. - Nest "for cleanliness". A premature nesting layer wastes latency and cost without saving context. If one agent can do the work, use one agent.
- Return full transcripts from a child. That defeats the entire purpose of nesting. Children return structured summaries.
Related
- Agent:
ruflo-agent:nested-coordinator— the orchestrator - ADR-147 — design rationale and four-phase rollout
- ADR-144 — authorization propagation shares the depth counter as
AuthScope.delegationDepth - ADR-099 — dossier investigator (recursive parallel research) is the textbook deep use case
Câu hỏi thường gặp
Tại sao dùng lồng ghép thay vì chạy các agent song song?
Skill nói rằng lồng ghép dùng để quản lý ngữ cảnh chứ không để tăng tốc, vì mỗi tầng có một cửa sổ ngữ cảnh mới.
Có thể đi sâu đến đâu?
Tối đa năm tầng.
Khi nào tôi nên bỏ qua nó?
Skill nói rằng nên bỏ qua khi một tập tác vụ song song đơn giản là đủ, vì lồng ghép làm tăng thời gian.
Chi tiết
Mô tả gốc của tác giả
Spawn nested sub-agents (agents that spawn sub-agents, up to depth=5) via Claude Code's native Task tool — for context-managed deep delegation
repo: ruvnet/ruflo
Độ phổ biến
- Sao GitHub
- 81k
- Vị trí xếp hạng
- #1558
- Giấy phép
- MIT
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
agent-adaptive-coordinator
81kGiúp agent của bạn chia và cân bằng lại một nhóm agent AI khi khối lượng công việc thay đổi, chọn bố cục phù hợp với tác vụ.
agent-agent
81kDạy agent của bạn biến một mục tiêu lớn thành kế hoạch hành động có thứ tự, và lập lại kế hoạch khi điều kiện thay đổi.
agent-agentic-payments
81kGiúp agent của bạn quản lý ủy quyền chi tiêu cho mua sắm bằng AI, với hạn mức chi, khung thời gian, quy tắc người bán và phê duyệt có chữ ký.
agent-analyze-code-quality
81kGiúp agent của bạn rà soát chất lượng mã, tìm code smell, nợ kỹ thuật và gợi ý tái cấu trúc mà không thay đổi các file.
Skill tương tự
add-model-provider
394kGiúp agent của bạn kết nối nhà cung cấp mô hình AI mới với OpenClaw bằng lệnh an toàn, giữ API key khỏi văn bản thuần và chạy thử.
acp-router
394kGiúp agent của bạn gửi một tác vụ đến trợ lý lập trình như Claude Code hoặc Cursor qua OpenClaw, để công việc chạy ngay trong công cụ đó.
browser-automation
394kHướng dẫn agent của bạn điều khiển trang web từng bước, gồm đăng nhập, tab và cách khôi phục khi trang ngừng phản hồi.