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.
share
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:
- Prompt chaining: fixed subtasks in sequence, each call working on the last one's output.
- Routing: inputs in distinct categories, each sent to its own prompt or model.
- Parallelisation: independent subtasks run at once, or one task run several times for confidence.
- Orchestrator-workers: an LLM splits a task whose subtasks cannot be predicted and hands them to workers.
- 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
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.
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.
- 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.