Beginner level · Module 2: Understanding AI Agents and Their Components · Lesson 3 of 3
The Agent Loop and Stopping Conditions
Learners trace the observe–think–act loop through a log, and see why every agent needs limits on steps, time and cost.
In this lesson you will
- Trace an agent loop from a log
- Define stopping conditions and limits
Key concepts
observe–think–act loopReAct patternstep limitcost limittrace log
The lesson
An agent repeats a loop: it observes (the question and any tool results), decides what to do next, acts (calls a tool or answers), and observes again. The ReAct research pattern describes this interleaving of reasoning and actions.
Without limits, an agent can loop for a long time, call tools repeatedly and run up costs. Every agent needs a maximum number of steps, a time limit and a cost or token budget, and should stop and hand over when it reaches them.
Trace logs record each step: the request, the tool called, the result and the decision. They are essential for understanding failures and for audits.
Step by step
- Run the notebook agent on a question that needs two searches.
- Read the trace and label each observe, think and act step.
- Set the step limit to 1 and observe what happens.
- Write the stopping conditions for the project assistant.
Practice activity
Annotate an agent trace and define the project assistant's limits.
Expected result: A correctly labelled trace and sensible step, time and cost limits.
Check your understanding
-
Why does an agent need a step limit?
Show answer
To prevent endless loops, long delays and high costs.
-
What does a trace log record?
Show answer
Each step: requests, tool calls, results and decisions.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.