Lesson 1 · Domain 1 — Agentic Architecture & Orchestration (27% of exam)
Every agent you'll design for this exam — customer support bot, research coordinator, CI reviewer — runs on the same underlying mechanism. Get this one loop exactly right and a large share of Domain 1's "knowledge of" bullets fall out for free.
An agentic loop is nothing more than: send a request to Claude, inspect what it decided to do, act on that decision, and repeat. The entire "decision" is carried in one field on the response: stop_reason.
stop_reason: "tool_use" — Claude wants to call one or more tools before it can finish. Your code must execute those tools and feed the results back in.stop_reason: "end_turn" — Claude is done reasoning and has produced its final answer. The loop terminates here.Each time you execute tools, their results get appended to the conversation history as a new message, and you send the whole growing conversation back to Claude for the next turn. This is why tool results accumulate in context — a fact you'll return to in Domain 5 when context management becomes the problem.
while (true) {
const response = await client.messages.create({
messages: conversation,
tools,
...
});
conversation.push(response.toMessage());
if (response.stop_reason === "end_turn") {
return response; // done — show this to the user
}
if (response.stop_reason === "tool_use") {
for (const block of response.content) {
if (block.type === "tool_use") {
const result = await executeTool(block.name, block.input);
conversation.push(toolResultMessage(block.id, result));
}
}
// loop continues — send the updated conversation back
}
}
stop_reason. Text content can appear alongside a tool_use block — it doesn't mean the turn is over.stop_reason tells you whether it wants to keep going.This loop is the substrate under the Claude Agent SDK, Claude Code itself, and any custom agent you build with the Messages API directly. Every other Domain 1 topic — subagent orchestration, hooks, session forking — is a variation played on top of this same loop.
Primary source: read Anthropic's own tool-use / stop_reason reference in the Claude API docs and the Agent SDK overview — this lesson compresses both down to the one mechanism the exam actually probes.
stop_reason after each API call. Which condition should terminate the loop and return the response to the user?stop_reason on the response is tool_use. What should the loop do next?Stuck on any of this, or want to see how this loop maps onto the Agent SDK's own TypeScript types? Just ask — I'm your teacher for this workspace, not just the lesson author.