Skip to main content

1.3 Agent design patterns and agentic frameworks

The four patterns items are written against​

PatternMechanismFailure it prevents
Tool-use loopModel requests a tool, code executes it, result is appended, repeat until end_turnHallucinated data — the model reads real state instead of guessing
SubagentsDelegate a scoped subtask to an isolated context, return only the conclusionMain-context exhaustion; cross-task interference
MemoryDurable store outside the conversation the agent reads and writes deliberatelyLosing facts to compaction or a new session
Context-window managementPrune, clear, compact, or externalise as the window fillsSilent 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.

MechanismWhereNotes
Memory toolClaude 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 storesServer-side, per agentPersisted across sessions by the platform
Agent memory in Claude CodeCLAUDE.md hierarchy plus scratchpad files in the repoSee 3.1
Your own storeAny database keyed by session or userExplicit 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.

MechanismWhat it doesHow to request it
Context editingClears old tool results or thinking blocks before the model sees themclient.beta.messages.* with beta context-management-2025-06-27, context_management.edits = [{"type": "clear_tool_uses_20250919"}] (or clear_thinking_20251015)
CompactionSummarizes earlier context server-side when it approaches the trigger thresholdBeta compact-2026-01-12, context_management.edits = [{"type": "compact_20260112"}]
Task budgetsGives the model an advisory token ceiling so it paces itself and finishes gracefullyBeta task-budgets-2026-03-13, output_config.task_budget = {"type": "tokens", "total": 64000} (minimum 20,000)
Compaction's one hard rule

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.

FrameworkShapeFits
Strands — model-driven agent SDKModel plus tools plus a prompt; the loop is the framework'sGetting a tool-using agent running quickly with provider-agnostic plumbing
LangGraph — graph-based orchestrationExplicit graph of nodes and edges with typed state and checkpointsWorkflows where you want deterministic control flow, branching, retries, and resumable state
PydanticAI — type-first agentsType-first agents with Pydantic-validated inputs and outputsPython services where the value is schema-validated structured output

The decision criteria:

ChooseWhen
Raw API plus your own loopYou need full control, minimal dependencies, or an unusual control flow
SDK tool runnerYou want the standard loop without hand-writing it, with per-turn hooks
A graph frameworkThe control flow is the hard part — branching, resumability, human-in-the-loop checkpoints
A type-first frameworkValidated structured output is the primary requirement
Claude Agent SDKYou want a coding/filesystem agent with built-in tools on your own infra
Framework-neutral facts still apply

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​

  1. 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?

  2. 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?