References: From single call to agent loop
Source material
Section titled “Source material”Source curriculum (structural mirror, cited as further study):• Anthropic Academy (https://anthropic.skilljar.com/): "Building with the Claude API" course (agent-loop sections) License: Anthropic Academy course content is account-gated; Clawdemy structurally mirrors the Academy's lesson progression as inspiration and cites it as further study. Every substantive claim in this lesson is verifiable against the public Anthropic engineering post + Anthropic public Claude documentation.
Primary public-source anchors (every substantive claim verifiedagainst):• Anthropic, "Building effective AI agents" (the canonical workflow-vs-agent framing; the augmented LLM building block; the standing call for the simplest solution first; the framework guidance) https://www.anthropic.com/engineering/building-effective-agents Authors: Erik Schluntz and Barry Zhang Published: 2024-12-19• Anthropic, "Tool use with Claude" overview (the canonical loop pattern: tool_use stop reason -> tool_use blocks -> execute -> tool_result -> repeat; tool_choice options; the per-model tool- use system-prompt token table) https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview• Anthropic, "How tool use works" (the conceptual model, deeper walk-through of the loop) https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works• Anthropic, "Handling stop reasons" (the full stop_reason vocabulary the loop dispatches on) https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons
Verbatim claims sourced from the public sources:• "[Workflows are] systems where LLMs and tools are orchestrated through predefined code paths" (Building effective agents)• "[Agents are] systems where LLMs dynamically direct their own processes and tool usage, maintaining control over how they accomplish tasks" (Building effective agents)• "Find the simplest solution possible, and only increasing complexity when needed" (Building effective agents)• "Workflows offer predictability and consistency for well-defined tasks, whereas agents are the better option when flexibility and model-driven decision-making are needed at scale" (Building effective agents)• "Start by using LLM APIs directly: many patterns can be implemented in a few lines of code" (Building effective agents)• "If frameworks are used, ensure you understand the underlying code" (Building effective agents)• "Claude responds with stop_reason: 'tool_use' and one or more tool_use blocks, your code executes the operation, and you send back a tool_result" (Tool use overview)• Per-model tool-use system-prompt token counts (Tool use overview pricing section)
Required attribution: "Based on the structure of the Anthropic Academy 'Building with the Claude API' course (https://anthropic.skilljar.com/) and Anthropic engineering, 'Building effective AI agents' (Erik S. and Barry Zhang, 2024-12-19, https://www.anthropic.com/engineering/building-effective-agents). This lesson is an independent structural mirror in original prose; every substantive claim is verified against the public Anthropic Claude documentation at https://platform.claude.com/docs/ and the named engineering post. Anthropic does not endorse it."Read this next
Section titled “Read this next”- Anthropic, “Building effective AI agents”. The canonical engineering post by Erik Schluntz and Barry Zhang (2024-12-19) that names the workflow-vs-agent distinction and catalogs the five workflow patterns plus the agent pattern. Read once before lesson 9; reread once a quarter as the field evolves.
- Anthropic, “Tool use with Claude” overview. The canonical reference for the loop primitives: tool_use + tool_result dispatch, the tool_choice modes, the auto-injected tool-use system-prompt token table per model.
- Anthropic, “How tool use works”. A deeper conceptual walk through where tools execute and how the loop turns over; useful when debugging an agent that is behaving unexpectedly.
- Anthropic, “Handling stop reasons”. The full per-value reference: every stop_reason the API can return and the recommended client-side handling for each.
Going deeper
Section titled “Going deeper”A short, durable list. Each link is a specific next step inside Track 22.
- Lesson 9 of this track, “Six effective-agent patterns.” Where the canonical patterns (prompt chaining, routing, parallelization, orchestrator-workers, evaluator-optimizer, plus the open-ended agent) are catalogued on the loop substrate this lesson introduces. The “six” is five workflow patterns plus the agent.
- Lesson 10 of this track, “Agent Skills and Claude Code.” Where Agent Skills become durable instructions the loop can reference, and Claude Code is the worked agent harness reading them.
- Lesson 11 of this track, “Subagents and Claude Managed Agents.” Where the loop in this lesson is the substrate, and a subagent is a focused inner loop spawned from inside an outer one. Claude Managed Agents are the Anthropic-hosted version.
- Lesson 12 of this track, “Shipping a Claude application.” Where the production disciplines (cost monitoring with usage, latency budgets, eval-set discipline) wrap the loop you wrote here.
Adjacent tracks (the natural next destinations)
Section titled “Adjacent tracks (the natural next destinations)”- Track 20 (AI Agents and Tool Use): pick this if you want the full track-level depth on agent design, including the broader principles around tool isolation, harness design, and the engineering discipline of running an agent in production over time.
- Track 21 (LLM Ops and Production): pick this if you want the provider-agnostic view of evaluation and observability for agent loops. The eval-set discipline that measures whether an agent is doing useful work lives there.
Where this connects inside the track
Section titled “Where this connects inside the track”The loop the rest of Phase 3 specializes:
- Lesson 1 (first call): the messages.create call inside the loop is the same call lesson 1 walked through; everything new is the while and the stop_reason dispatch around it.
- Lesson 2 (production patterns): the stop_reason dispatch table in this lesson is the same set of values lesson 2 introduced, now in a loop context where each value has a loop action.
- Lesson 3 (model selection): the per-model tool-use system-prompt token table (290 / 675 / 497 / 496 / etc.) stacks onto the per-token prices from L3.
- Lesson 4 (custom client tools): the tool_use / tool_result round-trip is the foundation; the loop is what runs it multiple times.
- Lesson 5 (server tools + Anthropic-schema + tool_search): the pause_turn stop reason from server tools is one of the values the loop dispatches on; computer-use tools deserve sandboxed environments by default inside the loop.
- Lesson 6 (MCP connector): MCP tools are just more tools in the loop; the denylist pattern from L6 becomes load-bearing for any agent loop that touches third-party catalogs.
- Lesson 7 (prompt caching + context management): all three cost-and-staleness levers stay engaged inside the loop. Cache the prefix per iteration; opt in to compaction at 150K with a cached system end; reach for tool result clearing in tool-heavy loops.
- Lesson 9 onward: every pattern lesson 9 catalogs sits on top of the loop in this lesson. Subagents (L11) are inner loops spawned from outer ones; Claude Code (L10) is a worked agent reading Skills as durable instructions.
- Lesson 12 (shipping): the usage object’s input_tokens / output_tokens / cache_creation / cache_read / iterations fields are what production cost monitoring tracks per loop iteration.