37.4 Termination conditions and budgets

Overview and links for this section of the guide.

The Infinite Loop Problem

Agents get stuck. "I'll try method A. Failed. I'll try method A again. Failed."

You must implement a **Time-to-Live (TTL)** or **Max Steps** counter. `if step_count > 10: raise AgentgaveUpError()`

Budgets

Track tokens/dollars per run. `current_cost += run_cost`. If `current_cost > $1.00`, kill the process. This prevents a runaway agent from burning your API key overnight.

Where to go next