正在学习
smoke.sh — tiny post-deploy checks
9.1 Multi-Agent and Subagent Workflows
As software projects grow, a single AI assistant can only handle so much context before efficiency drops or responses become inconsistent. This is where multi-agent and subagent workflows come in—a system where multiple specialized Claude instances collaborate to complete complex development tasks. Instead of one Claude handling everything from documentation to deployment, you orchestrate a team of Claude-powered agents, each with a distinct role: a Planner for task decomposition, a Coder for implementation, a Reviewer for QA, and a Deployer for final rollout.
This chapter marks a major shift in your Claude usage—from using Claude as an individual assistant to building a team of coordinated AIs that think, communicate, and execute in parallel. By the end of this project, you’ll have a functioning Claude-based system capable of automating a software sprint: dividing work, writing code, testing, and merging—all under your supervision.
Concept Development
A multi-agent workflow mimics human team dynamics. Each agent specializes in one domain but collaborates through structured prompts and shared context. Claude’s subagents—spawned as separate, goal-driven processes—make this possible while maintaining isolation and focus.
For example:
- Planner Claude interprets user intent and creates a task breakdown.
- Coder Claude writes functional code for each task.
- Reviewer Claude checks logic, readability, and security.
- Deployer Claude runs tests, builds artifacts, and performs CI/CD actions.
By connecting these agents with clearly defined inputs and outputs, you achieve asynchronous or sequential collaboration similar to real-world DevOps teams. The key principle is context synchronization: each agent receives the relevant subset of project data without flooding Claude’s context window.
Claude Code supports such structured cooperation through prompt chaining and shared memory constructs, allowing you to design systems where each AI instance feeds the next intelligently.
Hands-On Example: Creating a Multi-Agent Workflow in Python
Let’s create a simple prototype that simulates Claude subagent collaboration using a clean and runnable Python script. In this scenario, the main agent delegates coding and review tasks to subagents and merges their outputs into a single deliverable.
from typing import Dict, Any
class ClaudeAgent:
def __init__(self, name: str):
self.name = name
def respond(self, message: str) -> str:
# In production, this would call Claude's API.
print(f"[{self.name}] received: {message}")
if "plan" in message.lower():
return "1. Write API routes\n2. Add validation\n3. Implement tests"
elif "implement" in message.lower():
return "Code snippet: def create_task(): pass"
elif "review" in message.lower():
return "The code passes structure and naming standards."
else:
return "Acknowledged."
# Instantiate subagents
planner = ClaudeAgent("Planner")
coder = ClaudeAgent("Coder")
reviewer = ClaudeAgent("Reviewer")
练习题
What is the primary benefit of using multi-agent and subagent workflows in software projects?
Which role in a Claude-powered multi-agent team is responsible for creating a task breakdown?
Select all the roles in a Claude-powered multi-agent team mentioned in the text.
The shift in Claude usage with multi-agent workflows means using Claude as an individual assistant rather than building a team of coordinated AIs.
The goal of a multi-agent Claude-based system is to automate a software sprint including dividing work, writing code, testing, and merging under supervision.
A multi-agent workflow mimics human team dynamics where each agent specializes in one domain but collaborates through structured prompts and shared ___.
Claude's subagents are spawned as separate, goal-driven processes while maintaining isolation and ___.
What is the key principle in multi-agent workflows for collaboration?
How does Claude Code support structured cooperation in multi-agent workflows?
Select all the tasks performed by Claude subagents mentioned in the text.
Which of the following is a benefit of using a multi-agent workflow in software development?
Select all the knowledge points that are related to the roles and tasks of Claude subagents in a multi-agent workflow.
Explain how the collaboration principle in multi-agent workflows ensures efficient teamwork among Claude subagents.
Select all the knowledge points that are related to the shift in Claude usage with multi-agent workflows and the goal of a multi-agent Claude-based system.
In a multi-agent Claude-powered workflow, which agent is primarily responsible for ensuring the security of the code by checking logic, readability, and security standards?
Which of the following are key principles for achieving effective collaboration in a multi-agent Claude workflow? (Select all that apply)
In a multi-agent Claude workflow, the Deployer Claude is responsible for interpreting user intent and creating a task breakdown.
登录后解锁笔记、知识点解析、AI 问答
立即登录