支持代理与多代理研究
升级、钩子、中心辐射式协作以及带引用的综合。
支持代理与多代理研究 是 CoddyKit 上的免费 Claude Architect 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Claude Architect 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Claude Architect 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Two Scenarios, One Lesson
The exam shows you 4 of 8 scenarios. Two of the highest-value ones share a hidden spine: Scenario 1 (Customer Support Agent) and Scenario 3 (Multi-Agent Research System). Both are really about the same architect-grade judgment — when a model decides, and when deterministic code must guarantee.
- Support Agent: identity preconditions, hook-enforced policy, and disciplined escalation.
- Multi-Agent Research: a hub-and-spoke coordinator that fans out, then synthesises findings with citations and coverage annotations.
This lesson walks the decisions an examiner tests on both, weighted toward Domain 1 (Orchestration, 27%) with strong pulls from Tool Design, Prompt Engineering, and Reliability.
Preconditions Before Side Effects
The support agent has four tools: get_customer, lookup_order, process_refund, and escalate_to_human. The first decision the exam tests: a refund is a side effect, so it must be gated behind a verified identity.
A programmatic precondition — block process_refund until get_customer has returned a verified ID — is a deterministic guarantee. Prompt guidance ("please verify the customer first") is roughly 90% probabilistic; it will eventually let an unverified refund through. For an action with financial consequence, that gap is unacceptable.
# The precondition lives in HARD CODE, not the prompt.
def handle_refund(state, args):
if not state.get("verified_customer_id"):
return {
"is_error": True,
"errorCategory": "permission",
"message": "Identity not verified. Call get_customer first.",
}
return process_refund(args)Multiple Matches: Ask, Never Guess
A subtle but frequently-tested case: get_customer returns more than one match. The wrong answer picks the first row, or the highest-spending account, or guesses by recency. The right answer asks for more identifiers.
Guessing identity on an account that can issue refunds is exactly the kind of unrecoverable, high-stakes mistake the precondition was meant to prevent. When the input is ambiguous, the model's job is to disambiguate with the user — request an order number, email, or postal code — not to resolve the ambiguity on its own.
Hooks: 100% Deterministic Enforcement
Suppose policy says refunds over $500 require a manager. A system prompt that says "never refund more than $500 without approval" is probabilistic — it holds most of the time and fails silently the rest. When failure has financial, legal, or safety consequences, you reach for a hook.
- An outgoing-call hook intercepts the action before it executes and blocks any policy-violating call.
- A PostToolUse hook intercepts a tool's result before the model sees it — useful for redaction or for injecting a verified fact.
Hooks are 100% deterministic; prompts are ~90% probabilistic. That number is the whole answer on these questions.
A Hook That Blocks a $500 Refund
Here the guarantee is enforced in code that the model cannot talk its way past. Even if a clever user convinces the agent to attempt a $900 refund, the hook denies the call outright.
On the exam, any answer that enforces a hard money/legal/safety rule with prompt wording alone is a distractor. The deterministic option wins.
# Outgoing-call hook: deterministic policy gate.
def before_process_refund(call):
if call.tool == "process_refund" and call.input["amount"] > 500:
return {
"decision": "block",
"reason": "Refunds over $500 require human approval.",
}
return {"decision": "allow"}
# Prompts persuade; hooks guarantee.Escalation: Good Triggers vs Bad Triggers
Escalation is where most candidates lose points. Memorise the two lists.
Good triggers (escalate):
- An explicit human request — escalate immediately, no further attempts.
- A policy gap the agent has no rule for.
- No progress after genuine attempts.
- A threshold violation (e.g. refund over the policy cap).
Bad triggers (never escalate on these):
- Sentiment analysis of the customer's tone.
- The model's own self-rated confidence ("I'm 4/10 sure").
- Untrained classifiers.
Sentiment and self-rated confidence are unreliable signals; building escalation on them is a classic anti-pattern.
The Emotion-Handling Pattern
An upset customer is not, by itself, an escalation trigger. The exam-correct sequence is a three-step pattern:
- Acknowledge the emotion — briefly and genuinely.
- Propose a concrete solution — try to actually solve the problem.
- Escalate only if the request is reiterated — i.e. the customer explicitly asks again for a human, or the solution doesn't land.
This keeps a human in the loop for the cases that truly need one, without routing every frustrated message to a person. Note the contrast with an explicit "get me a human" — that you escalate immediately.
# Emotion != escalation. Reiteration or explicit ask = escalation.
# 1. acknowledge -> 2. propose solution -> 3. escalate if repeated
if user_explicitly_requested_human:
escalate_to_human(reason="explicit request") # immediate
elif solution_offered and user_reiterated_request:
escalate_to_human(reason="unresolved after attempt")Pivot: The Research Coordinator
Now Scenario 3. A research question spanning five sources is too much for one agent — attention dilutes and the context window fills with noise. The fix is hub-and-spoke: a coordinator decomposes the question and delegates each slice to a focused specialist subagent.
The coordinator owns five jobs: decompose, delegate, aggregate, route, handle errors. Delegation is itself a tool call, so the coordinator's allowedTools must include "Task". Each specialist is an AgentDefinition (name, description, system_prompt, allowed_tools) with a least-privilege tool set.
coordinator = AgentDefinition(
name="research_lead",
description="Decomposes a research question, delegates to specialists, synthesises a cited answer.",
system_prompt="Decompose the question, delegate each part via Task, then synthesise findings with citations.",
allowed_tools=["Task"], # REQUIRED, or it cannot delegate
)Context Isolation and Parallel Fan-Out
The most-tested fact about subagents: they do not inherit the coordinator's conversation history. Each one starts clean and knows only what the coordinator writes into its Task prompt. If a constraint, date window, or prior finding matters, the coordinator must restate it explicitly — every time.
This isolation is a feature: it keeps each spoke's context focused. And because multiple Task calls emitted in one response run in parallel, the coordinator fans out across independent sources simultaneously.
- Parallel Task calls for independent sub-tasks (different sources/files).
- Sequential delegation when a later step depends on an earlier result.
# Fan out to independent sources in ONE response -> parallel execution.
task(subagent="web_specialist", prompt=CONTEXT + "Find 2025 EV adoption stats. Cite each.")
task(subagent="filings_specialist", prompt=CONTEXT + "Pull Q4 revenue from the 10-K. Cite the page.")
task(subagent="news_specialist", prompt=CONTEXT + "Summarise regulatory changes. Cite source + date.")Errors and Partial Results, Not Aborts
One subagent failing must not abort the whole research run. The exam wants structured error propagation and graceful degradation:
- Distinguish an access failure (retryable?) from a valid empty result (no matches — a real answer).
- Recover transient faults locally inside the subagent; only escalate the non-recoverable.
- When escalating, carry partial results and structured context: failure type, attempted query, alternatives.
- Annotate coverage gaps in the final report — say what you couldn't reach, never silently suppress it.
A generic "Operation failed" blocks intelligent routing; a structured error (with errorCategory and isRetryable) enables it.
# Subagent returns structure, not a bare string.
return {
"is_error": True,
"errorCategory": "transient", # transient | validation | business | permission
"isRetryable": True,
"attempted_query": "site:sec.gov 10-K revenue",
"partial_results": rows_collected_so_far,
"message": "Source timed out after 2 retries; partial data attached.",
}Synthesis With Provenance
The coordinator's final job is synthesis — and on the exam, synthesis without provenance is wrong. Keep an explicit claim→source mapping for every assertion: URL, document name, the quote, and the publication date.
- When two sources conflict, annotate the discrepancy rather than arbitrarily picking one. Dates often resolve the apparent contradiction (an old figure vs a current one).
- Render by content type: tables for financials, prose for news, lists for technical findings.
- State coverage explicitly — which sub-questions were fully answered, partially answered, or unreachable.
A confident, well-formatted answer with no traceable sources is a trap; the cited, coverage-annotated answer is the architect-grade one.
Exam Scenario
A support agent confirms exactly one customer via get_customer and the customer, sounding frustrated, asks for a $750 refund. Company policy caps automated refunds at $500. Which design is exam-correct?
Key Takeaways
Across both scenarios, the same architect instincts decide the answer:
- Guarantee with code, persuade with prompts. Identity preconditions and money/legal/safety caps go in hooks and programmatic checks — never prompt wording alone.
- Escalate on objective signals (explicit request, policy gap, no progress, threshold violation). Never on sentiment, self-rated confidence, or untrained classifiers.
- Emotion pattern: acknowledge → propose a solution → escalate only if reiterated. Explicit human requests escalate immediately. Ambiguous identity → ask, don't guess.
- Hub-and-spoke: coordinator decomposes, delegates via "Task", aggregates. Subagents inherit no history — pass context explicitly. Independent slices run in parallel.
- Fail gracefully: structured errors with
errorCategory/isRetryable, recover transient faults locally, carry partial results, annotate coverage gaps. - Synthesise with provenance: claim→source mappings, conflict annotations resolved by date, render by content type.
Match the enforcement mechanism to the cost of failure, and you'll pick the right answer every time.
常见问题解答
「支持代理与多代理研究」课时是免费的吗?
是的 — 「支持代理与多代理研究」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Claude Architect 课程的其余内容,请升级到 CoddyKit PRO。 Claude Architect 课程共包含 4 节课。
「支持代理与多代理研究」这节课中我会学到什么?
升级、钩子、中心辐射式协作以及带引用的综合。 你通过在浏览器中直接运行的动手代码来练习 Claude Architect,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Claude Architect 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Claude Architect 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。
「支持代理与多代理研究」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Claude Architect 课中编写并运行代码吗?
能。每节 Claude Architect 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 支持代理与多代理研究
- 代码生成与开发者效率
- CI/CD 与结构化提取
- 对话模式与代理式工具