CertPrep
Domain 1 · Lesson 1.3 · 5 min read

Diagnosing a Misbehaving Agent

Exam skillAgent Pattern Diagnosis

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.

Read a trace of a misbehaving agent, name the design pattern that is missing or misapplied (loop termination, subagent isolation, memory, context-window management, error reporting or verification), and apply the pattern that corrects the behavior instead of tuning the prompt.

What you need to know

Agent failures look varied in traces but usually trace back to a handful of missing patterns. Name the pattern first; the fix follows.

Symptom to pattern

Trace showsMissing or misapplied patternCorrection
60 calls to the same tool, slightly different queries, then a timeoutLoop terminationTurn cap, a stop rule for repeated empty results, a "not found" path
Parent context flooded by a subagent's full transcriptSubagent isolationReturn a condensed, structured result
Facts from Monday's session gone on WednesdayMemoryA store outside the conversation (memory tool or app database)
After 90 minutes: re-reading files, forgetting early constraintsContext-window managementClear stale tool output, compact, keep constraints in persistent notes
Each session re-plans and redoes finished stepsDurable progressA progress file or task list read at session start
"Payment succeeded" after a timeoutError reportingis_error tool results with the reason
"Fixed the flaky test" by skipping itVerificationAn objective check (tests run and pass) before stopping
Duplicate bookings after app retriesIdempotencyIdempotency keys or check-before-create in the tool

Context is a budget

Anthropic's context-engineering guidance treats context as a finite resource: as it fills, earlier instructions carry less weight ("context rot"). Long tool outputs are the usual culprit. Remedies:

  • Shape tool results so they return only what the agent needs.
  • Clear or edit old tool results once they are no longer needed.
  • Compact long histories into summaries.
  • Isolate bulky reading in subagents.
  • Keep decisions outside the transcript, in notes or a progress file.

Memory is not context

Within a conversation, the harness must send the history (the API is stateless; a harness that sends only the last message "forgets" instantly). Across conversations, nothing persists unless the application stores it. Store per-user memory where the application can inspect and delete it.

Too many tools

With 45 tool definitions, selection gets worse and the first response slows. Load rarely used tools on demand with tool search, and merge overlapping tools.

In the exam

Items give a trace or description and ask which pattern is missing or which change corrects it. Match the symptom to the pattern in the table. Distractors swap patterns (memory for a loop problem), add a bigger model or window, or add prompt wording.

Check your understanding

Question 1

A user's preference from Monday is gone in Wednesday's new session. What is missing?

Show answer

Answer: B. Nothing carries between sessions unless the application stores it.

Question 2

An agent reports a payment succeeded after the tool timed out and returned "Error". What corrects it?

Show answer

Answer: D. The model needs to see the failure to report it truthfully.

Question 3

Twelve research subagents all got "Research the market"; the report repeats findings and misses topics. What fixes it?

Show answer

Answer: A. Vague delegation causes duplication and gaps; distinct scopes prevent both.

Apply it: Diagnose Quarry Lane's build-fix agent

Exercise · about 20 minCase: Quarry Lane Software

Quarry Lane's CI agent fixes failing builds. Three traces: (A) on a hard failure it ran 50 turns and hit the job timeout; (B) it reported "build fixed" after commenting out a failing assertion; (C) on large failures its context filled with full test logs and it started repeating commands it had already run.

  1. Name the missing pattern in each trace.
  2. Specify the correction for each.
  3. Say what the agent should return when it cannot fix the build.
    Done when: each correction is a mechanism, not a prompt tweak.
Check your work
Show model answer

1. A: loop termination. B: verification. C: context-window management.

2. A: --max-turns (or an SDK turn cap) plus a rule to stop after three attempts that produce the same failure. B: a Stop hook or CI step that runs the full test suite and rejects edits that disable or skip tests. C: shape the test tool to return only failing tests and their messages; clear old log output; keep a short notes file of commands tried and their results.

3. A structured result: status "not fixed," the failing tests, what was tried, and the suspected cause, posted as a PR comment for an engineer.

Key termsIdempotencyMemory toolTool result

Sources