Skip to content

CCAR-F · Domain 1: Agentic Architecture & Orchestration · 27% of the exam

Task 1.1: Design and implement agentic loops for autonomous task execution

The loop at the heart of every agent: send the request, read stop_reason, run the tools Claude asked for, append the results to the conversation and go round again until Claude ends its turn, and the anti-patterns that stop a loop at the wrong moment.

Study it

Sample questions

Try each one before opening the answer. Every option is explained, with the Anthropic documentation page that proves it.

Question 1 · choose 1

Your support resolution agent runs its own loop around the Messages API. A billing dispute can need five or six lookups in a row (get_customer, lookup_order and others) before Claude can answer, and the loop must neither stop early nor keep calling the API after Claude has finished. Which rule should decide whether the loop goes round again?

  1. AKeep running tools and sending results while stop_reason is "tool_use", and return the reply once it is "end_turn"
  2. BTell Claude to finish every resolved case with a marker such as [DONE] and stop when the marker appears in the text
  3. CAllow a fixed number of round trips sized to the longest case seen in testing, then return the latest text
  4. DEnd the loop as soon as a response contains a text block, since that text is the answer the customer is waiting to see
Show the answer and why
  • AKeep running tools and sending results while stop_reason is "tool_use", and return the reply once it is "end_turn"

    Correct

    stop_reason is the API's structured signal: "tool_use" means Claude is waiting for tool results, "end_turn" means it finished its response, however many lookups the case needed.

  • BTell Claude to finish every resolved case with a marker such as [DONE] and stop when the marker appears in the text

    Incorrect

    Parsing natural-language markers is brittle: Claude may write the marker while still planning a call, or leave it out, while the API already reports the reason it stopped.

  • CAllow a fixed number of round trips sized to the longest case seen in testing, then return the latest text

    Incorrect

    A count chosen in advance cuts off unusual cases that need more steps and says nothing about whether Claude has actually finished.

  • DEnd the loop as soon as a response contains a text block, since that text is the answer the customer is waiting to see

    Incorrect

    A response can hold text and tool_use blocks together, for example a sentence of reasoning before a lookup, so text alone does not mean Claude is done.

Drive the loop from stop_reason. Continue while Claude asks for tools ("tool_use"), feeding each result back, and stop when it ends its turn ("end_turn"). Text blocks, fixed counts and invented markers are proxies for a signal the API already returns.

Question 2 · choose 1

To save tokens, a developer's support loop sends Claude only the newest tool_result in each request, without the earlier turns. Claude now calls lookup_order again for orders it already checked and loses track of what the customer asked at the start. Which change fixes the behavior?

  1. ARaise max_tokens on each request so that Claude has enough room to keep the earlier lookups and the customer's goal in mind
  2. BTurn on prompt caching for the latest tool result so that Claude can recall it in the following requests
  3. CSend the full conversation each time, including the earlier lookups and the customer's first messages
  4. DCopy each new tool result into the system prompt in place of the previous one, so the latest data is always visible
Show the answer and why
  • ARaise max_tokens on each request so that Claude has enough room to keep the earlier lookups and the customer's goal in mind

    Incorrect

    max_tokens limits the length of the response Claude writes; it has no effect on what Claude can see from earlier turns.

  • BTurn on prompt caching for the latest tool result so that Claude can recall it in the following requests

    Incorrect

    Caching reuses a prefix that you send again; it lowers cost and latency but does not let Claude see content that a request leaves out.

  • CSend the full conversation each time, including the earlier lookups and the customer's first messages

    Correct

    The Messages API is stateless: Claude sees only what each request contains, so the history, earlier tool calls and their results included, has to be sent every time.

  • DCopy each new tool result into the system prompt in place of the previous one, so the latest data is always visible

    Incorrect

    Overwriting one slot still throws away the earlier results and the customer's messages, so Claude still cannot see what it already checked.

Each request has to carry the conversation so far. Claude reasons about the next action from the tool results already in context, so dropping earlier turns makes it repeat work and forget the customer's goal.

Question 3 · choose 2

A codebase-exploration tool calls the Messages API directly. One response comes back with stop_reason "tool_use" and three tool_use blocks, each a search over a different directory. Which TWO practices keep the next request correct and keep Claude making parallel calls? (Choose TWO.)

  1. ASend each result in its own user message, one request per result, in the order the calls appeared
  2. BNumber the results in a text block and let Claude match them to the calls by position
  3. CLeave out the results of searches that found nothing so that empty output does not distract Claude
  4. DPut the tool_result blocks at the start of that user message and any extra text after them
  5. EReturn all three results in one user message, each tool_result carrying the tool_use_id of the call it answers
Show the answer and why
  • ASend each result in its own user message, one request per result, in the order the calls appeared

    Incorrect

    Splitting the results across separate user messages is the documented way to teach Claude to stop calling tools in parallel.

  • BNumber the results in a text block and let Claude match them to the calls by position

    Incorrect

    Results are matched to calls by tool_use_id inside tool_result blocks, not by order in free text.

  • CLeave out the results of searches that found nothing so that empty output does not distract Claude

    Incorrect

    Every tool_use block must be answered; an empty result is still a result, and Claude needs to know the search ran and found nothing.

  • DPut the tool_result blocks at the start of that user message and any extra text after them

    Correct

    In a user message that answers tool calls, the tool_result blocks must come first; text placed before them is rejected.

  • EReturn all three results in one user message, each tool_result carrying the tool_use_id of the call it answers

    Correct

    Every tool_use needs a matching tool_result, and the results of parallel calls belong together in a single user message.

Answer parallel calls with one user message whose content starts with one tool_result per tool_use_id. Separate messages or missing results break the pairing the API expects and discourage parallel tool use.

Question 4 · choose 1

Your research loop calls the Messages API with the web search server tool. Some responses come back with stop_reason "pause_turn" and a server_tool_use block that has no result yet. The loop treats every stop reason other than "tool_use" as the end, so users get half-finished answers. What should the loop do with a "pause_turn" response?

  1. AAppend the response as it is to the messages and send another request so that Claude can continue
  2. BRun the search with your own search API and return a tool_result for the server_tool_use block
  3. CRetry the original request from the start with a higher max_tokens
  4. DAppend the paused response followed by a user message saying "please continue"
Show the answer and why
  • AAppend the response as it is to the messages and send another request so that Claude can continue

    Correct

    pause_turn means the server-side loop hit its iteration limit; sending the paused response back lets Claude finish the turn.

  • BRun the search with your own search API and return a tool_result for the server_tool_use block

    Incorrect

    The API runs server tools itself; the documented continuation is to send the paused response back, not to execute the search.

  • CRetry the original request from the start with a higher max_tokens

    Incorrect

    pause_turn is an iteration limit, not a token limit, and restarting throws away the work already done.

  • DAppend the paused response followed by a user message saying "please continue"

    Incorrect

    With a server tool call still unresolved, a user text turn is not the continuation the API expects; the request fails with an error naming the unresolved server tool.

Handle pause_turn in any loop that uses server tools: the server-side sampling loop reached its iteration limit, so add the assistant response to the messages as it is and make another request to let Claude continue. It is never returned while a client tool_use waits on you.

Question 5 · choose 1

After each tool call, your support loop sends the tool_result followed by a text block saying "Here is the result." Increasingly, Claude replies with an empty end_turn response instead of continuing with the case. What does the documentation point to?

  1. Amax_tokens is too low, so the response is cut off before any content appears
  2. BClaude is refusing the request, which always appears as an empty end_turn response
  3. CThe tool results are too long
  4. DThe text after each tool result teaches Claude to end its turn
Show the answer and why
  • Amax_tokens is too low, so the response is cut off before any content appears

    Incorrect

    A max_tokens cutoff reports stop_reason "max_tokens", not "end_turn".

  • BClaude is refusing the request, which always appears as an empty end_turn response

    Incorrect

    Refusals have their own stop_reason, "refusal".

  • CThe tool results are too long

    Incorrect

    Length is not the documented cause; the extra text pattern is.

  • DThe text after each tool result teaches Claude to end its turn

    Correct

    Adding text immediately after tool results is a documented cause of empty end_turn responses.

Empty end_turn responses often follow a pattern of text blocks inserted right after tool results. Send tool results on their own, and if a response is empty, continue with a new user message rather than resending it unchanged.

Question 6 · choose 1

Your research loop enables the web search server tool alongside your own client tools. A response contains a server_tool_use block for a web search and its web_search_tool_result block. What must your loop do for that search?

  1. ARun the search itself with your own search API and return a tool_result
  2. BEnd the loop, since a server tool result means Claude has finished
  3. CNothing to execute; the API ran it, and you send no tool_result for it
  4. DReturn an empty tool_result with the server tool's id so that the loop can continue
Show the answer and why
  • ARun the search itself with your own search API and return a tool_result

    Incorrect

    That is the client-tool pattern; server tools are executed by the API.

  • BEnd the loop, since a server tool result means Claude has finished

    Incorrect

    Whether Claude is finished still comes from stop_reason.

  • CNothing to execute; the API ran it, and you send no tool_result for it

    Correct

    Server tools run on Anthropic's side, and their results already sit in the response.

  • DReturn an empty tool_result with the server tool's id so that the loop can continue

    Incorrect

    Server tool calls do not take a tool_result from your code.

Client tools are executed by your code and answered with tool_result blocks; server tools such as web search are executed by the API, whose result blocks arrive in the response.

Question 7 · choose 2

Your team is choosing between writing its own Messages API loop and using the Claude Agent SDK for a codebase assistant that needs file tools, shell access, permission checks and hooks. Which TWO statements about the Agent SDK are correct? (Choose TWO.)

  1. AIt includes built-in tools such as Read, Edit, Bash, Glob and Grep
  2. BIt requires your code to append every tool_result to the history by hand
  3. CIt cannot apply permission rules, so every tool runs unchecked
  4. DIt ends after the first tool call so that your code decides each next step
  5. EIt runs the agent loop itself, executing tools and feeding results back until Claude stops calling tools
Show the answer and why
  • AIt includes built-in tools such as Read, Edit, Bash, Glob and Grep

    Correct

    The same built-in tools that power Claude Code are available.

  • BIt requires your code to append every tool_result to the history by hand

    Incorrect

    Result handling is part of the loop the SDK runs for you.

  • CIt cannot apply permission rules, so every tool runs unchecked

    Incorrect

    Permission modes, allow and deny rules, and hooks all apply.

  • DIt ends after the first tool call so that your code decides each next step

    Incorrect

    The loop continues on its own until a response has no tool calls.

  • EIt runs the agent loop itself, executing tools and feeding results back until Claude stops calling tools

    Correct

    The SDK embeds Claude Code's loop, so your code consumes messages rather than driving each turn.

The Agent SDK runs the agentic loop with Claude Code's built-in tools, permissions and hooks; you handle the stream of messages and the final result.

Question 8 · choose 1

Your support loop treats any response without a tool call as the final answer to show the customer. One response arrives with stop_reason "refusal". How should the loop handle it?

  1. AAs a tool failure, returning a tool_result with is_error set
  2. BAs an HTTP error, catching it in the client's exception handler
  3. CAs a refusal with its own handling, such as a fallback model
  4. DAs the final answer, since there are no tool calls in the response
Show the answer and why
  • AAs a tool failure, returning a tool_result with is_error set

    Incorrect

    No tool was called; there is nothing to return a result for.

  • BAs an HTTP error, catching it in the client's exception handler

    Incorrect

    Refusals come back as successful HTTP responses, not exceptions.

  • CAs a refusal with its own handling, such as a fallback model

    Correct

    A refusal is a normal 200 response with its own stop_reason and guidance for handling it.

  • DAs the final answer, since there are no tool calls in the response

    Incorrect

    That would show a refusal message as if it were the resolution.

Always branch on stop_reason. "refusal" means Claude declined; read stop_details and handle it explicitly, for example with a fallback, rather than treating it as an answer.

Practise domain 1 →Practise all domains →