<map version="1.0.1">
<node ID="ID_1633" TEXT="Chapter 4 — Agents and workflows"><richcontent TYPE="NOTE"><html><head></head><body><p>2026-09-28 → 2026-10-04</p><p>Agents &amp; Workflows</p></body></html></richcontent><node ID="ID_1336" TEXT="🎯 Goal"><richcontent TYPE="NOTE"><html><head></head><body><p>Choose between a single call, a workflow and an agent for any scenario; name the five patterns; build a guarded agent with the Agent SDK.</p></body></html></richcontent></node><node ID="ID_1338" TEXT="Exam domains"><node ID="ID_1337" TEXT="Agents &amp; Workflows — 14.7%"></node></node><node ID="ID_1417" TEXT="📅 Daily plan"><node ID="ID_1348" TEXT="09-28 · Workflows vs agents; the agent loop (model → tool → observe → repea…"><node ID="ID_1339" TEXT="Learn: Workflows vs agents; the agent loop (model → tool → observe → repeat); when not to build an agent"></node><node ID="ID_1344" TEXT="Build: Implement a 3-step prompt chain in Python"><node ID="ID_1340" TEXT="Read the article twice; write its definitions of workflow and agent into notes/agents.md in your own words."></node><node ID="ID_1341" TEXT="ch4/chain.py: step 1 extract facts from a PR diff → step 2 write a changelog entry → step 3 check the entry against the facts (gate) and reject/redo if mismatched."></node><node ID="ID_1342" TEXT="Log tokens per step; note that chaining costs more calls but each is cheaper and testable."></node><node ID="ID_1343" TEXT="List three tasks from your day job that are workflows and one that truly needs an agent."></node></node><node ID="ID_1345" TEXT="✔ Done when: Chain runs with a programmatic gate between steps; notes hold the definitions and your examples."></node><node ID="ID_1347" TEXT="Read"><node ID="ID_1346" TEXT="Building effective agents (Anthropic engineering)" LINK="https://www.anthropic.com/engineering/building-effective-agents"><richcontent TYPE="NOTE"><html><head></head><body><p>https://www.anthropic.com/engineering/building-effective-agents</p></body></html></richcontent></node></node></node><node ID="ID_1360" TEXT="09-29 · Patterns: prompt chaining, routing, parallelisation, orchestrator–w…"><node ID="ID_1349" TEXT="Learn: Patterns: prompt chaining, routing, parallelisation, orchestrator–workers, evaluator–optimizer"></node><node ID="ID_1354" TEXT="Build: Build a router that sends tickets to different prompts"><node ID="ID_1350" TEXT="ch4/router.py: Haiku classifies a ticket as billing / outage / how-to; each class goes to a different system prompt and model (outage → Sonnet)."></node><node ID="ID_1351" TEXT="Add parallelisation: send the same ticket to three graders concurrently (asyncio.gather) and take the majority vote (voting) — then split a long doc into sections summarised concurrently (sectioning)."></node><node ID="ID_1352" TEXT="Sketch orchestrator–workers and evaluator–optimizer on paper; note which needs the model to decide the sub-tasks dynamically (orchestrator) versus code doing it (parallelisation)."></node><node ID="ID_1353" TEXT="Fill a table: pattern → when → cost profile → failure mode."></node></node><node ID="ID_1355" TEXT="✔ Done when: Router and both parallel variants run; the pattern table is in notes."></node><node ID="ID_1359" TEXT="Read"><node ID="ID_1356" TEXT="Building effective agents — workflow patterns section" LINK="https://www.anthropic.com/engineering/building-effective-agents"><richcontent TYPE="NOTE"><html><head></head><body><p>https://www.anthropic.com/engineering/building-effective-agents</p></body></html></richcontent></node><node ID="ID_1357" TEXT="Anthropic cookbook: agent patterns" LINK="https://github.com/anthropics/anthropic-cookbook/tree/main/patterns/agents"><richcontent TYPE="NOTE"><html><head></head><body><p>https://github.com/anthropics/anthropic-cookbook/tree/main/patterns/agents</p></body></html></richcontent></node><node ID="ID_1358" TEXT="Library: agentpatterns"></node></node></node><node ID="ID_1371" TEXT="09-30 · Agent SDK: what it adds over the raw API (tool loop, context manage…"><node ID="ID_1361" TEXT="Learn: Agent SDK: what it adds over the raw API (tool loop, context management, subagents, permissions)"></node><node ID="ID_1366" TEXT="Build: Run the Agent SDK quickstart"><node ID="ID_1362" TEXT="pip install claude-agent-sdk (or npm i @anthropic-ai/claude-agent-sdk); run the quickstart: query() with a prompt that reads a file in your repo and reports on it."></node><node ID="ID_1363" TEXT="List what the SDK gave you for free: built-in tools (Read, Edit, Bash, Grep…), the loop, permission prompts, context compaction, CLAUDE.md loading, MCP support, subagents, hooks."></node><node ID="ID_1364" TEXT="Set allowed_tools to a read-only set and watch a write attempt get denied; then try permission_mode options."></node><node ID="ID_1365" TEXT="Compare with your hand-written loop from Chapter 2 — write down three things the SDK handles that you would have had to build."></node></node><node ID="ID_1367" TEXT="✔ Done when: Quickstart runs against your repo with a restricted tool set; notes list what the SDK adds."></node><node ID="ID_1370" TEXT="Read"><node ID="ID_1368" TEXT="Agent SDK overview" LINK="https://docs.claude.com/en/api/agent-sdk/overview"><richcontent TYPE="NOTE"><html><head></head><body><p>https://docs.claude.com/en/api/agent-sdk/overview</p></body></html></richcontent></node><node ID="ID_1369" TEXT="Agent SDK Python" LINK="https://docs.claude.com/en/api/agent-sdk/python"><richcontent TYPE="NOTE"><html><head></head><body><p>https://docs.claude.com/en/api/agent-sdk/python</p></body></html></richcontent></node></node></node><node ID="ID_1383" TEXT="10-01 · Subagents and delegation; memory and state; stopping conditions and…"><node ID="ID_1372" TEXT="Learn: Subagents and delegation; memory and state; stopping conditions and max turns"></node><node ID="ID_1377" TEXT="Build: Orchestrator + one worker agent on a real task from your dev project"><node ID="ID_1373" TEXT="Define a 'reviewer' subagent (own system prompt, read-only tools) and have the orchestrator delegate 'review these 3 files for error handling' to it."></node><node ID="ID_1374" TEXT="Set max_turns and a token budget; make the run stop cleanly and report what it finished."></node><node ID="ID_1375" TEXT="Persist and resume a session (session id) so the agent continues a task after a restart."></node><node ID="ID_1376" TEXT="Note the trade-off: a subagent gets a fresh, isolated context (good for focus, no pollution) but costs extra tokens and only returns a summary."></node></node><node ID="ID_1378" TEXT="✔ Done when: Orchestrator delegates to a worker, respects max_turns, and resumes from a saved session."></node><node ID="ID_1382" TEXT="Read"><node ID="ID_1379" TEXT="Agent SDK: subagents" LINK="https://docs.claude.com/en/api/agent-sdk/subagents"><richcontent TYPE="NOTE"><html><head></head><body><p>https://docs.claude.com/en/api/agent-sdk/subagents</p></body></html></richcontent></node><node ID="ID_1380" TEXT="Agent SDK: sessions and state" LINK="https://docs.claude.com/en/api/agent-sdk/sessions"><richcontent TYPE="NOTE"><html><head></head><body><p>https://docs.claude.com/en/api/agent-sdk/sessions</p></body></html></richcontent></node><node ID="ID_1381" TEXT="How we built our multi-agent research system" LINK="https://www.anthropic.com/engineering/multi-agent-research-system"><richcontent TYPE="NOTE"><html><head></head><body><p>https://www.anthropic.com/engineering/multi-agent-research-system</p></body></html></richcontent></node></node></node><node ID="ID_1396" TEXT="10-02 · Built-in server tools: web search, web fetch, code execution; Skill…"><node ID="ID_1384" TEXT="Learn: Built-in server tools: web search, web fetch, code execution; Skills concept"></node><node ID="ID_1389" TEXT="Build: Call web search from the API and cite results"><node ID="ID_1385" TEXT="Add tools=[{type:&quot;web_search_20250305&quot;, name:&quot;web_search&quot;, max_uses:3}] and ask about a recent Kubernetes CVE; print the citations from the response blocks."></node><node ID="ID_1386" TEXT="Try the code execution tool to compute statistics from a CSV you upload via the Files API."></node><node ID="ID_1387" TEXT="Read what a Skill is (a folder with SKILL.md + resources, loaded progressively when relevant) and how it differs from a tool (instructions/knowledge vs an action)."></node><node ID="ID_1388" TEXT="Write a 'client tool vs server tool vs MCP vs Skill' comparison in notes."></node></node><node ID="ID_1390" TEXT="✔ Done when: Web search call returns cited results; comparison table written."></node><node ID="ID_1395" TEXT="Read"><node ID="ID_1391" TEXT="Web search tool" LINK="https://docs.claude.com/en/docs/agents-and-tools/tool-use/web-search-tool"><richcontent TYPE="NOTE"><html><head></head><body><p>https://docs.claude.com/en/docs/agents-and-tools/tool-use/web-search-tool</p></body></html></richcontent></node><node ID="ID_1392" TEXT="Web fetch tool" LINK="https://docs.claude.com/en/docs/agents-and-tools/tool-use/web-fetch-tool"><richcontent TYPE="NOTE"><html><head></head><body><p>https://docs.claude.com/en/docs/agents-and-tools/tool-use/web-fetch-tool</p></body></html></richcontent></node><node ID="ID_1393" TEXT="Code execution tool" LINK="https://docs.claude.com/en/docs/agents-and-tools/tool-use/code-execution-tool"><richcontent TYPE="NOTE"><html><head></head><body><p>https://docs.claude.com/en/docs/agents-and-tools/tool-use/code-execution-tool</p></body></html></richcontent></node><node ID="ID_1394" TEXT="Agent Skills" LINK="https://docs.claude.com/en/docs/agents-and-tools/agent-skills/overview"><richcontent TYPE="NOTE"><html><head></head><body><p>https://docs.claude.com/en/docs/agents-and-tools/agent-skills/overview</p></body></html></richcontent></node></node></node><node ID="ID_1407" TEXT="10-03 · Failure modes: loops, runaway cost, hallucinated tools, lost contex…"><node ID="ID_1397" TEXT="Learn: Failure modes: loops, runaway cost, hallucinated tools, lost context — and guards for each"></node><node ID="ID_1402" TEXT="Build: Add max-turn and cost guards to your agent"><node ID="ID_1398" TEXT="Give your agent a broken tool that always errors; watch for a retry loop; add loop detection (same tool+args 3× → stop and ask)."></node><node ID="ID_1399" TEXT="Add a cost guard: sum usage across turns; stop at a USD threshold."></node><node ID="ID_1400" TEXT="Add a human checkpoint: any tool flagged destructive requires approval before execution (hook or permission callback)."></node><node ID="ID_1401" TEXT="Improve one tool description and result format following the 'writing tools for agents' article; measure fewer wasted calls."></node></node><node ID="ID_1403" TEXT="✔ Done when: Agent stops itself on loops and budget, and asks before destructive actions."></node><node ID="ID_1406" TEXT="Read"><node ID="ID_1404" TEXT="Building effective agents — 'when to use agents' and appendix" LINK="https://www.anthropic.com/engineering/building-effective-agents"><richcontent TYPE="NOTE"><html><head></head><body><p>https://www.anthropic.com/engineering/building-effective-agents</p></body></html></richcontent></node><node ID="ID_1405" TEXT="Writing tools for agents" LINK="https://www.anthropic.com/engineering/writing-tools-for-agents"><richcontent TYPE="NOTE"><html><head></head><body><p>https://www.anthropic.com/engineering/writing-tools-for-agents</p></body></html></richcontent></node></node></node><node ID="ID_1416" TEXT="10-04 · Review day"><node ID="ID_1408" TEXT="Learn: Review day"></node><node ID="ID_1412" TEXT="Build: Write notes/agents.md"><node ID="ID_1409" TEXT="Finish notes/agents.md: definitions, pattern table, agent loop, SDK features, guards, tool/server-tool/MCP/Skill comparison."></node><node ID="ID_1410" TEXT="Self-check; then the Agents &amp; Workflows quiz in the Question bank."></node><node ID="ID_1411" TEXT="Weekly retrospective."></node></node><node ID="ID_1413" TEXT="✔ Done when: Notes committed; quiz recorded; retrospective filled."></node><node ID="ID_1415" TEXT="Read"><node ID="ID_1414" TEXT="Study material below"></node></node></node></node><node ID="ID_1454" TEXT="📖 Study material"><node ID="ID_1422" TEXT="Definitions (Anthropic's framing)"><node ID="ID_1418" TEXT="Augmented LLM: one model call with retrieval, tools and memory — the building block."></node><node ID="ID_1419" TEXT="Workflow: LLM calls orchestrated by code along predefined paths. Predictable,…"><richcontent TYPE="NOTE"><html><head></head><body><p>Workflow: LLM calls orchestrated by code along predefined paths. Predictable, testable, cheap, easy to debug. Prefer this whenever the steps are known.</p></body></html></richcontent></node><node ID="ID_1420" TEXT="Agent: the model decides the path — choosing tools in a loop, observing results, until…"><richcontent TYPE="NOTE"><html><head></head><body><p>Agent: the model decides the path — choosing tools in a loop, observing results, until done. Use only when the task genuinely needs open-ended decisions and the number of steps is unknown. Costs more, harder to test, needs guardrails.</p></body></html></richcontent></node><node ID="ID_1421" TEXT="Rule: find the simplest solution possible; increase complexity only when it…"><richcontent TYPE="NOTE"><html><head></head><body><p>Rule: find the simplest solution possible; increase complexity only when it demonstrably improves outcomes. Many &quot;agent&quot; requests are really a single well-crafted prompt.</p></body></html></richcontent></node></node><node ID="ID_1428" TEXT="The five workflow patterns"><node ID="ID_1423" TEXT="Prompt chaining"><richcontent TYPE="NOTE"><html><head></head><body><p>A → gate → B → C · task decomposes into fixed steps; add programmatic checks between steps · more latency; each step must be verifiable</p></body></html></richcontent></node><node ID="ID_1424" TEXT="Routing"><richcontent TYPE="NOTE"><html><head></head><body><p>classify → specialised prompt/model · distinct input categories handled differently (support tiers, cheap vs expensive model) · misroutes; keep the classifier cheap and evaluated</p></body></html></richcontent></node><node ID="ID_1425" TEXT="Parallelisation"><richcontent TYPE="NOTE"><html><head></head><body><p>sectioning (split work) or voting (same task N times) · independent subtasks; need multiple perspectives or confidence · cost × N; aggregation logic</p></body></html></richcontent></node><node ID="ID_1426" TEXT="Orchestrator–workers"><richcontent TYPE="NOTE"><html><head></head><body><p>lead model plans sub-tasks dynamically, delegates, merges · sub-tasks not predictable in advance (multi-file code change, research) · token cost; workers need clear briefs and return summaries</p></body></html></richcontent></node><node ID="ID_1427" TEXT="Evaluator–optimizer"><richcontent TYPE="NOTE"><html><head></head><body><p>generator ↔ critic loop · clear evaluation criteria and iteration measurably helps (translation, code with tests) · infinite loops — cap iterations</p></body></html></richcontent></node></node><node ID="ID_1432" TEXT="The agent loop"><node ID="ID_1429" TEXT="Receive task → (model reasons → picks tool → your code runs it → result appended) × N…"><richcontent TYPE="NOTE"><html><head></head><body><p>Receive task → (model reasons → picks tool → your code runs it → result appended) × N → model signals done. Ground truth comes from tool results, so tool result quality drives agent quality.</p></body></html></richcontent></node><node ID="ID_1430" TEXT="Always give the agent: a clear goal and stopping condition, a small well-described…"><richcontent TYPE="NOTE"><html><head></head><body><p>Always give the agent: a clear goal and stopping condition, a small well-described tool set, max turns, a budget, and checkpoints for human approval before side effects.</p></body></html></richcontent></node><node ID="ID_1431" TEXT="Failure modes and guards: loops → loop detection + max turns; runaway cost → token/USD…"><richcontent TYPE="NOTE"><html><head></head><body><p>Failure modes and guards: loops → loop detection + max turns; runaway cost → token/USD budget; hallucinated tools/args → strict schemas, is_error feedback; lost context → compaction, memory/scratchpad files, subagents; destructive actions → permission callbacks/hooks, dry-run tools.</p></body></html></richcontent></node></node><node ID="ID_1436" TEXT="Claude Agent SDK"><node ID="ID_1433" TEXT="The framework behind Claude Code, exposed as a library (Python and TypeScript). You…"><richcontent TYPE="NOTE"><html><head></head><body><p>The framework behind Claude Code, exposed as a library (Python and TypeScript). You describe the task; it runs the loop with built-in tools (file read/edit, bash, grep, web), permission handling, automatic context compaction, CLAUDE.md/project context, MCP servers, subagents, hooks and session persistence.</p></body></html></richcontent></node><node ID="ID_1434" TEXT="Key knobs: allowed_tools / disallowed tools, permission_mode, max_turns, system…"><richcontent TYPE="NOTE"><html><head></head><body><p>Key knobs: allowed_tools / disallowed tools, permission_mode, max_turns, system prompt, MCP config, custom tools (in-process MCP), subagent definitions.</p></body></html></richcontent></node><node ID="ID_1435" TEXT="Use it when you want an agent that acts on files/systems; use the raw Messages API…"><richcontent TYPE="NOTE"><html><head></head><body><p>Use it when you want an agent that acts on files/systems; use the raw Messages API when you want tight control or a simple workflow.</p></body></html></richcontent></node></node><node ID="ID_1440" TEXT="Subagents, memory, state"><node ID="ID_1437" TEXT="A subagent runs in its own context window with its own system prompt and tool set and…"><richcontent TYPE="NOTE"><html><head></head><body><p>A subagent runs in its own context window with its own system prompt and tool set and returns a result to the parent. Benefits: isolation, parallelism, specialised roles. Cost: extra tokens; the parent only sees a summary — brief it well.</p></body></html></richcontent></node><node ID="ID_1438" TEXT="Short-term memory = the context window; long-term = files, a memory tool, a database,…"><richcontent TYPE="NOTE"><html><head></head><body><p>Short-term memory = the context window; long-term = files, a memory tool, a database, or a retrieval store the agent reads and writes.</p></body></html></richcontent></node><node ID="ID_1439" TEXT="Sessions can be persisted and resumed; design tasks to be resumable and idempotent."></node></node><node ID="ID_1451" TEXT="Server tools and Skills"><node ID="ID_1441" TEXT="Server tools (web search, web fetch, code execution, computer use, text editor, bash)…"><richcontent TYPE="NOTE"><html><head></head><body><p>Server tools (web search, web fetch, code execution, computer use, text editor, bash) execute on Anthropic's infrastructure; you add them to tools and get results and citations back without running anything.</p></body></html></richcontent></node><node ID="ID_1442" TEXT="Skills: folders of instructions (SKILL.md) plus scripts/resources that Claude loads…"><richcontent TYPE="NOTE"><html><head></head><body><p>Skills: folders of instructions (SKILL.md) plus scripts/resources that Claude loads progressively when the task matches — knowledge and procedures, not actions. Tools do things; Skills teach how.</p></body></html></richcontent></node><node ID="ID_1443" TEXT="MCP (Chapter 5): a standard way to plug external tools/resources into any client."></node><node ID="ID_1450" TEXT="⚠ Exam traps"><node ID="ID_1444" TEXT="Simplest solution wins — a single prompt or a workflow before an agent."></node><node ID="ID_1445" TEXT="If steps are predictable, it's a workflow."></node><node ID="ID_1446" TEXT="Subagents get their own context window (isolation, but extra cost and only a summary returns)."></node><node ID="ID_1447" TEXT="Human approval belongs before destructive actions."></node><node ID="ID_1448" TEXT="Parallelisation is code-driven; orchestrator–workers is model-driven."></node><node ID="ID_1449" TEXT="Evaluator–optimizer needs a cap."></node></node></node><node ID="ID_1453" TEXT="Agent SDK minimal (Python)"><node ID="ID_1452" TEXT="{ } code sample"><richcontent TYPE="NOTE"><html><head></head><body><p>import asyncio</p><p>from claude_agent_sdk import query, ClaudeAgentOptions</p><p>async def main():</p><p>    opts = ClaudeAgentOptions(</p><p>        allowed_tools=[&quot;Read&quot;,&quot;Grep&quot;,&quot;Glob&quot;],   # read-only</p><p>        max_turns=10,</p><p>        system_prompt=&quot;You are a code reviewer. Report, don't edit.&quot;)</p><p>    async for msg in query(prompt=&quot;Find error handling gaps in src/&quot;, options=opts):</p><p>        print(msg)</p><p>asyncio.run(main())</p></body></html></richcontent></node></node></node><node ID="ID_1584" TEXT="📚 Library digests"><node ID="ID_1468" TEXT="Building effective agents (Anthropic engineering)" LINK="https://www.anthropic.com/engineering/building-effective-agents"><richcontent TYPE="NOTE"><html><head></head><body><p>https://www.anthropic.com/engineering/building-effective-agents</p></body></html></richcontent><node ID="ID_1463" TEXT="Key facts"><node ID="ID_1455" TEXT="Workflows = LLMs and tools orchestrated through predefined code paths. Agents = LLMs dynamically…"><richcontent TYPE="NOTE"><html><head></head><body><p>Workflows = LLMs and tools orchestrated through predefined code paths. Agents = LLMs dynamically direct their own process and tool use.</p></body></html></richcontent></node><node ID="ID_1456" TEXT="Building block: the augmented LLM (LLM + retrieval + tools + memory); MCP is one way to wire in…"><richcontent TYPE="NOTE"><html><head></head><body><p>Building block: the augmented LLM (LLM + retrieval + tools + memory); MCP is one way to wire in tools.</p></body></html></richcontent></node><node ID="ID_1457" TEXT="Five workflow patterns: prompt chaining (sequential steps with programmatic gates; trades…"><richcontent TYPE="NOTE"><html><head></head><body><p>Five workflow patterns: prompt chaining (sequential steps with programmatic gates; trades latency for accuracy); routing (classify → specialised prompt/model); parallelisation — sectioning (independent subtasks) and voting (same task several times); orchestrator–workers (central LLM dynamically decomposes and delegates; for unpredictable subtasks); evaluator–optimizer (generator + feedback loop; needs clear evaluation criteria).</p></body></html></richcontent></node><node ID="ID_1458" TEXT="Autonomous agent: LLM in a loop using tools on environmental feedback ('ground truth' each…"><richcontent TYPE="NOTE"><html><head></head><body><p>Autonomous agent: LLM in a loop using tools on environmental feedback ('ground truth' each step), pausing for human checkpoints; stops on completion or a stopping condition (e.g. max iterations).</p></body></html></richcontent></node><node ID="ID_1459" TEXT="Start with the simplest solution; add agentic complexity only when it demonstrably improves…"><richcontent TYPE="NOTE"><html><head></head><body><p>Start with the simplest solution; add agentic complexity only when it demonstrably improves outcomes — agents bring higher cost and compounding errors.</p></body></html></richcontent></node><node ID="ID_1460" TEXT="Three principles: simplicity, transparency (show planning), a well-crafted agent–computer…"><richcontent TYPE="NOTE"><html><head></head><body><p>Three principles: simplicity, transparency (show planning), a well-crafted agent–computer interface (thorough tool docs, tested).</p></body></html></richcontent></node><node ID="ID_1461" TEXT="Frameworks are fine to start but add abstraction that obscures prompts and responses."></node><node ID="ID_1462" TEXT="Tool-design appendix: formats close to natural text; avoid formatting overhead;…"><richcontent TYPE="NOTE"><html><head></head><body><p>Tool-design appendix: formats close to natural text; avoid formatting overhead; docstring-quality descriptions; poka-yoke arguments (e.g. require absolute paths).</p></body></html></richcontent></node></node><node ID="ID_1467" TEXT="⚠ Exam traps"><node ID="ID_1464" TEXT="Orchestrator–workers decides subtasks dynamically; parallelisation uses predefined splits."></node><node ID="ID_1465" TEXT="Voting belongs to parallelisation, not evaluator–optimizer."></node><node ID="ID_1466" TEXT="The recommendation is the simplest system that works, not the most autonomous."></node></node></node><node ID="ID_1481" TEXT="Claude Agent SDK overview" LINK="https://code.claude.com/docs/en/agent-sdk/overview"><richcontent TYPE="NOTE"><html><head></head><body><p>https://code.claude.com/docs/en/agent-sdk/overview</p></body></html></richcontent><node ID="ID_1475" TEXT="Key facts"><node ID="ID_1469" TEXT="Agent SDK = Claude Code as a library: same tools, agent loop and context management, in Python…"><richcontent TYPE="NOTE"><html><head></head><body><p>Agent SDK = Claude Code as a library: same tools, agent loop and context management, in Python and TypeScript only. Other languages: run the CLI with -p and --output-format json.</p></body></html></richcontent></node><node ID="ID_1470" TEXT="Positioning: Agent SDK (runs the loop in your process) vs Claude Code CLI (interactive) vs…"><richcontent TYPE="NOTE"><html><head></head><body><p>Positioning: Agent SDK (runs the loop in your process) vs Claude Code CLI (interactive) vs Client SDK (raw API — you write the tool loop) vs Managed Agents (hosted; Anthropic runs the sandbox).</p></body></html></richcontent></node><node ID="ID_1471" TEXT="Capabilities: built-in tools (read/write/edit files, run commands, web search), hooks,…"><richcontent TYPE="NOTE"><html><head></head><body><p>Capabilities: built-in tools (read/write/edit files, run commands, web search), hooks, subagents, MCP, permissions, sessions (resume/fork), skills/commands/memory from .claude/ and ~/.claude/, plugins.</p></body></html></richcontent></node><node ID="ID_1472" TEXT="Install: pip install claude-agent-sdk / npm install @anthropic-ai/claude-agent-sdk; Python 3.10+…"><richcontent TYPE="NOTE"><html><head></head><body><p>Install: pip install claude-agent-sdk / npm install @anthropic-ai/claude-agent-sdk; Python 3.10+ / Node 18+; bundles the Claude Code binary.</p></body></html></richcontent></node><node ID="ID_1473" TEXT="Auth: ANTHROPIC_API_KEY in the process environment (the SDK does not load .env);…"><richcontent TYPE="NOTE"><html><head></head><body><p>Auth: ANTHROPIC_API_KEY in the process environment (the SDK does not load .env); CLAUDE_CODE_USE_BEDROCK / VERTEX / FOUNDRY for cloud platforms.</p></body></html></richcontent></node><node ID="ID_1474" TEXT="Branding: 'Powered by Claude' allowed; 'Claude Code' branding not permitted for third-party…"><richcontent TYPE="NOTE"><html><head></head><body><p>Branding: 'Powered by Claude' allowed; 'Claude Code' branding not permitted for third-party products.</p></body></html></richcontent></node></node><node ID="ID_1479" TEXT="⚠ Exam traps"><node ID="ID_1476" TEXT="Agent SDK ≠ Client SDK: with the client SDK you implement the tool loop yourself."></node><node ID="ID_1477" TEXT="Python and TypeScript only."></node><node ID="ID_1478" TEXT="ANTHROPIC_API_KEY must be in the environment; .env files are not auto-loaded."></node></node><node ID="ID_1480" TEXT="{ } code"><richcontent TYPE="NOTE"><html><head></head><body><p>from claude_agent_sdk import query, ClaudeAgentOptions</p><p>async for message in query(</p><p>    prompt=&quot;Review utils.py for bugs and report them.&quot;,</p><p>    options=ClaudeAgentOptions(allowed_tools=[&quot;Read&quot;,&quot;Grep&quot;,&quot;Glob&quot;], max_turns=10)):</p><p>    if hasattr(message, &quot;result&quot;): print(message.result)</p></body></html></richcontent></node></node><node ID="ID_1495" TEXT="Agent SDK — Python reference" LINK="https://code.claude.com/docs/en/agent-sdk/python"><richcontent TYPE="NOTE"><html><head></head><body><p>https://code.claude.com/docs/en/agent-sdk/python</p></body></html></richcontent><node ID="ID_1489" TEXT="Key facts"><node ID="ID_1482" TEXT="query() = new session per call, single exchange, no interrupts. ClaudeSDKClient = persistent…"><richcontent TYPE="NOTE"><html><head></head><body><p>query() = new session per call, single exchange, no interrupts. ClaudeSDKClient = persistent multi-turn session with interrupt(); use async with.</p></body></html></richcontent></node><node ID="ID_1483" TEXT="ClaudeAgentOptions: allowed_tools=[], disallowed_tools, permission_mode (default | acceptEdits |…"><richcontent TYPE="NOTE"><html><head></head><body><p>ClaudeAgentOptions: allowed_tools=[], disallowed_tools, permission_mode (default | acceptEdits | plan | dontAsk | bypassPermissions | auto), system_prompt, mcp_servers={}, max_turns, max_budget_usd, cwd, setting_sources (None = user+project+local; [] = none), continue_conversation, resume, fork_session, model, output_format (json_schema), hooks.</p></body></html></richcontent></node><node ID="ID_1484" TEXT="allowed_tools AUTO-APPROVES the listed tools — it does not restrict Claude to them; use…"><richcontent TYPE="NOTE"><html><head></head><body><p>allowed_tools AUTO-APPROVES the listed tools — it does not restrict Claude to them; use disallowed_tools to remove tools.</p></body></html></richcontent></node><node ID="ID_1485" TEXT="can_use_tool callback fires only when permission evaluation falls through to a prompt; to…"><richcontent TYPE="NOTE"><html><head></head><body><p>can_use_tool callback fires only when permission evaluation falls through to a prompt; to intercept every call use a PreToolUse hook.</p></body></html></richcontent></node><node ID="ID_1486" TEXT="Precedence: managed policy &gt; programmatic options &gt; local &gt; project &gt; user settings."></node><node ID="ID_1487" TEXT="Custom in-process tools: @tool(name, description, input_schema) + create_sdk_mcp_server(name,…"><richcontent TYPE="NOTE"><html><head></head><body><p>Custom in-process tools: @tool(name, description, input_schema) + create_sdk_mcp_server(name, tools=[…]) passed via mcp_servers.</p></body></html></richcontent></node><node ID="ID_1488" TEXT="Message types: AssistantMessage, UserMessage, ResultMessage (subtype, session_id,…"><richcontent TYPE="NOTE"><html><head></head><body><p>Message types: AssistantMessage, UserMessage, ResultMessage (subtype, session_id, total_cost_usd), SystemMessage, StreamEvent; blocks TextBlock/ThinkingBlock/ToolUseBlock/ToolResultBlock.</p></body></html></richcontent></node></node><node ID="ID_1493" TEXT="⚠ Exam traps"><node ID="ID_1490" TEXT="allowed_tools=['Bash'] does not block other tools — it only pre-approves Bash."></node><node ID="ID_1491" TEXT="can_use_tool is skipped for auto-approved tools; PreToolUse hooks are not."></node><node ID="ID_1492" TEXT="query() cannot be interrupted; only ClaudeSDKClient supports interrupt()."></node></node><node ID="ID_1494" TEXT="{ } code"><richcontent TYPE="NOTE"><html><head></head><body><p>from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions, ResultMessage</p><p>opts = ClaudeAgentOptions(permission_mode=&quot;acceptEdits&quot;, max_turns=5, max_budget_usd=1.0)</p><p>async with ClaudeSDKClient(options=opts) as client:</p><p>    await client.query(&quot;Add input validation to api/handlers.py&quot;)</p><p>    async for m in client.receive_response():</p><p>        if isinstance(m, ResultMessage): print(m.subtype, m.total_cost_usd)</p></body></html></richcontent></node></node><node ID="ID_1509" TEXT="Agent SDK — subagents" LINK="https://code.claude.com/docs/en/agent-sdk/subagents"><richcontent TYPE="NOTE"><html><head></head><body><p>https://code.claude.com/docs/en/agent-sdk/subagents</p></body></html></richcontent><node ID="ID_1503" TEXT="Key facts"><node ID="ID_1496" TEXT="Define via the agents={…} option (recommended), .claude/agents/*.md files, or the built-in…"><richcontent TYPE="NOTE"><html><head></head><body><p>Define via the agents={…} option (recommended), .claude/agents/*.md files, or the built-in general-purpose agent. Programmatic definitions override same-named files.</p></body></html></richcontent></node><node ID="ID_1497" TEXT="AgentDefinition: description and prompt required; optional tools (omit = inherit),…"><richcontent TYPE="NOTE"><html><head></head><body><p>AgentDefinition: description and prompt required; optional tools (omit = inherit), disallowedTools, model (opus | sonnet | haiku | fable | inherit | full ID), skills, memory, mcpServers, maxTurns, background, effort, permissionMode.</p></body></html></richcontent></node><node ID="ID_1498" TEXT="Invoked through the Agent tool; include 'Agent' in allowed_tools to auto-approve delegation."></node><node ID="ID_1499" TEXT="Context isolation: a subagent starts fresh — its own prompt, project CLAUDE.md and tool…"><richcontent TYPE="NOTE"><html><head></head><body><p>Context isolation: a subagent starts fresh — its own prompt, project CLAUDE.md and tool definitions; NOT the parent's history or system prompt. Only the final message returns to the parent (marked with parent_tool_use_id).</p></body></html></richcontent></node><node ID="ID_1500" TEXT="Subagents run in the background by default and can nest: default max depth 3…"><richcontent TYPE="NOTE"><html><head></head><body><p>Subagents run in the background by default and can nest: default max depth 3 (CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH), max concurrent 20.</p></body></html></richcontent></node><node ID="ID_1501" TEXT="Completed subagents can be resumed by agentId with the same definitions; built-in Explore/Plan…"><richcontent TYPE="NOTE"><html><head></head><body><p>Completed subagents can be resumed by agentId with the same definitions; built-in Explore/Plan are one-shot.</p></body></html></richcontent></node><node ID="ID_1502" TEXT="Subagent output is scanned to neutralise system-reminder-style tags and fake turn markers."></node></node><node ID="ID_1507" TEXT="⚠ Exam traps"><node ID="ID_1504" TEXT="Subagents do NOT inherit the parent's conversation or system prompt."></node><node ID="ID_1505" TEXT="Programmatic definition beats a same-named .claude/agents file."></node><node ID="ID_1506" TEXT="Default spawn depth 3, concurrency 20."></node></node><node ID="ID_1508" TEXT="{ } code"><richcontent TYPE="NOTE"><html><head></head><body><p>from claude_agent_sdk import AgentDefinition</p><p>opts = ClaudeAgentOptions(</p><p>    allowed_tools=[&quot;Read&quot;,&quot;Grep&quot;,&quot;Glob&quot;,&quot;Agent&quot;],</p><p>    agents={&quot;reviewer&quot;: AgentDefinition(</p><p>        description=&quot;Strict code reviewer. Use after any change under src/.&quot;,</p><p>        prompt=&quot;Review for error handling and security. Report file:line. Never edit.&quot;,</p><p>        tools=[&quot;Read&quot;,&quot;Grep&quot;,&quot;Glob&quot;], model=&quot;sonnet&quot;)})</p></body></html></richcontent></node></node><node ID="ID_1521" TEXT="Agent SDK — sessions (continue, resume, fork)" LINK="https://code.claude.com/docs/en/agent-sdk/sessions"><richcontent TYPE="NOTE"><html><head></head><body><p>https://code.claude.com/docs/en/agent-sdk/sessions</p></body></html></richcontent><node ID="ID_1515" TEXT="Key facts"><node ID="ID_1510" TEXT="A session = conversation history persisted to disk automatically; it persists the conversation,…"><richcontent TYPE="NOTE"><html><head></head><body><p>A session = conversation history persisted to disk automatically; it persists the conversation, not the filesystem (use file checkpointing for that).</p></body></html></richcontent></node><node ID="ID_1511" TEXT="continue_conversation=True → most recent session in the cwd, no ID. resume=&lt;id&gt; → a specific…"><richcontent TYPE="NOTE"><html><head></head><body><p>continue_conversation=True → most recent session in the cwd, no ID. resume=&lt;id&gt; → a specific session. resume + fork_session=True → new session ID with a copy of history; the original is unchanged.</p></body></html></richcontent></node><node ID="ID_1512" TEXT="Session ID comes on ResultMessage.session_id (present even on error results)."></node><node ID="ID_1513" TEXT="Storage: ~/.claude/projects/&lt;encoded-cwd&gt;/&lt;session-id&gt;.jsonl; CLAUDE_CONFIG_DIR overrides.…"><richcontent TYPE="NOTE"><html><head></head><body><p>Storage: ~/.claude/projects/&lt;encoded-cwd&gt;/&lt;session-id&gt;.jsonl; CLAUDE_CONFIG_DIR overrides. Cross-host resume needs a session store adapter or moving the file.</p></body></html></richcontent></node><node ID="ID_1514" TEXT="Resume after error_max_turns / error_max_budget_usd with higher limits. Helpers:…"><richcontent TYPE="NOTE"><html><head></head><body><p>Resume after error_max_turns / error_max_budget_usd with higher limits. Helpers: list_sessions(), get_session_messages(), rename_session(), tag_session().</p></body></html></richcontent></node></node><node ID="ID_1519" TEXT="⚠ Exam traps"><node ID="ID_1516" TEXT="Forking branches history, not files — a fork's edits are real on disk."></node><node ID="ID_1517" TEXT="continue needs no ID but only finds the most recent session in that cwd."></node><node ID="ID_1518" TEXT="Session IDs are on ResultMessage even when the run errored."></node></node><node ID="ID_1520" TEXT="{ } code"><richcontent TYPE="NOTE"><html><head></head><body><p>async for m in query(prompt=&quot;Now outline OAuth2 instead&quot;,</p><p>        options=ClaudeAgentOptions(resume=session_id, fork_session=True)):</p><p>    if isinstance(m, ResultMessage): forked_id = m.session_id</p></body></html></richcontent></node></node><node ID="ID_1533" TEXT="Writing effective tools for agents (engineering blog)" LINK="https://www.anthropic.com/engineering/writing-tools-for-agents"><richcontent TYPE="NOTE"><html><head></head><body><p>https://www.anthropic.com/engineering/writing-tools-for-agents</p></body></html></richcontent><node ID="ID_1528" TEXT="Key facts"><node ID="ID_1522" TEXT="Tools are a contract between deterministic systems and non-deterministic agents."></node><node ID="ID_1523" TEXT="Workflow: prototype → wrap in a local MCP server → realistic multi-step evals → agentic loop…"><richcontent TYPE="NOTE"><html><head></head><body><p>Workflow: prototype → wrap in a local MCP server → realistic multi-step evals → agentic loop evals → read transcripts → let Claude analyse transcripts and rewrite tool descriptions.</p></body></html></richcontent></node><node ID="ID_1524" TEXT="More tools don't mean better outcomes: consolidate multi-step flows (schedule_event instead of…"><richcontent TYPE="NOTE"><html><head></head><body><p>More tools don't mean better outcomes: consolidate multi-step flows (schedule_event instead of list_users + list_events + create_event); prefer search over list.</p></body></html></richcontent></node><node ID="ID_1525" TEXT="Namespace names by service/resource (asana_projects_search). Return semantic context (names over…"><richcontent TYPE="NOTE"><html><head></head><body><p>Namespace names by service/resource (asana_projects_search). Return semantic context (names over UUIDs); offer a response_format enum (detailed / concise) — concise cut ~⅔ of tokens in the example.</p></body></html></richcontent></node><node ID="ID_1526" TEXT="Token efficiency: pagination, filtering, truncation with sensible defaults; actionable error…"><richcontent TYPE="NOTE"><html><head></head><body><p>Token efficiency: pagination, filtering, truncation with sensible defaults; actionable error messages instead of opaque codes.</p></body></html></richcontent></node><node ID="ID_1527" TEXT="Descriptions are prompt engineering: state query formats, terminology, relationships;…"><richcontent TYPE="NOTE"><html><head></head><body><p>Descriptions are prompt engineering: state query formats, terminology, relationships; unambiguous parameter names (user_id, not user).</p></body></html></richcontent></node></node><node ID="ID_1532" TEXT="⚠ Exam traps"><node ID="ID_1529" TEXT="Wrapping every API endpoint as a tool is discouraged — target high-impact workflows."></node><node ID="ID_1530" TEXT="Prefer semantic identifiers (names) in responses over technical IDs."></node><node ID="ID_1531" TEXT="user_id beats user — parameter naming changes accuracy."></node></node></node><node ID="ID_1546" TEXT="Web search tool (server tool)" LINK="https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool"><richcontent TYPE="NOTE"><html><head></head><body><p>https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool</p></body></html></richcontent><node ID="ID_1540" TEXT="Key facts"><node ID="ID_1534" TEXT="Tool name web_search; type web_search_20250305 (newer types add dynamic filtering and…"><richcontent TYPE="NOTE"><html><head></head><body><p>Tool name web_search; type web_search_20250305 (newer types add dynamic filtering and response_inclusion). Must be enabled by an org admin in the Console, else 400.</p></body></html></richcontent></node><node ID="ID_1535" TEXT="Params: max_uses; allowed_domains / blocked_domains — mutually exclusive (400 if both);…"><richcontent TYPE="NOTE"><html><head></head><body><p>Params: max_uses; allowed_domains / blocked_domains — mutually exclusive (400 if both); user_location {type:'approximate', city, region, country, timezone}.</p></body></html></richcontent></node><node ID="ID_1536" TEXT="Response: server_tool_use (srvtoolu_…) → web_search_tool_result with web_search_result items…"><richcontent TYPE="NOTE"><html><head></head><body><p>Response: server_tool_use (srvtoolu_…) → web_search_tool_result with web_search_result items (url, title, encrypted_content, page_age); citations via web_search_result_location. encrypted_content must be passed back unchanged in multi-turn.</p></body></html></richcontent></node><node ID="ID_1537" TEXT="Errors: too_many_requests, invalid_tool_input, max_uses_exceeded, query_too_long,…"><richcontent TYPE="NOTE"><html><head></head><body><p>Errors: too_many_requests, invalid_tool_input, max_uses_exceeded, query_too_long, request_too_large, unavailable.</p></body></html></richcontent></node><node ID="ID_1538" TEXT="Pricing $10 per 1,000 searches plus tokens; failed searches aren't billed;…"><richcontent TYPE="NOTE"><html><head></head><body><p>Pricing $10 per 1,000 searches plus tokens; failed searches aren't billed; usage.server_tool_use.web_search_requests. May return stop_reason pause_turn on long searches — send the response back to continue.</p></body></html></richcontent></node><node ID="ID_1539" TEXT="Supports streaming, caching, Batches; Claude 4.6+ on the Claude API, Vertex and Foundry (not…"><richcontent TYPE="NOTE"><html><head></head><body><p>Supports streaming, caching, Batches; Claude 4.6+ on the Claude API, Vertex and Foundry (not Bedrock). Web fetch is a companion server tool (web_fetch) that retrieves a URL's content.</p></body></html></richcontent></node></node><node ID="ID_1544" TEXT="⚠ Exam traps"><node ID="ID_1541" TEXT="allowed_domains and blocked_domains cannot be combined."></node><node ID="ID_1542" TEXT="pause_turn means 'send it back to continue', not an error."></node><node ID="ID_1543" TEXT="Each search counts as one use regardless of result count."></node></node><node ID="ID_1545" TEXT="{ } code"><richcontent TYPE="NOTE"><html><head></head><body><p>r = client.messages.create(model=&quot;claude-sonnet-5&quot;, max_tokens=2048,</p><p>    tools=[{&quot;type&quot;:&quot;web_search_20250305&quot;,&quot;name&quot;:&quot;web_search&quot;,&quot;max_uses&quot;:3,</p><p>            &quot;blocked_domains&quot;:[&quot;untrusted.example&quot;]}],</p><p>    messages=[{&quot;role&quot;:&quot;user&quot;,&quot;content&quot;:&quot;Latest Kubernetes CVE this month? Cite sources.&quot;}])</p></body></html></richcontent></node></node><node ID="ID_1558" TEXT="Code execution tool (server tool)" LINK="https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool"><richcontent TYPE="NOTE"><html><head></head><body><p>https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool</p></body></html></richcontent><node ID="ID_1552" TEXT="Key facts"><node ID="ID_1547" TEXT="name code_execution; types code_execution_20250825 / 20260120 (REPL state, programmatic tool…"><richcontent TYPE="NOTE"><html><head></head><body><p>name code_execution; types code_execution_20250825 / 20260120 (REPL state, programmatic tool calling). No beta header needed now.</p></body></html></richcontent></node><node ID="ID_1548" TEXT="Sandbox: Python 3.11, Linux, 1 CPU, 5 GiB RAM, 5 GiB disk, NO internet; 90 s per REPL cell.…"><richcontent TYPE="NOTE"><html><head></head><body><p>Sandbox: Python 3.11, Linux, 1 CPU, 5 GiB RAM, 5 GiB disk, NO internet; 90 s per REPL cell. Pre-installed: pandas, numpy, scipy, scikit-learn, matplotlib, openpyxl, python-docx, python-pptx, pypdf, reportlab…</p></body></html></richcontent></node><node ID="ID_1549" TEXT="Container: response.container.id; reuse via top-level container=; expires 30 days after creation."></node><node ID="ID_1550" TEXT="Files in via the Files API (container_upload); outputs written to $OUTPUT_DIR come back as…"><richcontent TYPE="NOTE"><html><head></head><body><p>Files in via the Files API (container_upload); outputs written to $OUTPUT_DIR come back as file_ids (downloadable).</p></body></html></richcontent></node><node ID="ID_1551" TEXT="Pricing: free with web search/fetch; otherwise 1,550 free container-hours per org per month,…"><richcontent TYPE="NOTE"><html><head></head><body><p>Pricing: free with web search/fetch; otherwise 1,550 free container-hours per org per month, then $0.05/hour (5-minute minimum). Haiku 4.5: no REPL persistence.</p></body></html></richcontent></node></node><node ID="ID_1556" TEXT="⚠ Exam traps"><node ID="ID_1553" TEXT="No internet in the sandbox — pip install at runtime fails."></node><node ID="ID_1554" TEXT="Only files at the top level of $OUTPUT_DIR are returned."></node><node ID="ID_1555" TEXT="Container hard expiry is 30 days."></node></node><node ID="ID_1557" TEXT="{ } code"><richcontent TYPE="NOTE"><html><head></head><body><p>r = client.messages.create(model=&quot;claude-sonnet-5&quot;, max_tokens=4096,</p><p>    tools=[{&quot;type&quot;:&quot;code_execution_20250825&quot;,&quot;name&quot;:&quot;code_execution&quot;}],</p><p>    messages=[{&quot;role&quot;:&quot;user&quot;,&quot;content&quot;:&quot;Compute mean and p95 of these latencies: 120, 340, 90, 1500, 210&quot;}])</p><p>r2 = client.messages.create(container=r.container.id, ...)   # reuse state</p></body></html></richcontent></node></node><node ID="ID_1571" TEXT="Agent Skills overview" LINK="https://platform.claude.com/docs/en/agents-and-tools/agent-skills/overview"><richcontent TYPE="NOTE"><html><head></head><body><p>https://platform.claude.com/docs/en/agents-and-tools/agent-skills/overview</p></body></html></richcontent><node ID="ID_1565" TEXT="Key facts"><node ID="ID_1559" TEXT="A Skill = a folder with SKILL.md (YAML frontmatter + instructions) plus optional scripts/resources."></node><node ID="ID_1560" TEXT="Frontmatter: name (≤64 chars, lowercase/digits/hyphens, no 'anthropic'/'claude') and description…"><richcontent TYPE="NOTE"><html><head></head><body><p>Frontmatter: name (≤64 chars, lowercase/digits/hyphens, no 'anthropic'/'claude') and description (≤1,024 chars; must say what it does AND when to use it) — both required.</p></body></html></richcontent></node><node ID="ID_1561" TEXT="Progressive disclosure: L1 metadata always loaded (~100 tokens per skill); L2 SKILL.md body on…"><richcontent TYPE="NOTE"><html><head></head><body><p>Progressive disclosure: L1 metadata always loaded (~100 tokens per skill); L2 SKILL.md body on trigger (&lt;5k tokens recommended); L3 bundled files only when accessed.</p></body></html></richcontent></node><node ID="ID_1562" TEXT="Surfaces: Claude API (pre-built pptx/xlsx/docx/pdf + custom via /v1/skills; REQUIRES the code…"><richcontent TYPE="NOTE"><html><head></head><body><p>Surfaces: Claude API (pre-built pptx/xlsx/docx/pdf + custom via /v1/skills; REQUIRES the code execution tool), Claude Code (custom only, ~/.claude/skills/ or .claude/skills/), claude.ai (per-user).</p></body></html></richcontent></node><node ID="ID_1563" TEXT="API: container={skills:[{type:'anthropic', skill_id:'pptx', version:'latest'}]}; max 20 skills…"><richcontent TYPE="NOTE"><html><head></head><body><p>API: container={skills:[{type:'anthropic', skill_id:'pptx', version:'latest'}]}; max 20 skills per request; upload ≤30 MB; Skills API endpoints under /v1/skills.</p></body></html></richcontent></node><node ID="ID_1564" TEXT="Sandbox has no network and no runtime package install. Treat third-party skills like installing…"><richcontent TYPE="NOTE"><html><head></head><body><p>Sandbox has no network and no runtime package install. Treat third-party skills like installing software.</p></body></html></richcontent></node></node><node ID="ID_1569" TEXT="⚠ Exam traps"><node ID="ID_1566" TEXT="Skills in the API need the code execution tool in tools, or they won't run."></node><node ID="ID_1567" TEXT="The description must say WHEN to use the skill — that is the trigger."></node><node ID="ID_1568" TEXT="Pre-built document skills are not in Claude Code; only custom skills are."></node></node><node ID="ID_1570" TEXT="{ } code"><richcontent TYPE="NOTE"><html><head></head><body><p>r = client.messages.create(model=&quot;claude-sonnet-5&quot;, max_tokens=4096,</p><p>    container={&quot;skills&quot;:[{&quot;type&quot;:&quot;anthropic&quot;,&quot;skill_id&quot;:&quot;xlsx&quot;,&quot;version&quot;:&quot;latest&quot;}]},</p><p>    tools=[{&quot;type&quot;:&quot;code_execution_20250825&quot;,&quot;name&quot;:&quot;code_execution&quot;}],</p><p>    messages=[{&quot;role&quot;:&quot;user&quot;,&quot;content&quot;:&quot;Build a workbook of last quarter's incident counts by service.&quot;}])</p></body></html></richcontent></node></node><node ID="ID_1583" TEXT="Agent frameworks and memory management (LangGraph and friends) — blueprint 4.9%" LINK="https://docs.claude.com/en/api/agent-sdk/overview"><richcontent TYPE="NOTE"><html><head></head><body><p>https://docs.claude.com/en/api/agent-sdk/overview</p></body></html></richcontent><node ID="ID_1578" TEXT="Key facts"><node ID="ID_1572" TEXT="Framework landscape: Claude Agent SDK (Anthropic; Claude Code's loop as a library), LangGraph…"><richcontent TYPE="NOTE"><html><head></head><body><p>Framework landscape: Claude Agent SDK (Anthropic; Claude Code's loop as a library), LangGraph (graph of nodes/edges with explicit state, checkpoints, human-in-the-loop interrupts), LangChain agents, CrewAI (role-based crews), AutoGen (conversational multi-agent), plus DIY loops on the Messages API.</p></body></html></richcontent></node><node ID="ID_1573" TEXT="Anthropic's guidance: frameworks are fine to start but add abstraction that hides prompts and…"><richcontent TYPE="NOTE"><html><head></head><body><p>Anthropic's guidance: frameworks are fine to start but add abstraction that hides prompts and responses; understand the underlying calls; prefer the simplest thing that works.</p></body></html></richcontent></node><node ID="ID_1574" TEXT="LangGraph concepts worth recognising: state (typed dict), nodes (functions/LLM calls), edges…"><richcontent TYPE="NOTE"><html><head></head><body><p>LangGraph concepts worth recognising: state (typed dict), nodes (functions/LLM calls), edges (conditional routing), checkpointer (persist state between steps → resumability and time travel), interrupt() for human approval — maps to the workflow patterns (routing = conditional edge; orchestrator = node that fans out).</p></body></html></richcontent></node><node ID="ID_1575" TEXT="Memory management: short-term = the context window (manage with summarisation, context…"><richcontent TYPE="NOTE"><html><head></head><body><p>Memory management: short-term = the context window (manage with summarisation, context editing/compaction); working memory = scratchpad files or state objects; long-term = retrieval store (vector/keyword DB), a memory tool, or Claude Code's auto memory; episodic = session logs. Write durable facts to persistent storage before compaction.</p></body></html></richcontent></node><node ID="ID_1576" TEXT="Deployment models: in-process library (Agent SDK), headless CLI in CI (claude -p), hosted…"><richcontent TYPE="NOTE"><html><head></head><body><p>Deployment models: in-process library (Agent SDK), headless CLI in CI (claude -p), hosted Managed Agents (Anthropic-run sandbox, session-hour pricing), your own container with the SDK; choose by control vs operations burden.</p></body></html></richcontent></node><node ID="ID_1577" TEXT="Manager hierarchies: orchestrator delegates to workers (subagents) with narrow briefs and…"><richcontent TYPE="NOTE"><html><head></head><body><p>Manager hierarchies: orchestrator delegates to workers (subagents) with narrow briefs and restricted tools; results summarised back; depth and concurrency limits prevent runaway trees.</p></body></html></richcontent></node></node><node ID="ID_1582" TEXT="⚠ Exam traps"><node ID="ID_1579" TEXT="A framework doesn't change the fundamentals: stateless API, tool loop, context budget."></node><node ID="ID_1580" TEXT="Checkpointing/persistence is what makes long-running agents resumable — in the Agent SDK that is sessions; in LangGraph a checkpointer."></node><node ID="ID_1581" TEXT="Long-term memory lives outside the context window (files, DB, memory tool)."></node></node></node></node><node ID="ID_1605" TEXT="❓ Self-check"><node ID="ID_1586" TEXT="Nightly job: summarise each PR, label it, post to Slack. Agent or workflow?"><node ID="ID_1585" TEXT="→ Workflow (chaining + maybe routing). Steps are fixed and known."></node></node><node ID="ID_1588" TEXT="An agent keeps calling the same tool forever. First fix?"><node ID="ID_1587" TEXT="→ Max-turn / loop-detection guard; then improve tool result messages so the model sees the outcome."></node></node><node ID="ID_1590" TEXT="Support tickets in three categories need different handling. Pattern?"><node ID="ID_1589" TEXT="→ Routing — cheap classifier, then specialised prompt (and model) per class."></node></node><node ID="ID_1592" TEXT="You need a quality score you can trust for an essay grader. Pattern?"><node ID="ID_1591" TEXT="→ Parallelisation (voting) — several independent graders, aggregate."></node></node><node ID="ID_1594" TEXT="Refactor touching an unknown number of files. Pattern?"><node ID="ID_1593" TEXT="→ Orchestrator–workers — the lead decides sub-tasks dynamically."></node></node><node ID="ID_1596" TEXT="Translation must be polished until a critic is satisfied. Pattern and guard?"><node ID="ID_1595" TEXT="→ Evaluator–optimizer with an iteration cap."></node></node><node ID="ID_1598" TEXT="What does a subagent share with its parent?"><node ID="ID_1597" TEXT="→ Nothing but the brief and the returned summary — it has its own context window."></node></node><node ID="ID_1600" TEXT="Where should human approval sit for a 'delete namespace' tool?"><node ID="ID_1599" TEXT="→ Before execution — a permission callback or hook, not a post-hoc review."></node></node><node ID="ID_1602" TEXT="Tool vs Skill?"><node ID="ID_1601" TEXT="→ A tool performs an action via a schema; a Skill is packaged instructions/resources Claude loads to know how to do something."></node></node><node ID="ID_1604" TEXT="What does the Agent SDK give you over the Messages API?"><node ID="ID_1603" TEXT="→ The tool loop, built-in file/bash tools, permissions, context compaction, MCP, subagents, hooks, sessions."></node></node></node><node ID="ID_1618" TEXT="⚠ Traps to drill"><node ID="ID_1607" TEXT="Predictable multi-step task — agent or workflow?"><node ID="ID_1606" TEXT="→ Workflow. Agents only when the path is unknown in advance."></node></node><node ID="ID_1609" TEXT="Five workflow patterns?"><node ID="ID_1608" TEXT="→ Chaining, routing, parallelisation (sectioning/voting), orchestrator–workers, evaluator–optimizer."></node></node><node ID="ID_1611" TEXT="Subagent context?"><node ID="ID_1610" TEXT="→ Its own window — isolation and focus, but extra tokens and only a summary returns."></node></node><node ID="ID_1613" TEXT="Human-in-the-loop placement?"><node ID="ID_1612" TEXT="→ Before destructive/irreversible actions."></node></node><node ID="ID_1615" TEXT="Who decides sub-tasks in orchestrator–workers vs parallelisation?"><node ID="ID_1614" TEXT="→ Orchestrator: the model. Parallelisation: your code."></node></node><node ID="ID_1617" TEXT="Agent loops forever — first guard?"><node ID="ID_1616" TEXT="→ Max turns / loop detection; then better tool results."></node></node></node><node ID="ID_1625" TEXT="🗒 Cheat sheet"><node ID="ID_1619" TEXT="Workflow = code-defined path (predictable, testable, cheap). Agent = model-chosen path in a loop (open-ended only). Simplest thing first."></node><node ID="ID_1620" TEXT="Patterns: chaining (gates between steps) · routing (classify→specialist) · parallel (sectioning / voting) · orchestrator–workers (model plans) · evaluator–optimizer (cap it)"></node><node ID="ID_1621" TEXT="Agent guards: clear stop condition, max_turns, cost budget, loop detection, strict tool schemas + is_error, approval before side effects, compaction"></node><node ID="ID_1622" TEXT="Agent SDK = Claude Code's loop as a library: built-in tools, permissions, compaction, MCP, subagents, hooks, sessions; allowed_tools / permission_mode / max_turns"></node><node ID="ID_1623" TEXT="Subagent = own context window, own prompt/tools, returns summary; costs more; good for isolation and parallelism"></node><node ID="ID_1624" TEXT="Server tools (web search/fetch, code exec) run on Anthropic's side; Skills = SKILL.md folders of know-how, loaded progressively; MCP = standard plug for external tools"></node></node><node ID="ID_1632" TEXT="☑ Chapter checklist"><node ID="ID_1626" TEXT="Can name and sketch the five workflow patterns"></node><node ID="ID_1627" TEXT="Can explain why a workflow beats an agent for a predictable task"></node><node ID="ID_1628" TEXT="Agent SDK quickstart ran end to end"></node><node ID="ID_1629" TEXT="Orchestrator–worker demo works on your project"></node><node ID="ID_1630" TEXT="Guards: max turns, cost cap, tool allow-list, human approval for destructive actions in place"></node><node ID="ID_1631" TEXT="notes/agents.md written"></node></node></node>
</map>
