Lesson 2 - For complex queries, how does the agent know to loop the model and not just exit

Hello,
I have some confusion in lesson 2.
For the query:

query = "Who won the super bowl in 2024? In what state is the winning team headquarters located? \
What is the GDP of that state? Answer each question."  

The model first finds who won. Then goes back and checks which state the winning team is located in. Then again run the loop to the last part of the question.

How does it know it has to run the loop again? How is the flow built for it?

Thank you!