Sub-Agents in Claude Code – Context, Delegation, and Focus
Lesson 4: Building Multi-Agent Workflows
Lesson Objectives
By the end of this lesson, students should be able to:
- Design a multi-agent workflow for a complex task
- Identify which sub-agents can run in parallel vs. must run sequentially
- Implement a parent-aggregates pattern for multi-agent output
- Recognize when a workflow is too complex for current sub-agent tooling
Lesson Content
Multi-agent workflow design.
A multi-agent workflow has three layers:
- Parent agent: Coordinates sub-agents, provides context, aggregates results
- Sub-agents: Complete focused, scoped tasks and return results
- Synthesis: Parent uses sub-agent results to produce final output
Design starts with decomposition: what are the distinct subtasks that benefit from focused context? Each distinct subtask is a candidate for a sub-agent.
Parallel vs. sequential sub-agents.
Parallel: Sub-agents that do not depend on each other's results can run simultaneously. A security sub-agent and a performance sub-agent analyzing the same codebase are independent – run them in parallel to save time.
Sequential: Sub-agents where the output of one informs the input of the next must run in order. A "discover failing tests" sub-agent must complete before a "fix failing tests" sub-agent can be scoped – it needs the list of failing tests.
Most multi-agent workflows have both patterns: some parallel sub-agents in the analysis phase, some sequential in the remediation phase.
The parent-aggregates pattern.
The parent agent should not attempt complex reasoning during aggregation – it should collect structured sub-agent outputs and combine them:
Phase 1 – Spawn and run parallel analysis sub-agents:
– Security sub-agent -> findings_security.md
– Performance sub-agent -> findings_performance.md
– Coverage sub-agent -> findings_coverage.mdPhase 2 – Aggregate:
– Combine all findings into a single report
– Deduplicate issues that appear in multiple analyses
– Prioritize by severity across all finding typesPhase 3 – Remediation (optional):
– Spawn remediation sub-agents for high-severity items
– Each remediation sub-agent receives the specific finding it addresses
Knowing when the workflow is too complex.
Multi-agent workflows have coordination overhead. If the workflow requires more than four to five sub-agents, complex dependency management, or multiple aggregation phases – consider whether the task can be decomposed differently, or whether the complexity warrants a more formal orchestration approach than ad-hoc Cowork mode sub-agents.
Enroll to continue this lesson.
The preview above shows the lesson objectives and opening lesson content. Enroll to view the full lesson, complete the practice work, and take the lesson quiz.
