AI Hints
Home›Generative AI Tutorial›Tools and Agents
Generative AI · Lesson 39 of 77

The Agent Loop

Think, act, observe, repeat.

⏱ 2 min read▶ Video at 1:30:18🎓 Free
Watch this lesson in the Generative AI courseWatch on YouTube ↗Full Generative AI course

A single tool call answers a single question. But many real tasks need many steps, and the next step depends on the last result. An agent is a model, that works in a loop, planning, acting, and checking, until the job is done. In this lesson, you will see how.

The Agent Loop
From the video: The Agent Loop
  • Many steps, not one
  • A model that works in a loop
  • Until the job is done

The agent loop

Here is the loop. The agent first thinks, what should I do next, to reach the goal? Then it acts, by calling a tool. Then it observes, reading the result. Then it decides, is the goal reached? If not, it thinks again, using what it just learned. Think, act, observe, repeat. The loop ends, when the agent decides the goal is complete, or it hits a safety limit.

Goal
  1. Thinkwhat should I do next?
  2. Actcall a tool
  3. Observeread the result
  4. Decidedone, or loop again

An agent at work: planning a trip

Imagine asking an agent, find me a cheap flight to Rome next month, and a hotel near the centre. It might search flights, and see three options. It compares prices, then picks the best. It searches hotels near the centre, and checks reviews. It sees that one is full, and tries another. Finally, it reports its findings, and asks for your approval, before booking. Each step depended on the last.

Search flightsthree options found
Compare pricespick the cheapest sensible one
Search hotelsnear the centre, with good reviews
Adaptone is full, so try another
Report and askapproval before booking

Workflow or agent?

Not every job needs an agent. A workflow follows steps that you wrote in advance, so it is predictable, cheap, and easy to test. An agent decides its own steps, so it is flexible, but harder to predict, slower, and more expensive. The wise rule is, use the simplest thing that works. If you know the steps, build a workflow. Use an agent only when the path truly cannot be known in advance.

Workflow

  • Fixed steps you design
  • Predictable and cheap
  • Easy to test
  • Best when steps are known

Agent

  • Model chooses the steps
  • Flexible, handles surprises
  • Harder to predict
  • Best when the path is unknown

Summary

Excellent. An agent works in a loop, think, act, observe, and decide, using tools along the way. Use a workflow when the steps are known, and an agent when they are not. Next, how agents plan, remember, and stay safe.

Key takeaways
  • Agent loop: think, act, observe, decide
  • Workflow: fixed steps. Agent: flexible steps
  • Use the simplest thing that works
Next up: Planning, Memory and Safety — making agents dependable