Task statement 1.3 · Agents and workflows

1.3 · Agent Patterns and Frameworks

Shelfwise, the course example, is one agent in the Agent SDK's tool loop, and each staff chat is its own session. A pattern answers one limit that a multi-step agent hits, and a framework packages patterns behind its own code. Shelfwise has needed one pattern and no framework.

Why it's tested

The tempting start is the full kit of framework, memory store, subagents and automatic summaries, because tutorials show them together. Each pattern answers one limit and adds requests or code you did not write, so one added before its limit appears only makes the agent harder to debug. Memory can even make answers worse, because a note about something that changes hourly is read back as current.

Start hereThree terms this section adds

agent memory
Information an agent writes outside its context window, usually as files, and reads back later.
compaction
Replacing older turns with a summary, so a long task still fits its context window.
abstraction framework
A library that runs agent patterns behind its own API.

KnowledgeCommon agent design patterns for multi-step tasks

Anthropic's "Building effective agents" builds every pattern from an augmented LLM, a model given retrieval, tools and memory. The guide's four patterns each handle one limit. The tool-use loop handles a route that depends on results: Claude calls a tool, reads the tool_result and decides again until stop_reason is end_turn, as 1.2 builds by hand. Subagents handle reading that would swamp one context window, because each returns only a condensed summary, often 1,000–2,000 tokens in Anthropic's context-engineering post (1.1 covers when that pays). Memory handles facts that must outlive a session, and context-window management handles a task that outgrows its window. The same post matches compaction to long back-and-forth, note-taking to work with clear milestones, and multi-agent work to parallel research.

When code holds the route, five workflow patterns from "Building effective agents" set LLM calls on fixed paths:

  1. Prompt chaining: fixed subtasks in sequence, each call working on the last one's output.
  2. Routing: inputs in distinct categories, each sent to its own prompt or model.
  3. Parallelisation: independent subtasks run at once, or one task run several times for confidence.
  4. Orchestrator-workers: an LLM splits a task whose subtasks cannot be predicted and hands them to workers.
  5. Evaluator-optimiser: one call drafts and another grades it against clear criteria, looping while rounds help.

Claude Code's dynamic workflows, run by its Workflow tool, use the word differently: a script Claude writes to orchestrate subagents, not a path you code in advance.

Interactive · what each pattern does to the context window

Four patterns side by side, each read from top to bottom. Tool-use loop: a request enters one context window where Claude calls a tool and each tool result is appended, so the history grows until Claude ends the turn with an answer. Subagent: the main agent's context window sends a prompt to a subagent in its own context window outside it, which reads many files and returns only a summary. Memory: Claude in session 1 writes a note to storage you control outside the window, and Claude in session 2 reads it back. Context management: a window near its limit has its oldest tool results replaced by placeholders or its older turns replaced by a summary, leaving the recent turns and room to continue. Tool-use loop request Claude tool tool_result 1 tool_result 2 tool_result 3 ONE CONTEXT WINDOW end_turn answer history grows each turn RESENT ON EVERY REQUEST Subagent main agent answer MAIN WINDOW subagent reads files OWN WINDOW prompt summary reading stays outside ONLY THE SUMMARY RETURNS Memory Claude SESSION 1 notes your storage write Claude SESSION 2 read back outlives the session RE-ENTERS AS CONTEXT Context management old tool results older turns recent turns NEAR THE LIMIT clear or summarise placeholder summary recent turns ROOM TO CONTINUE same task, smaller history EXACT DETAIL CAN BE LOST

Choose a pattern to see what it keeps in the context window and what it moves out.

Tool-use loop: Claude calls a tool, its result is appended to the history, and the whole history is resent on the next request, so one context window grows with every turn until Claude ends the turn.

Subagent: the main agent sends a prompt to a subagent working in its own context window; the subagent's reading stays there, and only its condensed summary enters the main window.

Memory: Claude writes a note through a tool to storage outside the context window, and a later session reads it back, so the note outlives the session but returns as context, current or not.

Context management: near the limit, context editing replaces the oldest tool results with placeholders, or compaction replaces older turns with a summary, so the task continues but exact detail can be lost.

Each column reads downward. Amber is Claude's work, green a tool or subagent, blue your code or storage, grey rows history, and a dashed ember border a context window.

KnowledgeMemory: short-term and persistent

Short-term memory is the context window itself: the Messages API is stateless, so the history your code resends is all Claude knows, and it ends with the session. Persistent memory sits outside the window, at three layers. The API's memory tool (memory_20250818) is client-side: Claude asks to view, create, edit, rename or delete files under /memories, and your code runs each command against storage you choose. Claude Code's auto memory is notes Claude writes itself under ~/.claude/projects/<project>/memory/, loaded at each session's start beside CLAUDE.md, the instructions file you write, and both are context, not enforced configuration. Managed Agents memory stores, in beta, mount a store into the session's sandbox as a directory. Every layer re-enters the window as text, so a stale or injected note reads as current, which is why the docs advise read_only access for a store that untrusted input could reach.

More precise than the guide. No single docs feature is called "Agent Memory", which the guide lists among Claude Code's components (as of 2026-10-05): the closest match in Claude Code's docs is a subagent's memory field, stored in .claude/agent-memory/<name>/ at project scope, and Managed Agents' memory-store page is titled "Using agent memory". Exam answer: agent memory is what the agent itself writes and reads through tools, apart from the instructions you write and the session's context.

KnowledgeContext-window management

When one task outgrows its context window, the API offers two managed responses, both in beta. Context editing (clear_tool_uses_20250919) replaces the oldest tool results with placeholders before the request reaches Claude, by default once input passes 100,000 tokens, keeping the last three. Compaction replaces older turns with a summary Claude writes on the server, on request or at a threshold you set, and the docs make it the primary strategy for long conversations. Both drop detail, so a value the next step needs exactly must be written somewhere first, and with the memory tool enabled, context editing warns Claude before clearing so it can save what matters. 6.1 covers this in depth.

KnowledgeAgentic abstraction frameworks

An abstraction framework packages these patterns so you configure them instead of writing them. LangGraph, from LangChain, is an orchestration framework and runtime for long-running, stateful agents: it models a workflow as a graph whose nodes are functions and whose edges pick the next node from shared state, mixing fixed steps with LLM-driven ones. Strands Agents, an open-source SDK from AWS, wraps a model in an agent loop that runs in your process, with Amazon Bedrock as the default provider. PydanticAI (its docs write Pydantic AI) is a typed agent loop whose model is a string you can swap. "Building effective agents" lists the Claude Agent SDK (1.2) and Strands among frameworks, and warns that their layers "obscure the underlying prompts and responses, making them harder to debug". It advises starting with the API directly, and understanding a framework's underlying code if you adopt one.

SkillWorked example: the memory Shelfwise turned down

Shelfwise uses one pattern, a tool-use loop of about three requests, with no subagents (1.1). Its memory is each chat's own session, resumed by session_id (2.5), far from its context window's limit. A proposal to remember counts across chats, hypothetical and never built, shows why it keeps no persistent memory:

# proposal (hypothetical, not built): auto memory keeps counts across chats
09:40 chat → note (needs Write and Edit): "4 mm drill bits · Leeds · 12 (feed 09:00)"
15:10 new chat → the note loads into the system prompt
  "any 4 mm drill bits at Leeds?" → "12 in stock" from the note, no lookup
# decision: memory stays per chat; counts come only from stock_lookup
ClaudeAgentOptions(setting_sources=[], env={..., "CLAUDE_CODE_DISABLE_AUTO_MEMORY": "1"})

A count belongs to the feed, which changes hourly, so a remembered count would be an old count given with no lookup, as in 2.5. The review also found that auto memory loads regardless of setting_sources, so the service now turns it off in its env options. A rewrite onto a graph framework, also hypothetical and rejected, would put a layer between the team and the cached ≈6,000-token prefix that keeps answers under $0.01.

Before adding a pattern or a framework, ask: which limit has the agent actually hit? The next step depends on the last result → a tool-use loop, and nothing more. Reading swamps a context window, or a task outgrows it → a subagent, context editing or compaction. A fact must outlive the session and stay true → persistent memory. A framework → only for an abstraction you can name, such as a graph with persisted state.
Takeaway
  • The memory tool is client-side: Claude requests file commands under /memories, and your code runs them.
  • Context editing swaps old tool results for placeholders, and compaction swaps older turns for a summary.
  • LangGraph is a graph over shared state, Strands Agents an in-process loop, PydanticAI a typed loop.

check yourself

0 / 3 answered

A Messages API agent reconciles 3,000 invoices in batches of 50 within one long conversation. Its requests turn on context editing, which clears old tool results, and compaction at a 150,000-token threshold. After batch 31 it starts batch 12 again. The request log shows the results for batches 1–28 each replaced by a short placeholder saying the result was removed.What is the most likely root cause?

Select one.

A three-engineer team runs a Claude-only triage agent as a 70-line Messages API loop with four tools. A new rule says a supervisor must approve every refund tool call before it runs, which can take two days, and the run must then continue where it stopped, even after a service restart.Which approach most proportionately meets the new rule?

Select one.

One run of a journal's statistics check gives a quarter false flags and misses real errors, while a rerun rarely repeats a false flag and often catches a missed error. False flags and misses occur alike across study types. An editing step rewrites each manuscript until a grader scores it at least 8/10 on a fixed rubric, within three rounds.Which TWO workflow patterns best cut false flags without missing more real errors, and fit the editing step?

Select two.

sources

  1. Anthropic Engineering, "Building effective agents": the augmented LLM with retrieval, tools and memory; when to use prompt chaining, routing, parallelisation, orchestrator-workers and evaluator-optimiser; frameworks named (the Claude Agent SDK, Strands Agents SDK by AWS, Rivet, Vellum); abstraction that obscures prompts and responses; start with LLM APIs directly; understand the underlying code. Checked 2026-10-04.
  2. Anthropic Engineering, "Effective context engineering for AI agents": compaction, structured note-taking and multi-agent architectures for long-horizon tasks, and which task each suits; a sub-agent's condensed summary of often 1,000–2,000 tokens. Checked 2026-10-04.
  3. Claude API Docs, "Memory tool": memory_20250818; client-side operation; the six commands under /memories; Claude checks its memory directory before a task; pairing with context editing and compaction. Checked 2026-10-04.
  4. Claude API Docs, "Context editing" and "Compaction overview": clear_tool_uses_20250919, its 100,000-token trigger and three kept tool uses, placeholders, server-side application, the memory-tool warning; compaction on demand or at a threshold, both in beta; compaction as the primary strategy. Checked 2026-10-04.
  5. Claude API Docs, "Using agent memory": memory stores, in beta, mounted as a directory in the session's sandbox; read_only access for stores untrusted input could reach. Checked 2026-10-04.
  6. Claude Code Docs, "How Claude remembers your project", "Create custom subagents" and "Use Claude Code features in the SDK": CLAUDE.md written by you, auto memory written by Claude, both context; the auto memory directory; the subagent memory field; auto memory read regardless of settingSources, saved with Write and Edit, and turned off with CLAUDE_CODE_DISABLE_AUTO_MEMORY. Checked 2026-10-04.
  7. Claude Code Docs, "Orchestrate subagents at scale with dynamic workflows": a script Claude writes that orchestrates many subagents, run through the Workflow tool. Checked 2026-10-04.
  8. Framework docs, for one or two defining facts each: LangGraph overview and Graph API (orchestration framework and runtime; graphs of state, nodes and edges); Strands Agents (open-source SDK; in-process loop; Amazon Bedrock default provider); Pydantic AI (typed agent loop; swappable models). Checked 2026-10-04.
  9. The auto-memory proposal, the graph-framework rewrite and the CLAUDE_CODE_DISABLE_AUTO_MEMORY setting are this course's additions to Shelfwise; the proposal and the rewrite are hypothetical and not built.