Skip to main content
Agentic architecture

Claude Agentic Loop: Workflow vs Agent in Scenario Questions

How the Claude agentic loop uses stop_reason and tool_result, the loop anti-patterns the exam targets, and when to pick a fixed workflow over an agent.

The CertGrove team · 6 min read

Many CCAR-F scenario questions come down to one design choice: should the code fix the sequence of steps, or should Claude decide what to do next? Get the Claude agentic loop mechanics right and you can rule out most distractors on sight. This post covers the loop itself, the anti-patterns the exam guide names, and how to choose between a workflow and an agent.

How the Claude agentic loop works

An agentic loop is a plain while loop around the Messages API. You send the conversation and the available tools. Claude replies, and you look at stop_reason:

  • "tool_use": the response contains one or more tool_use blocks. Run each tool, then send back a user message with a matching tool_result block for every tool_use_id. Go around again.
  • "end_turn": Claude has finished. Show the final answer.

The step people forget is appending. The assistant's tool_use turn and your tool_result turn both go into the message history, so on the next request Claude can reason about what it just learned.

flowchart TD
    A[Send messages + tools] --> B{stop_reason?}
    B -- tool_use --> C[Run each requested tool]
    C --> D[Append assistant turn and tool_result blocks]
    D --> A
    B -- end_turn --> E[Return final answer]

Here is a minimal Python version:

import anthropic

client = anthropic.Anthropic()
messages = [{"role": "user", "content": "Refund order 8812 if it qualifies."}]

while True:
    response = client.messages.create(
        model=MODEL, max_tokens=1024, tools=TOOLS, messages=messages
    )
    messages.append({"role": "assistant", "content": response.content})

    if response.stop_reason != "tool_use":
        break  # "end_turn" (also handle "max_tokens" etc. explicitly)

    results = []
    for block in response.content:
        if block.type == "tool_use":
            output = run_tool(block.name, block.input)
            results.append({
                "type": "tool_result",
                "tool_use_id": block.id,
                "content": output,
            })
    messages.append({"role": "user", "content": results})

Other stop reasons exist, such as "max_tokens" when the output limit is hit. A production loop handles them on purpose rather than treating everything that isn't tool_use as success.

Agentic loop anti-patterns from the exam guide

Task statement 1.1 lists three anti-patterns by name. Expect them as wrong answers.

Parsing natural language to decide when to stop. Checking whether Claude wrote "I'm done" or "Task complete" is fragile. The wording varies from run to run, and a phrase like "done with step one" can trigger a false stop. stop_reason is the structured signal; use it.

Arbitrary iteration caps as the primary stop. A maximum turn count is a reasonable safety net against runaway loops. As the main way to end the loop it is wrong: it cuts off tasks that legitimately need more steps and lets short tasks waste turns. Keep the cap as a backstop and let stop_reason drive completion.

Treating text content as a completion signal. A response can contain a text block ("Let me check the order status") and a tool_use block together. If your loop stops because it saw text, it drops the pending tool call and the task fails halfway.

Workflow vs agent: fixed steps or model-driven decisions

The exam guide separates model-driven decision-making, where Claude picks the next tool based on context, from pre-configured decision trees or tool sequences. Neither is better in general. The question is whether you know the steps in advance.

Use a fixed workflow (prompt chaining) whenUse an agent loop when
The steps are known and the same every timeThe next step depends on what the last one found
You want predictable cost and easy testingThe task is open-ended (investigate, debug, research)
Example: review each file, then run a cross-file integration passExample: "find out why checkout fails for some EU users"

Prompt chaining splits a predictable job into focused passes, each with its own prompt. The exam guide's code review example does per-file analysis first, then a separate integration pass, which avoids diluting attention across a huge diff. Dynamic decomposition fits investigations where the plan has to change as you learn more.

A common distractor proposes a full agent for a task that is a fixed checklist, or forces a rigid pipeline onto an investigation. Read the scenario for the word that tells you whether the path is known.

When to add human confirmation

Autonomy is not all-or-nothing. Put a person in the loop when:

  • the action is irreversible or costly (large refunds, deleting data, deploying),
  • the request falls in a policy gap the agent has no rule for,
  • the customer explicitly asks for a human, which the guide says to honor immediately.

When a business rule must hold every time, say "no refunds above $500 without approval", enforce it in code, for example with a hook that intercepts the tool call, rather than with a prompt instruction. Prompts give probabilistic compliance. Hooks give a guarantee.

Try it

A team's support agent sometimes stops halfway: it says "Let me look up that order" and the conversation ends without the lookup ever happening. The loop code exits as soon as a response contains a text block. What is the best fix?

  • A) Raise the maximum iteration count from 5 to 15.
  • B) Continue the loop while stop_reason is "tool_use" and stop on "end_turn".
  • C) Add a system prompt rule telling Claude never to write text before calling a tool.
  • D) Stop the loop only when the response contains the phrase "final answer".

Answer: B. The bug is checking for text instead of the structured stop signal. A response can hold both text and a tool_use block, and stop_reason is what says which kind of turn it is.

  • A has nothing to do with the bug. The loop already quits early, well before any cap.
  • C relies on prompt compliance to patch a control-flow bug, and Claude can still produce text alongside tool calls.
  • D swaps one natural-language check for another.

Key takeaways

  • Loop while stop_reason is "tool_use", stop on "end_turn", and handle other values on purpose.
  • Append both the assistant's tool_use turn and your tool_result blocks before the next request.
  • Iteration caps are a safety net, not the stopping rule. Never stop on phrases or on the presence of text.
  • Known steps mean prompt chaining. Steps that depend on findings mean an agent loop.
  • Gate irreversible or high-risk actions with human confirmation, and use hooks for rules that must always hold.

Frequently asked questions

The CertGrove teamBilingual study notes for developers preparing for Claude Certified Architect — Foundations.