Your First Agent
An agent is just the model in a loop: decide the next step, do it with a tool, look at the result, repeat — until the goal is met.
You ask your assistant: “Find the cheapest flight to Tokyo next month and put it on my calendar.” That isn’t one action — it’s several, and each depends on the last: search flights → compare them → pick one → add a calendar event for that flight. A single request→tool→answer round-trip (L17) can’t do this, because you can’t know which event to add before you’ve seen the search results. What you need is a loop. That loop is what turns a model into an agent.
An agent is the model in a loop
A single tool call is one round-trip. An agent wraps that in a loop. Each pass through the loop has three beats: plan (the model looks at the goal and everything that’s happened so far, and decides the next action), act (it requests a tool call; your code runs it — exactly like L17), and observe (the result is fed back into the conversation). Then it loops: plan the next step using that new information, act, observe — until the goal is met. One model call is a single step; the loop is what strings many steps into completing a real task.
Why a loop, not one big plan
Couldn’t the model just plan all the steps up front and run them? No — because it can’t know step 3 before seeing step 2’s result. The cheapest flight, whether a search returns anything, whether a calendar slot is free — those are facts about the world the model only learns by acting and looking. Feeding each observation back is what lets the next decision be grounded in what actually happened, so the agent adapts — a flight sold out, a search came back empty — instead of blindly following a script that reality already broke.
The Tokyo task, looping: • Plan: “I should search flights.” Act: search_flights(dest=Tokyo, month=next). Observe: 12 options. • Plan: “Pick the cheapest.” Act: reason over the 12 → $640 on the 14th. Observe: choice recorded. • Plan: “Add it to the calendar.” Act: add_event(“Flight to Tokyo”, Mar 14). Observe: success. • Goal met → stop and report. Step 3’s event depended on step 2’s choice — impossible as one call.
Knowing when to stop
A loop needs a way out, or it runs forever or in circles. So every agent carries a termination condition: stop when the goal is achieved, or when it hits a budget (a max number of steps). The goal also has to stay in view each iteration, so the model doesn’t wander. And the honest trade-off: the more freedom you give an agent to choose its own steps, the more ways it can go wrong — pick the wrong tool, loop without progress, or let a small early error compound. Building the loop is the easy part; keeping it reliable is the next lesson.
An agent works like driving with live navigation, not a memorized route. The GPS doesn’t compute every turn blindly at the start; at each junction it looks at where you actually are (observe), decides the next turn (plan), tells you to take it (act), and then looks again — rerouting the moment reality differs from the plan (a closed road, a missed exit). It stops when you arrive. That look-decide-move-look-again loop, adapting to what it sees, is exactly an agent.
A research agent answering “What’s the capital of the country that won the most recent Rugby World Cup?”: 1. Plan: “First find which country won.” Act: web_search(“most recent Rugby World Cup winner”). Observe: “Country X.” 2. Plan: “Now find Country X’s capital.” Act: web_search(“capital of Country X”). Observe: “City Y.” 3. Plan: “I have both facts; I can answer.” No tool needed. Observe: goal met. 4. Stop → “The capital is City Y.” Notice the second search was only possible after observing the first result — the loop carried that fact forward. A single call could never have chained the two lookups.
This is the reading. The interactive version — active-recall quiz, a hands-on experiment you run in your own AI, and an earned mastery check — is free in the app.
Start this lesson free →