Claude Certification Program · Five exams · Guides updated December 7, 2026

Home › Study guides › CCDV-F › Domain 1 › Lesson 1.3

CCDV-F · Domain 1 · 17% of the exam · Lesson 1.3 · 20 min read Updated for the December 7, 2026 exam guide (v1.1)

Agent pattern diagnosis: read the trace, name the missing pattern

Diagnose a misbehaving agent from its trace: loop termination, subagent isolation, memory or context-window management, and the pattern that fixes it.

Written against skill 1.3 of the official CCDV-F exam guide (Version 1.1, effective December 7, 2026). An independent resource, not affiliated with Anthropic; the practice questions are written from scratch.

1.3.1 Why a misbehaving agent is usually missing a pattern

A good mechanic does not replace the engine because the car makes a noise. She listens: a squeal on braking, a knock under load, a click when turning. Each noise points to one part, and she fixes that part. A bigger engine would leave the squeal where it was.

Ingrid and Tomasz, two developers at a small legal-tech company, shipped a case-file research assistant built on Claude. A lawyer asks a question about a dispute, such as "when did the landlord first learn about the leaking roof?", and the assistant searches about 400 documents, reads the relevant ones and answers with citations. In its first month the support inbox filled with four kinds of complaint. Some answers were a single sentence like "I'll search the files now." One run never finished. On Thursday the assistant had forgotten everything settled on Monday. And in long sessions it started mixing up dates and dropping its citations.

The tempting response to all four is a bigger model, a higher limit or a stern line in the prompt. None of that works. Each complaint comes from one of four agent design patterns being missing or misapplied: how the tool-use loop ends, how subagents isolate work, how memory carries facts between sessions, and how the context window is managed. Each leaves its own fingerprint in the agent's trace, the log of every request and response in a run.

1.3.2 Reading a trace: where the evidence lives

Here is the question that trips people up: the user saw a bad answer, so where do you look? Not at the answer alone. An agent is Claude using tools in a loop: your code sends the conversation and a tool list, Claude replies with an answer or a request to use a tool, your code runs the tool, appends the result and sends everything again. A trace records each pass, and four fields in it carry nearly all the evidence.

  1. stop_reason. The field on every response that says why Claude stopped, such as end_turn, tool_use or max_tokens.
  2. The tool calls. Which tool, with which input, and what came back, including errors.
  3. usage.input_tokens. How big each request was. Its curve across turns shows what the conversation is accumulating.
  4. How the run ended. The turn count, and whether the run finished or hit a cap.

Ingrid now logs one line per turn, and diagnosis becomes a short routine: symptom, evidence, pattern, fix, replay.

From complaint to pattern

SYMPTOMwhat the user saw
EVIDENCEstop_reason, tool calls, input_tokens, turn count
PATTERNwhich one is missing or misapplied
FIX AND REPLAYapply it, rerun the same question
Diagnosis moves from what the user saw to what the trace shows, names one pattern, and ends by replaying the run to prove the fix.
Fingerprint in the trace Pattern to suspect Pattern that corrects it
Run ends with a "let me check" reply; the same call repeats until a timeout; a truncated reply shown as final Tool-use loop termination Continue on tool_use, finish on end_turn, treat other stops as incomplete, cap turns and spend
input_tokens jumps after a reading step; a delegated task comes back generic or off target Subagent isolation Bulk reading in a fresh context that returns condensed findings, with a complete brief
A new session re-asks settled facts; its first request carries an old transcript; another client's notes appear Memory Curated notes outside the window, read on demand, scoped per user or matter
input_tokens climbs every turn of one session; late turns forget early rules or confuse facts Context-window management Clear stale tool results, compact, load just in time, keep standing rules in the system prompt

Memorise the first two columns: a question usually gives the fingerprint and asks for the pattern. The next four sections explain each row.

1.3.3 Loop termination: stopping too soon, or never

The first complaint, an answer that reads "I'll search the files now", looks like a lazy model. The trace says otherwise.

run 5107  turn 1  stop_reason=tool_use  content=[text "I'll search the case files for the inspection reports.", tool_use search_case_files]
run 5107  ended after 1 turn, 0 tools executed; text shown to the user as the answer

Claude did the right thing: it wrote a short note and asked for a tool in the same response, which is normal. The loop, though, ended as soon as it saw a text block, so the tool never ran. That is a termination defect: the exit condition reads the content instead of stop_reason. The rule: on tool_use, run the tools and go round again; on end_turn, the reply is finished. Any other stop, such as max_tokens or refusal, means the run did NOT finish normally and must not be shown as an answer. Look at the two if lines and the last line of the corrected loop.

messages = [{"role": "user", "content": question}]
for turn in range(MAX_TURNS):                       # SAFETY NET: a hard cap
    reply = client.messages.create(model=MODEL, max_tokens=4096,
                                   system=SYSTEM, tools=TOOLS, messages=messages)
    log_turn(run_id, turn, reply.stop_reason, reply.usage.input_tokens)
    if reply.stop_reason == "end_turn":             # the normal finish
        return reply
    if reply.stop_reason != "tool_use":             # max_tokens, refusal...
        raise IncompleteRun(reply.stop_reason)      # never shown as an answer
    messages.append({"role": "assistant", "content": reply.content})
    messages.append({"role": "user", "content": run_tools(reply.content)})
raise IncompleteRun("turn cap reached")             # a cap is not a success

The opposite failure is the run that never ends. Its trace showed read_bundle(["d77"]) returning "document not found" on turn 6, and the identical call on every turn after that until a server timeout killed it at turn 40. The prototype had no cap at all. Two fixes apply: the cap (MAX_TURNS) bounds the damage, and a tool error that says what to do next removes the reason to repeat. Think of the cap as a circuit breaker: it stops the fire spreading, but you still have to find the faulty wire.

How the run ended What it means What your code should do
end_turn Claude finished its reply Use the answer
tool_use Claude wants a tool run Run it, append the result, loop again
max_tokens or model_context_window_exceeded The reply was cut off Treat as truncated, never as a finished answer
A turn or budget cap Your safety net fired Report an incomplete run; investigate why

Memorise the first two rows; recognise the others. If the agent uses server tools that Anthropic runs, such as web search, pause_turn also appears and means send the response back to let it continue. The Claude Agent SDK runs this loop for you and continues until a response contains no tool calls. Its caps are max_turns and max_budget_usd (maxTurns and maxBudgetUsd in TypeScript), and the final ResultMessage carries a subtype: success, or an error such as error_max_turns or error_max_budget_usd. Code that prints the result without checking that subtype has the same bug as Ingrid's first loop.

1.3.4 Subagent isolation: leaks in both directions

The second fingerprint was a cost curve. In one run, input_tokens was about 6,000 on turn 3, then 52,000 on turn 4 and every turn after. The step between them was read_bundle, which was meant to read six documents and return findings.

A subagent is a separate agent instance with its own fresh context: it receives only the instructions and task you give it, does the bulky work, and returns only its final message to the parent. The pattern is like a partner who sends a junior into the archive: the junior comes back with a two-page memo, not with the boxes. Tomasz's refactor had made read_bundle return the full text "in case Claude needs it", so 41,000 tokens of raw documents landed in the main conversation and were resent on every later turn. The isolation existed on paper but leaked upward. The fix is to restore the contract: findings only, each quoting its clause and citing its document id.

What crosses the subagent boundary

Parent agent

Main conversationquestion, document ids, findings
Sends downone complete task brief

Subagent

Fresh contextits own prompt plus the brief
Does the bulkreads documents, calls tools
Sends upits final message only
Isolation works only when the brief going down is complete and the result coming up is condensed; a leak in either direction shows up in the trace.

The leak can also run the other way. A week later, read summaries came back fluent and useless: rent arrears, parking bays, nothing about the roof. The read_bundle tool accepted only doc_ids, so the subagent's prompt said "summarise these documents" and never contained the question. A fresh context means the subagent knows nothing the brief does not tell it. The fix is not a smarter model; it is a tool schema that also takes the question and the output format, so the brief is complete.

The Claude Agent SDK packages the same pattern: Claude starts subagents through the Agent tool, whose prompt string is the only content passed down. The parent's history and tool results stay behind, and only the subagent's final message returns. Forks, which copy the conversation on purpose, are the deliberate exception. Two other signatures point here too: a main agent reading every document itself, with no subagent at all, and subagents added for small tasks, where each one's extra requests buy nothing.

1.3.5 Memory: forgetting, and remembering the wrong things

Thursday's complaint was the opposite of bloat. A lawyer typed "carry on with the lease dispute", and the trace showed the first reply asking which documents mattered and what the key dates were, facts confirmed on Monday. The request's tool list had no memory tool, and nothing from Monday was sent. Claude does not recall Monday's session on its own, so a new session starts blank unless your application supplies what it should know.

The pattern is memory outside the context window: the agent writes curated notes to a store and reads back only what the current task needs. Anthropic's memory tool is one ready-made version. Adding {"type": "memory_20250818", "name": "memory"} to tools lets Claude view, create, edit, rename and delete files under /memories, and with it enabled Claude checks that directory before starting a task. The tool is client-side: Claude only requests each operation, and your handler runs it against storage you control.

Two kinds of memory in one agent

Within a session

The conversationresent on every request
Grows every turnand suffers context rot
Gone when the session ends

Across sessions

A memory storenotes under /memories
Curated factsdates, parties, open questions
Read on demandscoped to one client matter
The conversation is short-term memory that ends with the session; a scoped memory store lives outside the window and is read back only when needed.

Memory can also be misapplied. Tomasz's first patch replayed Monday's whole transcript before Thursday's question; the fingerprint was a first request of about 96,000 input tokens and an answer that dwelt on documents ruled out on Monday. That is history, not memory. A later trace showed a view /memories listing that included another client's folder, because the handler mapped every session to one shared directory. The fix lives in code: Ingrid's handler maps /memories to one folder per client matter and rejects any path that resolves outside it, such as /memories/../secrets.env. Path validation, size caps and expiry of old notes are your handler's job, because your code executes every operation.

1.3.6 Context-window management: the slow fade within one session

The last complaint came from long sessions. After about 30 questions on one dispute, answers began confusing the dates of two inspection reports, and later replies stopped citing document ids. No single turn looked broken. The trace showed a curve: input_tokens rose from 4,000 on turn 1 to 118,000 on turn 30, most of it old search results and read findings that no later step needed.

Everything in a request counts against the context window, the most text Claude can take in at once: system prompt, tool definitions, every message and every tool result. Quality does not wait for the hard limit. Anthropic's context-engineering guidance calls the decline context rot: as tokens accumulate, the model recalls information from the context less accurately. It describes context as an attention budget, so every stale result left in place spends attention the current question needs. The fingerprint is a rising input_tokens curve within one session plus errors that appear late, never early.

turn  1  input_tokens=4,010     cites doc ids: yes
turn 18  input_tokens=61,400    cites doc ids: yes
turn 30  input_tokens=118,200   confuses d14 (12 March) with d31 (2 May)
turn 31  context compacted
turn 32  input_tokens=9,800     cites doc ids: no

The correcting pattern is to decide what each request carries. Search returns ids and titles, and full text loads only when a step needs it (just-in-time retrieval). Old tool results get cleared, which the API's context editing feature (in beta) can do automatically. Very long sessions get compaction, which replaces older turns with a summary: the API offers it in beta, and the Agent SDK compacts automatically as the window fills. Notice turns 31 and 32: compaction ran, and citations stopped. The citation rule had appeared only in the first user message, and the summary did not keep it.

1.3.7 The exam traps

Most wrong answers treat the symptom instead of naming the pattern.

  • ✗ Raising the turn cap or the budget because the agent keeps looping. ✓ Find why it repeats, usually a tool error that gives no next step or a wrong exit condition. The cap is a safety net that bounds damage, not a fix.
  • ✗ Showing whatever the loop returned last as the answer. ✓ Check stop_reason or the SDK result subtype first; max_tokens, error_max_turns and similar stops mean an incomplete run.
  • ✗ Moving to a bigger model or larger context window to cure late-session confusion. ✓ Control what enters the window. More room lets stale content grow, and context rot grows with it.
  • ✗ Replaying old transcripts so the agent "remembers". ✓ Keep curated notes in a memory store, scoped per user or matter, and read back what the task needs.
  • ✗ Letting a subagent return raw material, or briefing it in one line. ✓ The brief carries the question, inputs and output format; the return is condensed findings.
  • ✗ Adding a prompt line such as "do not repeat searches" or "remember earlier sessions". ✓ Each of these patterns lives in your code: the exit condition, the handler, the tool contract, what each request contains.

Four tempting fixes for a misbehaving agent, one real one

A bigger model or windowmore room, same defect
Raise the turn capa longer loop, same loop
A sterner system promptwords cannot change the loop
Retry the runa deterministic bug recurs
Name the pattern, apply ittermination, isolation, memory or context
Capacity, louder prompts and retries leave the cause in place; naming the missing or misapplied pattern and applying it removes it.

1.3.8 Put it together: diagnose a broken agent from its trace

You now have the whole routine: read the trace, match the fingerprint to one of four patterns, apply that pattern and replay. To make the fingerprints stick, create each one yourself and watch it appear in your log.

Choosing between a workflow and an agent, and where it runs, comes first in architecture and runtime selection. Building the loop and making required actions run deterministically with hooks is Agent SDK construction. And the full mechanics of compaction, clearing and starting a fresh session belong to context management for long-running sessions.

Key takeaways

  • ✓ Most agent misbehaviour comes from one of four patterns being missing or misapplied: loop termination, subagent isolation, memory or context-window management.
  • ✓ Diagnose from the trace: stop_reason, the tool calls and results, input_tokens per turn and how the run ended, then replay the run to confirm the fix.
  • ✓ A loop continues on tool_use, finishes on end_turn, and treats every other stop, a cap included, as incomplete; the cap bounds damage but is not the fix.
  • ✓ A subagent starts fresh and returns only its final message, so a token jump after delegation or an off-target result means the return leaked or the brief was incomplete.
  • ✓ A new session that re-asks settled facts lacks memory; replayed transcripts and unscoped notes are memory misapplied, and the handler owns the fix.
  • ✓ A rising input_tokens curve with late-session errors calls for context-window management, with standing rules kept in the system prompt, outside the messages compaction summarizes.

Check your understanding

4 questions written for this lesson. Every answer option is explained, including the ones you did not pick. Nothing is stored.

CCDV-F practice questions are being rewritten

The 159 CCDV-F practice questions here were written for the previous exam guide and are tagged to its domains. New questions for the December 7, 2026 guide (v1.1) are being written. Until they are ready, the practice for the new guide is the questions at the end of every lesson, with every answer option explained. The old bank stays open for general practice.

Back to Domain 1 → The previous-guide bank →

Sources