1.3 Agent design patterns and agentic frameworks
The four patterns items are written against
| Pattern | Mechanism | Failure it prevents |
|---|---|---|
| Tool-use loop | Model requests a tool, code executes it, result is appended, repeat until end_turn | Hallucinated data — the model reads real state instead of guessing |
| Subagents | Delegate a scoped subtask to an isolated context, return only the conclusion | Main-context exhaustion; cross-task interference |
| Memory | Durable store outside the conversation the agent reads and writes deliberately | Losing facts to compaction or a new session |
| Context-window management | Prune, clear, compact, or externalise as the window fills | Silent quality decay, then a hard context error |
Memory: outside the window, on purpose
The conversation is not storage. Anything that must survive a summary, a new session, or a subagent boundary belongs in memory.
| Mechanism | Where | Notes |
|---|---|---|
| Memory tool | Claude API — declare {"type": "memory_20250818", "name": "memory"} | Schema-less Anthropic-defined tool; you implement the backend (files, DB). Python/TypeScript ship base classes for it |
| Managed Agents memory stores | Server-side, per agent | Persisted across sessions by the platform |
| Agent memory in Claude Code | CLAUDE.md hierarchy plus scratchpad files in the repo | See 3.1 |
| Your own store | Any database keyed by session or user | Explicit reads and writes through a custom tool |
The pattern that scores: write structured facts, not transcripts. "Customer ID 88214, order 12345, damaged item, refund approved by policy 4.2" survives; three turns of dialogue do not.
Context-window management
Three server-side mechanisms, easy to confuse, and the exam confuses them deliberately.
| Mechanism | What it does | How to request it |
|---|---|---|
| Context editing | Clears old tool results or thinking blocks before the model sees them | client.beta.messages.* with beta context-management-2025-06-27, context_management.edits = [{"type": "clear_tool_uses_20250919"}] (or clear_thinking_20251015) |
| Compaction | Summarizes earlier context server-side when it approaches the trigger threshold | Beta compact-2026-01-12, context_management.edits = [{"type": "compact_20260112"}] |
| Task budgets | Gives the model an advisory token ceiling so it paces itself and finishes gracefully | Beta task-budgets-2026-03-13, output_config.task_budget = {"type": "tokens", "total": 64000} (minimum 20,000) |
Append response.content, not just the extracted text, on every turn. Compaction blocks in the response are what the API uses to replace the compacted history on the next request. Appending only the text silently loses the compaction state.
max_tokens is an enforced per-response ceiling the model is unaware of; a task budget is an advisory ceiling it is aware of. Items pair them to see whether you know the difference.
Application-level techniques that do not need a beta header:
- Prune tool output before appending it — return the three fields the model needs, not the 200-field payload.
- Externalise long artifacts to a file or store, and pass the handle.
- Delegate to a subagent so the verbose reading happens in a context you throw away.
More on this in 6.1 Context engineering.
Agentic abstraction frameworks
The guide names three explicitly. Items ask what a framework is for, not for its API.
| Framework | Shape | Fits |
|---|---|---|
| Strands — model-driven agent SDK | Model plus tools plus a prompt; the loop is the framework's | Getting a tool-using agent running quickly with provider-agnostic plumbing |
| LangGraph — graph-based orchestration | Explicit graph of nodes and edges with typed state and checkpoints | Workflows where you want deterministic control flow, branching, retries, and resumable state |
| PydanticAI — type-first agents | Type-first agents with Pydantic-validated inputs and outputs | Python services where the value is schema-validated structured output |
The decision criteria:
| Choose | When |
|---|---|
| Raw API plus your own loop | You need full control, minimal dependencies, or an unusual control flow |
| SDK tool runner | You want the standard loop without hand-writing it, with per-turn hooks |
| A graph framework | The control flow is the hard part — branching, resumability, human-in-the-loop checkpoints |
| A type-first framework | Validated structured output is the primary requirement |
| Claude Agent SDK | You want a coding/filesystem agent with built-in tools on your own infra |
A framework does not change the API contract underneath. stop_reason still drives termination, tool results still need matching IDs, caching still depends on prefix stability, and a framework's "memory" is still just a store you must design. Items that look framework-specific are usually testing the underlying mechanic.
Quiz
- Question 1
A long agent session uses server-side compaction. After the first compaction the agent behaves as though the conversation had restarted. The application extracts the text from each response, appends it to messages, and re-sends the array. What is the cause?
- Question 2
Three tools in one pipeline return timestamps as Unix seconds, Unix milliseconds, and ISO 8601 strings; two of them encode status as integer codes. The agent regularly misreads dates and statuses. Which fix is cleanest?
Links
- https://www.anthropic.com/engineering/building-effective-agents
- https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents
- https://platform.claude.com/docs/en/agents-and-tools/tool-use/memory-tool
- https://platform.claude.com/docs/en/build-with-claude/context-windows
- https://code.claude.com/docs/en/agent-sdk/subagents