CCDV-F · Agents and Workflows
Diagnosing which pattern a misbehaving agent is missing
A warehouse agent answers slowly when the user asks about three products, and now and then the API returns a 400 that mentions a tool_use without its tool_result. Another agent, a tutoring one, starts every session by pasting the student’s previous twenty conversations. A third, after an hour, begins ignoring the rules from the start. In all three the code “works”, but a pattern is missing or misapplied. The exam gives you a trace or a description and asks you to name which one.
How to read the behavior
Look at what the agent does too much, too little or out of order, and find the pattern that governs it:
| Symptom in the trace | Pattern missing or misapplied | Fix |
|---|---|---|
| The loop never ends, or ends when the text “sounds” final | Tool-use loop termination | Decide by stop_reason: tool_use continues, end_turn stops; add a step cap as a safety net, not as the normal way to finish |
400 for a tool_use without a tool_result |
One result per block | Walk every tool_use and return one tool_result for each, together, in the same user message |
| Takes the sum of several independent queries | Parallel tool use | Run independent, read-only calls at once; run dependent or side-effecting ones in order |
| A subagent pollutes the main agent with 20,000 tokens of exploration | Subagent isolation | The subagent works in its own context and returns only a structured summary |
| Every session starts from zero, or pastes the whole history | Memory tool | Short notes in your own storage, read only when needed |
| After an hour it ignores early rules and repeats steps | Context window management | Prune old outputs, compact, use subagents or start a fresh session with a summary |
| Skips a mandatory step “sometimes” | A hook is missing | The rule goes in code (PreToolUse), not in the prompt |
Memory: what lasts and where it lives
Short-term memory is the current conversation inside the context window: it is lost when the session ends and takes up room while it lasts. Long-term memory (preferences, decisions, progress) lives outside. The API offers the memory tool: Claude asks to create, read, edit or delete files in a /memories directory and your application runs each operation on the storage you control. It is a client-side tool, so you must validate every path so it never leaves that directory.
Keeping the window from filling up
In a long agent, tool outputs pile up. There are three ways to contain it: delegate to subagents that return summaries, remove or compact old outputs (context editing and compaction) and send what must last to external memory. A frequent distractor: prompt caching makes things cheaper and faster, but it frees not one token of the window.
Diagnosing without overcorrecting
The question is always “which pattern explains this behavior?”, not “what do I add?”. Adding more agents, another model or an orchestration framework does not fix a badly terminated loop or a missing tool_result. And strengthening the prompt does not fix a step that must be deterministic: that is a hook’s job.
The typical traps
- Processing only the first
tool_use, or sending the results in separate messages. - Ending the loop on a phrase from the model or on text length.
- Running independent read-only queries in series.
- Pasting the full history into every session instead of using memory with short notes.
- Implementing the memory tool without validating paths.
- Believing prompt caching solves a window that is filling up.
- Answering any failure with “more agents” or “a framework”.
On the exam
Read the trace the way a doctor reads a symptom. A 400 that names a tool_use without a result is a missing result in the loop. An agent that slows down on independent queries needs concurrent execution. If it has to remember between sessions, look for memory with your own storage. If it degrades in a long session, look for the context technique that attacks the cause (pruning, subagent, fresh session), not a cost one.
Quick question
A practice exam question on this domain. It counts towards your progress.
A SaaS company receives about 30,000 support tickets a month. Roughly 70% are routine: password resets, invoice copies, plan changes. They follow known procedures with three or four fixed steps. The remaining 30% are open-ended: integration problems, strange behaviors, edge cases that need investigation across logs and docs.
The team first built one autonomous agent for everything. Routine tickets are slow and expensive, and about 2% of them skip a required identity check. Open-ended tickets are handled well. The team has two backend engineers and a tight budget.
Which architecture best serves both kinds of tickets?