Skip to content
Simon Place
FR EN
Book a Meet call

Module 1 of 10, lesson 2 of 5

Going deeper

What an agent really is

The loop, in ten lines

Remove the libraries and an agent is this loop. The model never runs anything: it returns a response, and your code decides what happens next.

for (let step = 0; step < maxSteps; step += 1) {
  const response = await model.create({ messages, tools });
  messages.push({ role: 'assistant', content: response.content });
  if (response.stop_reason === 'end_turn') return response;

  const results = await runTools(response.content);
  messages.push({ role: 'user', content: results });
}
return { status: 'max_steps' };

Each detail has a consequence. The whole conversation goes back on every call, so cost grows with each step: a twenty-step run pays for the first message twenty times, unless prompt caching reduces that. And stop_reason isn’t decoration. A response cut off by a token limit looks like an answer but isn’t one.

Four ways to stop

  • Success: the model ends its turn. That’s its claim, not proof, so an important result needs a check in code.
  • Budget: steps, tokens, money, wall-clock time. Set all four, because each one catches a different failure.
  • Blockage: the same call repeats, or nothing new comes back.
  • Handover: a human must decide. This one is a normal outcome, not an error.

Autonomy is a dial

Most useful systems don’t sit at the far end. Anthropic’s essay Building effective agents describes simpler patterns that keep the path in your hands: prompt chaining, routing, parallel work, orchestrator and workers, evaluator and optimizer. The practical order is to try one prompt, then a fixed chain, then a router, and only then a loop. Move up a level when a measurement shows the current one failing, not because a demo looked better.

Legal notice and privacy