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 shows | Missing or misapplied pattern | Correction |
|---|---|---|
| 60 calls to the same tool, slightly different queries, then a timeout | Loop termination | Turn cap, a stop rule for repeated empty results, a "not found" path |
| Parent context flooded by a subagent's full transcript | Subagent isolation | Return a condensed, structured result |
| Facts from Monday's session gone on Wednesday | Memory | A store outside the conversation (memory tool or app database) |
| After 90 minutes: re-reading files, forgetting early constraints | Context-window management | Clear stale tool output, compact, keep constraints in persistent notes |
| Each session re-plans and redoes finished steps | Durable progress | A progress file or task list read at session start |
| "Payment succeeded" after a timeout | Error reporting | is_error tool results with the reason |
| "Fixed the flaky test" by skipping it | Verification | An objective check (tests run and pass) before stopping |
| Duplicate bookings after app retries | Idempotency | Idempotency 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
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.
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.
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
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.
- Name the missing pattern in each trace.
- Specify the correction for each.
- Say what the agent should return when it cannot fix the build.
Done when: each correction is a mechanism, not a prompt tweak.
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.