BACK TO INTERVIEW BANK
agent-architecturejunior

Walk through the agent loop step by step

Answer

  1. Assemble context. System prompt, tool definitions, conversation history, and the user's request.
  2. Call the model. It returns either a final answer or one or more tool calls.
  3. If it is a final answer, stop.
  4. Execute the requested tools. Usually with a permission check for anything consequential.
  5. Append results to the conversation as tool result messages.
  6. Go to step 2.

Two controls matter. A stopping condition, normally the model producing a response with no tool calls. And a step limit, a hard cap on iterations, because models can loop indefinitely retrying a failing call.

Everything else in a harness is refinement of this: how context gets trimmed when the window fills, how tools are chosen, how permissions work, how errors are surfaced back to the model.

Worth noting that tool results re-enter as context, so a tool returning 50,000 tokens of log output consumes the window as surely as a long conversation does.

Common wrong answer

Describing a planning phase as though it were a required step, with the agent producing a full plan up front and then executing it. Some systems do that, but it is a design choice, not part of the loop. Most coding agents interleave deciding and acting, which is what lets them respond to what they discover.

Also common is forgetting the step limit. Interviewers ask about it because the failure mode is real and expensive.

Likely follow-ups

  • Where does this loop most commonly break?
  • How do you stop an infinite loop?