Skip to main content

Pattern · Agents

Agent loop

A model that repeatedly chooses a tool, sees the result, and decides the next step until the task is done.

Say it in the interview

If the steps are known, I would build a workflow; if not, an agent loop: the model picks a tool, my code validates and runs it, the result goes back, with a step cap and a budget, and a hand-off to a person when either is hit.

When to use it

  • The steps are not known in advance
  • The task needs information gathered along the way

How it works

  1. Model: task + history + tools → Wants a tool?
  2. Wants a tool? → yes → Your code validates and runs it
  3. Your code validates and runs it → Model: task + history + tools
  4. Wants a tool? → no → Final answer
  5. Your code validates and runs it → step cap or budget hit → Stop, hand to a person

Trade-offs

  • Handles open-ended tasks
  • Less predictable, slower and costlier than a fixed workflow
  • Needs caps, logs and evals

Pitfalls interviewers probe

  • Using an agent where a fixed workflow would do
  • No step cap or budget

Practise it on these questions

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.