Claude Architect · 강의

하위 에이전트 병렬 생성

한 응답에 포함된 여러 Task 호출은 동시에 실행됩니다

레슨 4/413개 단계

하위 에이전트 병렬 생성은(는) CoddyKit의 무료 Claude Architect 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Claude Architect 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Claude Architect 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Why Parallelism Matters

In a hub-and-spoke multi-agent system, a coordinator decomposes a task, delegates pieces to subagents, then aggregates the results. The key performance lever: multiple Task calls emitted in one response run concurrently.

If a research job needs three independent lookups, you don't have to do them one after another. Spawn all three in a single turn and they execute in parallel, collapsing three round-trips into one wave.

The Parallel Rule

The rule is precise: every Task call the model emits in the same assistant response is dispatched at the same time. There is no special API flag — concurrency is a property of how many Task calls share one response.

  • Three Task calls in one response → three subagents run in parallel.
  • One Task call, wait for the result, then another Task call next turn → sequential.

So parallelism is a decomposition decision, not a configuration toggle.

Coordinator Must Allow Task

A coordinator can only spawn subagents if its allowedTools includes "Task". Without it, the model has no mechanism to delegate and will try to do everything itself.

This is part of least-privilege design: only the coordinator gets Task; leaf subagents usually do not, so they can't recursively spawn more agents.

from claude_agent_sdk import AgentDefinition

coordinator = AgentDefinition(
    name="research_coordinator",
    description="Decomposes a research question and delegates to subagents in parallel.",
    system_prompt="Break the question into independent sub-questions and spawn one subagent per topic IN A SINGLE RESPONSE.",
    allowed_tools=["Task"],  # required to spawn subagents
)

Subagents Don't Inherit History

This is the single most-tested fact about subagents: a subagent does NOT inherit the coordinator's conversation history. It starts with a clean context.

Therefore all context a subagent needs must be passed explicitly in its prompt — the question, relevant constraints, prior findings, output format. If you assume the subagent "already knows" what the coordinator discussed, it will hallucinate or under-perform.

Self-Contained Subagent Prompts

Because context isn't inherited, each parallel Task prompt should be fully self-contained. Notice how each spawned subagent below carries its own topic and the same explicit instructions — nothing is left implicit.

# Coordinator emits these THREE Task calls in ONE response -> they run in parallel
tasks = [
    Task(agent="researcher",
         prompt="Topic: 2024 EV battery cost trends.\n"
                "Return: 3 findings, each with source URL + publication date."),
    Task(agent="researcher",
         prompt="Topic: solid-state battery timelines.\n"
                "Return: 3 findings, each with source URL + publication date."),
    Task(agent="researcher",
         prompt="Topic: lithium supply constraints 2025.\n"
                "Return: 3 findings, each with source URL + publication date."),
]

When Parallel Is Correct

Parallel spawning is the right move when sub-tasks are independent — none needs the output of another.

  • Multi-topic research: each topic is its own lane.
  • Per-file local code review: review each file independently in parallel, then a separate cross-file integration pass.
  • Fan-out lookups: several catalogs or APIs queried at once.

If task B needs A's result, that's a sequential dependency — use a fixed pipeline / prompt chaining instead, not parallel spawning.

Parallel vs. Sequential Decomposition

Match the decomposition pattern to the work:

  • Parallel Task fan-out → independent subtasks, latency-sensitive, results merged at the end.
  • Fixed pipeline / prompt chaining → known sequential steps where each feeds the next.
  • Adaptive decomposition → open-ended investigation where the next step depends on what you just found.

Forcing inherently sequential steps into one parallel wave produces agents working with missing inputs — a correctness bug, not a speedup.

# Sequential: step 2 NEEDS step 1's output -> chain, do NOT parallelize
# 1) fetch the schema, THEN 2) extract rows against that schema
schema = Task(agent="schema_reader", prompt="Return the orders table schema.")
# ...wait for result, then next turn:
extract = Task(agent="extractor",
               prompt=f"Using this schema:\n{schema}\nExtract Q1 orders.")

Aggregating Parallel Results

After a parallel wave returns, the coordinator's job is to aggregate: merge the findings, deduplicate, and resolve conflicts. Don't arbitrarily pick one number when two subagents disagree — annotate the conflict (dates often resolve apparent contradictions).

The coordinator also routes follow-ups: if one lane came back thin, it can spawn a targeted second wave.

# After the parallel wave, the coordinator receives all three result blocks
# and synthesizes. Keep claim -> source mappings for provenance.
synthesis_prompt = (
    "You have results from 3 parallel researchers below.\n"
    "Merge into one report. For each claim keep its source URL + date.\n"
    "If two sources conflict, annotate both rather than picking one."
)

Partial Failure in a Parallel Wave

When you fan out, one lane may fail while others succeed. Do not abort the whole workflow on a single failure, and never silently suppress it.

  • Recover transient faults locally inside the subagent (retry).
  • Escalate non-recoverable failures with partial results and structured context: failure type, attempted query, what did succeed.

The coordinator should annotate coverage gaps ("topic 2 unavailable") rather than presenting incomplete output as complete.

# A subagent returns STRUCTURED context on failure, not a silent drop
{
    "isError": True,
    "errorCategory": "transient",      # transient|validation|business|permission
    "isRetryable": True,
    "message": "Search API timed out",
    "attempted_query": "solid-state battery timelines",
    "partial_results": ["1 finding retrieved before timeout"],
}

Least-Privilege Subagents

Each subagent's allowed_tools should be scoped to its role — least privilege. A researcher needs read/search tools; it does not need Task (no recursive spawning) and it does not need write or refund tools.

Remember the tool-count guideline: 4-5 tools per agent is optimal; 18+ degrades selection reliability. Narrow, role-scoped subagents pick the right tool far more reliably than one overloaded mega-agent.

researcher = AgentDefinition(
    name="researcher",
    description="Investigates ONE topic and returns findings with citations.",
    system_prompt="Research the given topic. Return findings with source URL + date.",
    allowed_tools=["WebSearch", "WebFetch", "Read"],  # no Task: cannot re-spawn
)

The Agentic Loop Still Governs

Parallelism doesn't change the control flow. The coordinator still runs the standard agentic loop: send request → inspect stop_reason → if tool_use, run the tools (the parallel subagents) and append their results to history → repeat until end_turn.

Terminate on stop_reason, never by parsing text for words like "done". Iteration caps are a safety net, not the primary stop mechanism. Whether one Task or three ran, the loop logic is identical.

Quick Check

A coordinator must research three independent topics as fast as possible. Which approach correctly spawns the subagents in parallel?

Recap

Key takeaways for parallel subagent spawning:

  • Multiple Task calls in one response run in parallel — there's no flag, it's a decomposition choice.
  • The coordinator's allowedTools must include "Task".
  • Subagents do not inherit history — pass all context explicitly in each self-contained prompt.
  • Use parallel for independent subtasks; use a pipeline/chaining for sequential dependencies.
  • On partial failure: recover transient faults locally, escalate non-recoverable ones with partial results — never abort the whole workflow or suppress silently.
  • Scope subagents with least privilege (4-5 tools), and keep terminating on stop_reason, never on parsed text.
무료로 시작

AI 튜터와 함께 Python을(를) 배우세요 — 무료

브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.

코스
26
레슨
104

자주 묻는 질문

“하위 에이전트 병렬 생성” 강의는 무료인가요?

네 — “하위 에이전트 병렬 생성” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Claude Architect 강의 전체를 잠금 해제할 수 있습니다. Claude Architect 강의에는 총 4개의 강의가 포함되어 있습니다.

“하위 에이전트 병렬 생성”에서 뭘 배우나요?

한 응답에 포함된 여러 Task 호출은 동시에 실행됩니다 브라우저에서 직접 실행하는 실습 코드로 Claude Architect을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Claude Architect을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Claude Architect은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“하위 에이전트 병렬 생성” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Claude Architect 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Claude Architect 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 허브 앤 스포크 코디네이터 토폴로지
  2. 코디네이터의 책임
  3. 하위 에이전트는 이력을 상속하지 않습니다
  4. 하위 에이전트 병렬 생성
← Claude Architect(으)로 돌아가기