Learn AI compute, then follow the market
← Back to Compute College

Compute College

Agent loops, stopping conditions, and budgets

Control repeated model and tool steps with explicit limits, progress checks, and cost budgets.

Plain-English definition

An agent loop is the repeat cycle in which a model observes the current state, chooses a step, uses a tool, and checks what happened next. In production, the loop needs limits on steps, time, tokens, tool calls, and cost, plus a clear way to stop when it is stuck.

Memory trick: A loop without a budget is an open-ended bill.

Why it matters

A loop that works on a demo can repeat indefinitely when a tool fails, context grows, or the model misunderstands the goal. Budgets protect users, provider capacity, and system reliability while making failure recoverable.

Simple example

A research agent may run for at most eight model steps, three searches per source, 60 seconds, and a defined token budget. It stops early when the evidence checklist is complete and escalates when the same search or error repeats.

Example figures are illustrative calculations, not current quoted market prices.

Current example

Source material

OpenAI Agents SDK documentation

Official documentation and guidance for orchestrating model-driven tools with application controls.

Common mistake

A maximum step count is only one limit. A short loop can still consume large contexts or expensive tools, and a long loop can repeat the same failed action.

Practical takeaway

What you can do with this

Set step, time, token, tool, and cost limits. Add progress detection for repeated states and a user-visible fallback when the loop stops.

Decision check: what happens to the user, state, and partial work when the agent reaches its budget?

Compute College learning path

AI Engineering

Step 31 of 48: Agent loops, stopping conditions, and budgets