The Agent Loop
An agent does not answer in one shot. It thinks, uses a tool, looks at the result and thinks again. This lesson shows the loop step by step, how it stops, and what goes wrong when it does not.
New words
- Agent loop
- Code that repeats: ask the model, run its tool, send back the result.
- ReAct
- A pattern where the model reasons first, then acts, then reasons again.
- Tool call
- A request from the model to run one of your functions.
- Max steps
- A limit on how many times the loop may call the model.
- Stop condition
- A rule that ends the loop, such as a final answer.
- History
- The full list of messages sent to the model on every call.
What you will learn
- The problem: one answer is not enough
- The loop in simple steps
- ReAct: reason, then act
- When does the loop stop?
- Why does cost grow with every step?
- Try it: a weather agent, one step at a time
- What goes wrong, and how to handle it
- In a real system
- Interview tip
- Key takeaways
10 quiz questions at the end.
The full lesson, with interactive demos and the quiz, opens after you sign in with Google. It is free.