daBongo LMS AI Training Courses

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:

  1. Parent agent: Coordinates sub-agents, provides context, aggregates results
  2. Sub-agents: Complete focused, scoped tasks and return results
  3. 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.md

Phase 2 – Aggregate:

  • Combine all findings into a single report
  • Deduplicate issues that appear in multiple analyses
  • Prioritize by severity across all finding types

Phase 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.

Practical Example

A developer builds a "pre-release audit" multi-agent workflow:

  • Phase 1 (parallel): security sub-agent, test coverage sub-agent, documentation coverage sub-agent
  • All three return structured findings in the same format
  • Phase 2: parent aggregates all findings into a single audit report, sorted by severity
  • Phase 3 (sequential, only if Phase 2 finds critical issues): a fix sub-agent for each critical finding

He runs this workflow before every major release.

The pre-release audit that previously took a full day of manual review takes ninety minutes of automated sub-agent execution plus thirty minutes of his review time.

The structured output format from all sub-agents makes the aggregation step trivial.

Safety Notes

Multi-agent workflows with write-access sub-agents in the remediation phase can make widespread, hard-to-review changes. For Phase 3 (remediation) sub-agents: always review the finding before spawning the remediation sub-agent, review the sub-agent's proposed changes before committing, and use feature branches so all changes can be reviewed as a unit in a PR. Automated multi-agent remediation without review is how AI-assisted technical debt compounds quickly.

Log in and enroll to access lesson quizzes.

Scroll to Top