# Chapter 16: Agents

Part of the course “AI from Zero to Autonomous Agents” (https://llm.yoga/en). Page for humans: https://llm.yoga/en/16-agenten

*A model, a few tools and a loop: what comes out of that, when a fixed workflow is the better choice, and how to keep agents under control.*

About 30 min to read · about 30 min hands-on exercise

**Start with the missions**

This chapter also comes as 3 short missions with a case, a decision and feedback, about 10 minutes each:

- [16.1 Cancel order 4711 if it hasn’t shipped](https://llm.yoga/en/einsatz-16-1.md)
- [16.2 Posting invoices: agent or workflow?](https://llm.yoga/en/einsatz-16-2.md)
- [16.3 The rule is in the system prompt, yet it changes files outside projekt/](https://llm.yoga/en/einsatz-16-3.md)

For agents, this page is split into 5 parts so that each part can be fetched in full. Read the parts the question needs.

## Parts

### Part 1: https://llm.yoga/en/16-agenten-1.md

- **Getting started**: Picture a new colleague on her first day.
- **The agent loop**: According to Anthropic, agents are “typically just LLMs using tools based on environmental feedback in a loop” (Building effective agents).
- **Tools: how the model asks for help**: A tool has three parts: a name, a description and an input schema in JSON Schema format (a language for describing what a JSON document must look like).
- **stop_reason: why the response ended**: Every response from the Claude API carries a field stop_reason.

### Part 2: https://llm.yoga/en/16-agenten-2.md

- **Walkthrough: three rounds in the Claude API format**: In the abstract, the loop is hard to grasp.
- **tool_choice: forcing tool use, and why that barely works anymore**: With the tool_choice parameter, you control whether the model has to use tools.
- **Workflow or agent?**: Not everything that uses several model calls is an agent.

### Part 3: https://llm.yoga/en/16-agenten-3.md

- **Coordinator and subagents: hub and spoke**: When a task gets big, a single agent hits two limits.
- **Handoffs**: A handoff is the moment an agent passes on responsibility: to another agent or to a human.
- **Hooks: enforcing rules instead of asking**: A sentence in the system prompt like “Always research before you summarize” is a request.

### Part 4: https://llm.yoga/en/16-agenten-4.md

- **When the loop ends: stopping criteria and anti-patterns**: A loop without a clean end is the most common mistake when you build one yourself.
- **Exercise: an agent loop in 50 lines**: Goal: you build the loop from this chapter yourself, with one tool, a round counter and the right ending, and see how a small model handles it.
- **Common misconceptions**: The model runs the tools itself.
- **Review questions**: 1. Your loop calls the Claude API and gets a response with one text block and two tool_use blocks.

### Part 5: https://llm.yoga/en/16-agenten-5.md

- **Go further**: Anthropic: Building effective agents (December 19, 2024), workflows versus agents and the five patterns.
