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.

  • The design makes a hidden tradeoff measurable before it reaches users.
  • A clear boundary reduces retries, unsafe actions, or unnecessary capacity.
  • The operating choice should be tested against the workload rather than assumed from a demo.

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.

  • The example names the input, decision, and expected boundary.
  • A deterministic or human checkpoint owns the part a model should not guess.
  • The result can be measured with quality, latency, safety, and cost metrics.

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

Current example

Primary reference

This source explains the method or risk boundary. It does not replace testing the actual model, data, provider, and workload conditions in production.

OpenAI Agents SDK documentation

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

Source discipline: examples on this page are illustrative; measure the real workload before making a release or capacity decision.

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.

  • Start with a narrow workflow and explicit failure boundary.
  • Instrument the path before optimizing it.
  • Review the design whenever model, tool, traffic, or policy changes.

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