Agentic Architecture & Orchestration
This domain focuses critically on how to build, orchestrate, and manage multi-agent systems using the Claude Agent SDK and core APIs. Understanding state, loops, and hooks is paramount here. The exam tests you recursively on knowing when to rely on the agent's logic versus strictly enforced programmatic logic.
Task 1.1: The Agentic Loop Lifecycle
The agentic loop represents the foundational lifecycle of any autonomous AI assistant. It dictates how the model receives user queries, determines if tools are required, handles execution, and resolves back into natural language answers.
Complete State Machine Flow:
1. Model Invocation: The client app issues a call to Claude's Message API containing the active chat array and the list of JSON-schema formatted tool structures.
2. Control Token Inspection: Inspect the API header response metadata. Specifically, read the stop_reason field.
3. Execution Route:
- If
stop_reason === "tool_use": The client interceptor extracts the list of tool calls, parses the arguments, executes them in the local environment, formats the response, appends it as a new message, and repeats Step 1. - If
stop_reason === "end_turn": The loop ceases. Display the text payload to the user.
API Payload Example:
`json
{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 2048,
"system": "You are a database agent. Query tables only when requested.",
"messages": [
{
"role": "user",
"content": "Retrieve account details for user 'usr_982'."
}
],
"tools": [
{
"name": "lookup_user",
"description": "Fetch user metrics from internal user DB.",
"input_schema": {
"type": "object",
"properties": {
"user_id": {
"type": "string",
"description": "UUID string of the target customer account."
}
},
"required": ["user_id"]
}
}
]
}
`
Loop Stop Reasons:
| Stop Reason | Meaning | Client Action Required |
|-------------|---------|-----------------------|
| "end_turn" | Model completed output naturally. | End loop, present content to user. |
| "tool_use" | Model expects tool execution results. | Run tool locally, send results to API. |
| "max_tokens" | Generation limit exceeded. | Resume session or escalate. |
| "stop_sequence" | Ceased on custom stop string. | Parse up to stop boundary. |
> [!WARNING]
> Core Exam Anti-Patterns:
> 1. Parsing natural language signals: Checking if the model outputs words like "I am finished". Natural language is ambiguous; always use the programmatic stop_reason === "end_turn" control token.
> 2. Relying solely on arbitrary loops caps: Hard limiting iterations without active state checking leads to silent failures. Use validation hooks instead.
> 3. Assuming text content means stop: Claude often returns reasoning thoughts alongside tool parameters in a single payload. Do not end execution just because text content is present.
---
Task 1.2: Multi-Agent Orchestration Patterns
When system complexity increases, bundling too many tools (e.g. 15+) onto a single agent causes significant routing degradation and token overhead. Modern architectures separate logic into multi-agent systems.
Comparison: Hub-and-Spoke vs. Peer-to-Peer
| Attribute | Hub-and-Spoke (Recommended) | Peer-to-Peer (Avoid) |
|-----------|-----------------------------|----------------------|
| Control Flow | Coordinator agent routes all traffic. | Agents call each other directly. |
| State Tracking | Centralized in the Coordinator. | Distributed, complex sync required. |
| Context Leaks | Low (only relevant facts are passed). | High (history gets passed along peers). |
| Recovery | Easy (coordinator handles subagent fails). | Hard (cascading failures crash loop). |
The Subagent Isolation Principle:
Subagents do NOT inherit the primary conversation context natively. They have isolated memory states. The Coordinator must explicitly summarize and pass only the required information to subagents.
---
Task 1.3: Subagent Invocation and Context Passing
Subagents are spawned by the Coordinator using the Task tool. The Coordinator's allowedTools list must explicitly declare the Task tool:
`typescript
const taskTool = {
name: "Task",
description: "Spawn a specialized subagent to perform a targeted task.",
input_schema: {
type: "object",
properties: {
subagent_type: { type: "string", enum: ["database", "payment", "support"] },
instruction: { type: "string" }
},
required: ["subagent_type", "instruction"]
}
};
`
When executing a subagent turn, package only the relevant slices of the coordinator history. Passing the entire chat history violates context boundaries and leads to subagent confusion.