Stop Sign
🛑 Some goals never finish. A bot that keeps trying forever burns battery (and real money, with real models). Every agent needs a step limit. break jumps out of a loop early, and return inside a loop leaves the whole function.
for n in range(100):
if n == 3:
break
print(n)0 1 2
pip.next_step(goal, done) tells your agent what to do next, or "DONE" when the goal is finished. For a goal Pip can't finish, it just says "thinking..." forever.
Instructions
- Make
run_agent(goal, limit)with an empty listdoneinside. - Loop at most
limittimes. Each time, askpip.next_step(goal, done): if it says"DONE", returnFinished in 3 steps.(with the real count). - Otherwise add the step to
done. If the loop runs out, returnStopped after 5 steps.(with the limit). - Print
run_agent("count to 3", 5)and thenrun_agent("count to infinity", 5).
💡 Hint
for i in range(limit): step = pip.next_step(goal, done). If step == "DONE": return "Finished in " + str(len(done)) + " steps." After the loop, return the Stopped message.