What Is an Agent?
The loop behind everything.
Think about how you solve a task that you've never seen. You have a look, you try something, you see what happens, and then you decide what to do next. You don't plan every step up front. You loop. An agent does exactly the same.

- You look
- You try something
- You see what happens, then loop
The agent loop
Here it is. Think, act, observe. The model thinks about what to do. It acts, by calling a tool. It observes the result. And that result goes back into the next thought. This repeats until the goal is met, or until it gives up. Every agent product that you've ever seen, however impressive, runs on this loop.
The loop in twelve lines
Let's write it. This has no AI in it at all, just the shape. A list of notes holds everything so far. In a loop, we think, and we check whether we're done. If not, we act, and we add the result to our notes. And there's a maximum number of steps, so it can't run forever. Run it. There's the loop, working through its steps. Keep this shape in mind. Everything else in this course plugs into it.
def agent(goal, think, act, max_steps=5):
notes = [goal]
for step in range(1, max_steps + 1):
decision = think(notes)
print(f"Step {step}: {decision}")
if decision == "done":
return notes
notes.append(act(decision))
return notes
plan = iter(["look up order", "check policy", "done"])
agent("Help with order A17", lambda notes: next(plan), lambda d: f"result of {d}")Step 1: look up order Step 2: check policy Step 3: done
The four parts of any agent
Every agent has four parts. A model, which does the thinking. Tools, which let it act. Memory, which holds what it knows. And instructions, which tell it its goal and rules. Change any one of those, and you've got a different agent. That's also the outline of this course.
Summary
Think, act, observe, repeat. That loop is an agent. But how much freedom should you give it? That turns out to be the most important design choice that you'll make.
Key takeaways- Think, act, observe
- Model, tools, memory, instructions
- A step limit keeps it safe