Asked about Budgets, loops and giving up well

How do you stop an agent running forever?

An answer that works

Three independent budgets: turns, wall-clock time and cost. Any one being exceeded stops the run. Turns alone are not enough because a single turn can be slow or expensive.

Then they push further

Why is a turn limit alone not enough?

One turn can call a slow tool or produce a huge output, so a run can blow its time or cost budget in very few turns. Each budget protects against a different failure.

What does the user see when a budget trips?

A structured partial result: what was done, what was not, and why it stopped, with a way to continue if that makes sense. A silent failure or a generic error throws away the work already done.

How would you choose the limits?

From data. Run the eval tasks, look at turns, time and cost for the runs that succeeded, and set limits a little above the high end of that range. Revisit them when tools or models change.

What gets marked up

Marked up for independent budgets, for returning partial results instead of throwing, and for deriving limits from measured runs rather than picking round numbers.

Reading an answer is not being able to give one. The section that teaches this is Budgets, loops and giving up well, 3 hours of The agent loop.

Learn this properly