Chapter 3 of 8
Domain 1: orchestration, hooks, and escalation
Once you have one agent, the exam moves to coordinating several, and it tests the hub-and-spoke topology consistently. One coordinator decomposes the task and delegates to specialized subagents, then aggregates the results, and there is no direct communication between subagents. The single most tested concept in this domain is that subagents have isolated context: they do not inherit the coordinator's conversation history or memory, so every piece of context a subagent needs must be passed explicitly in its prompt. Information loss between a coordinator and a subagent is almost always incomplete context passing, not a context window overflow, and that is the most common wrong answer. The second sharp line is enforcement. When failure has financial, legal, or safety consequences, you use a hook, not a prompt instruction, because a hook is deterministic and a prompt is only probabilistic. A PreToolUse hook can block a refund over 500 dollars every single time; a prompt that says "only process refunds under 500" works most of the time, which is not good enough for money. The third topic is escalation. Explicit human requests, policy gaps, no progress after defined attempts, and financial thresholds are reliable triggers. Sentiment analysis, model confidence scores, and automatic category classifiers are traps. In this lab you prove a subagent only answers correctly when context is passed, route each error category to its recovery action, and separate the reliable escalation triggers from the distractors.
The lab: read it, then run it
#!/usr/bin/env python3
"""
LAB CF3: Multi-agent orchestration, hooks, and escalation (Domain 1, 27%).
Hub-and-spoke: one coordinator delegates to subagents that have ISOLATED
context. Every fact a subagent needs must be passed explicitly. Hooks enforce
policy deterministically where prompts only enforce it probabilistically. And
some escalation triggers are reliable while others are exam traps. This lab
drills all three: it proves a subagent only answers correctly when context is
passed, routes subagent errors to the right recovery action, and separates
reliable escalation triggers from the unreliable distractors.
Deterministic, offline, standard library only.
Run: python3 modules/academy-content/labs/cca-f/cf3-orchestration.py
"""
import sys
# STEP 1: subagents have isolated context. A subagent cannot see the
# coordinator's history; it only knows what its own prompt contains.
CASE_FACTS = {"order_total": 89.99}
def subagent(prompt: dict):
"""A subagent sees ONLY its own prompt dict. It returns the order total if
and only if the coordinator passed it explicitly."""
return prompt.get("order_total", None) # nothing inherited from the hub
no_context = subagent({"task": "summarize the order"}) # forgot to pass it
with_context = subagent({"task": "summarize", "order_total": CASE_FACTS["order_total"]})
print("STEP 1: isolated subagent context")
print(f" no explicit context -> {no_context} (subagent is blind)")
print(f" explicit context -> {with_context} (correct)")
# STEP 2: structured error routing. Each error category has a fixed retryable
# flag and coordinator action.
ERROR_TABLE = {
"transient": (True, "retry with exponential backoff"),
"validation": (True, "fix input and retry"),
"business": (False, "explain to user, propose alternative"),
"permission": (False, "escalate to human"),
}
def route_error(category: str):
return ERROR_TABLE[category]
print("")
print("STEP 2: structured error routing")
routing_ok = True
for cat, (retryable, action) in ERROR_TABLE.items():
got_retry, got_action = route_error(cat)
ok_row = (got_retry == retryable and got_action == action)
routing_ok = routing_ok and ok_row
print(f" {cat:<11} retryable={got_retry!s:<5} -> {got_action}")
# STEP 3: escalation triggers. Reliable vs trap.
RELIABLE = {"explicit_human_request", "policy_gap", "no_progress_after_attempts",
"financial_over_threshold"}
TRAPS = {"negative_sentiment", "self_reported_confidence", "auto_category_classifier"}
def should_escalate(trigger: str) -> bool:
"""Only reliable triggers escalate. Traps must NOT drive escalation."""
return trigger in RELIABLE
print("")
print("STEP 3: escalation triggers (reliable vs exam trap)")
escalation_ok = True
for t in sorted(RELIABLE):
d = should_escalate(t)
escalation_ok = escalation_ok and d
print(f" reliable {t:<28} escalate={d}")
for t in sorted(TRAPS):
d = should_escalate(t)
escalation_ok = escalation_ok and (not d)
print(f" trap {t:<28} escalate={d}")
# Invariants.
context_ok = (no_context is None and with_context == 89.99)
hook_beats_prompt = True # hooks are deterministic(100%) vs prompts probabilistic
# demonstrate: a $700 refund is blocked by a hook every time, a prompt is not
HOOK_LIMIT = 500
refund = 700
hook_blocks = refund > HOOK_LIMIT # PreToolUse hook redirects deterministically
print("")
print(f"STEP 4: hook enforcement on a ${refund} refund (limit ${HOOK_LIMIT})")
print(f" PreToolUse hook redirects to escalation: {hook_blocks} (deterministic, every time)")
ok = context_ok and routing_ok and escalation_ok and hook_blocks
print("")
print(f" explicit context is mandatory for subagents : {context_ok}")
print(f" error categories route correctly : {routing_ok}")
print(f" reliable triggers escalate, traps do not : {escalation_ok}")
print("")
print(f"ORCHESTRATION RULES HOLD (explicit context + error routing + escalation + hooks): {'YES' if ok else 'NO'}")
if not ok:
sys.exit(1)
print("Pass context explicitly, enforce money with hooks, escalate on reliable triggers only. Next: Claude Code config.")
Runnable lab
cf3-orchestration.pyProve explicit context is mandatory for subagents, route error categories to recovery actions, and classify escalation triggers.
Proves: ORCHESTRATION RULES HOLD (explicit context + error routing + escalation + hooks): YES
Runs in your browser via Pyodide. First run loads the runtime once; no install, no server.
The subagent was blind until you passed the order total into its prompt, which is the isolated-context rule made concrete. The error table routed each category correctly: transient and validation errors are retryable, business and permission errors are not, and each carries a specific coordinator action. Two more patterns for the exam. A failing subagent should return a structured error with errorCategory, isRetryable, partial_results, and alternative_approaches, never a bare "operation failed", and it should continue with partial results and annotate the coverage gap rather than aborting the whole workflow. And a coordinator spawns subagents in parallel by issuing multiple Task invocations in one response, not sequential calls. Next you leave agents and move to configuring Claude Code itself.
Check your understanding
1. Why does a subagent sometimes miss information the coordinator clearly had?
2. You must guarantee that refunds over 500 dollars are never auto-processed. What enforces this?
3. Which of these is a reliable escalation trigger?
4. How should a failing subagent report an error to the coordinator?