Chapter 1 · Part 1

What makes it an agent

You've probably heard "AI agent" a hundred times. Behind the buzzword is one small, concrete idea — and by the end of this course you'll have built one in Python. The idea is a loop.

A normal chatbot does one thing: you send a message, it sends one back. Even tool use — where the model calls a function you wrote — is a single round trip: it asks for the tool, you run it, it writes its answer. Done.

An agent wraps that in a loop. It calls a tool, reads the result, decides what to do next, calls another tool, reads that, and keeps going on its own until the task is finished. The same request → tool → result cycle, run over and over, without you steering each step.

Plan → act → observe → repeat

That loop is the whole thing. One turn of it looks like:

📌The agent loop
  • Plan — the model decides what to do next (and which tool would help).
  • Act — it asks to call a tool; your code runs it.
  • Observe — the tool's result goes back to the model.
  • Repeat — until the model has what it needs and writes a final answer.

Ask a chatbot "what's in notes.txt and how many words is it?" and it can't help — it has no file. Give an agent a read_file tool and a count_words tool, and it will read the file (act), see the text (observe), count the words (act again), then answer — several steps, one request. That autonomy is the entire difference.

This builds on the last course

This is the sequel to Your First Claude API App, which ended with a single tool call. If you did that course you're ready. If not, you only need the two things it set up:

Set up (once)
pip install anthropic
export ANTHROPIC_API_KEY="sk-ant-..."   # from console.anthropic.com — never hard-code it

With the key in an environment variable, Anthropic() finds it automatically:

hello.py — confirm you're set up
from anthropic import Anthropic

client = Anthropic()

reply = client.messages.create(
  model="claude-opus-4-8",
  max_tokens=256,
  messages=[{"role": "user", "content": "In one sentence, what is an AI agent?"}],
)
print(reply.content[0].text)
⚠️This course spends real money

Unlike the free, local courses, this one calls Claude — and an agent loops, so it makes several calls per task. It's still cents, not dollars, but set a spend limit in the Anthropic Console (Billing → Limits) before you start, and we'll track cost in the last chapter.

If that printed a sentence, you're ready. Next: write the loop that turns this into an agent.