CCDV-F Prep unofficial
← All skills

Agents and Workflows

Agent Pattern Diagnosis

Exam objective: Analyzing a trace or description of a misbehaving agent to identify which design pattern is missing or misapplied, such as tool-use loop termination, subagent isolation, memory, or context-window management, and selecting the pattern that corrects the behavior.

What the exam tests

You are given a trace or a description of a misbehaving agent and must name the missing or misapplied pattern, then pick the fix that treats the cause. Work in this order: how did the loop end (or fail to end), what was in context at that moment, and what should have been carried across a boundary (turn, compaction, subagent or session).

Key rules

Loop termination

  • A client-tool loop runs while stop_reason == "tool_use". Every other value leaves the loop. A response can hold text and tool calls together.
  • Return one tool_result per tool_use block, in one user message, with the results before any text.
  • pause_turn (server-tool loop hit its iteration limit): append the assistant content unchanged and resend with the same tools, with no new user message.
  • max_tokens with an incomplete trailing tool_use: do not execute it; retry with a higher max_tokens.
  • Empty end_turn after tool results: look for text appended after tool_result blocks.
  • In the Agent SDK, bound open-ended runs with maxTurns / maxBudgetUsd and check the ResultMessage subtype before reading result.
while response.stop_reason == "tool_use":
    messages.append({"role": "assistant", "content": response.content})
    messages.append({"role": "user", "content": run_tools(response.content)})
    response = client.messages.create(messages=messages, **params)
handle_final(response)  # end_turn, max_tokens, refusal, pause_turn, ...

Subagent isolation

  • A non-fork subagent starts without the parent's history, tool results or system prompt. Put paths, errors and decisions in the delegation prompt.
  • Only its final message returns, so delegation is the cure for a parent flooded by exploration.
  • Restrict its tools to what the subtask needs. Cap depth, concurrency and spend if the agent tree runs away.

Context-window management

  • Quality degrades as context grows, so problems appear before any hard limit.
  • Stale tool results: tool result clearing (clear_tool_uses_20250919). It invalidates the cached prefix when it clears; clear_at_least makes that worthwhile, and exclude_tools protects important results.
  • Long conversation near the limit: compaction (summary of older turns). Detail can be lost, so tune what the summary preserves.
  • In the Agent SDK, standing rules go in CLAUDE.md, not only in the first prompt.
  • Bloated or overlapping tool sets waste context and cause wrong tool choices.
  • Load data just in time through file paths, queries or links instead of preloading everything.

Memory and multi-session work

  • Nothing carries into a new conversation unless it is stored outside the context window, for example with the memory tool (client-side: your handler runs the file operations and must block path traversal).
  • For long builds: a first session writes a feature list, progress log and startup script; later sessions read them, test the baseline, do one feature, verify end to end and record the result.
  • Compaction and memory complement each other: one keeps the active context small, the other preserves what must survive the summary.

Traps

  • Deciding the loop is over because the response contains text.
  • Looping while stop_reason != "end_turn": a refusal or truncation never satisfies the condition, so the loop does not exit on its own.
  • Treating an iteration cap as the fix. It is a backstop; the exit condition is still wrong.
  • Raising max_tokens to cure input growth. It limits output.
  • Picking a bigger context window when the problem is relevance, lost instructions or cross-session state.
  • Expecting compaction to give a brand-new session any history.
  • Writing "fix the bug we discussed" as a subagent prompt.
  • Sending tool_result blocks for server tools.

Decide quickly

SituationChoiceWhy
Agent announces a step, then stopsKey the loop on stop_reasonText may precede a tool call
Research answer cut off with pause_turnResend with the paused turn appendedThe turn is unfinished
Old tool outputs dominate inputTool result clearingRemoves what is no longer needed
Long dialogue nears the limitCompactionKeeps the conversation going
Rule forgotten after compact_boundaryMove it to CLAUDE.mdRe-injected on every request
Exploration floods the main agentSubagentOnly the summary returns
Subagent solves the wrong problemRicher delegation promptIt cannot see the parent history
New session repeats old workMemory or progress filesState must live outside context
Agent declares victory earlyFeature list plus end-to-end checksGives an explicit definition of done

Sources