Agents, Tool Use & MCP·Question 3 of 90BasicAI-75

Walk me through the core agent loop. What are the components and stop conditions?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

An agent is a model, a set of tools, and context/memory, run in a loop with stop conditions. Per iteration: (1) call the model with the conversation so far plus tool definitions; (2) if the model emits tool calls, execute them in your runtime; (3) append results to the context; (4) check stop conditions; (5) repeat.

Full worked answer with diagram

An agent is a model, a set of tools, and context/memory, run in a loop with stop conditions. Per iteration: (1) call the model with the conversation so far plus tool definitions; (2) if the model emits tool calls, execute them in your runtime; (3) append results to the context; (4) check stop conditions; (5) repeat.

def run_agent(user_msg, tools, max_iters=15):
    messages = [{"role": "user", "content": user_msg}]
    for _ in range(max_iters):
        resp = llm(messages, tools=tools)
        messages.append(resp.message)
        if not resp.tool_calls:              # natural stop
            return resp.text
        for call in resp.tool_calls:
            result = execute(call.name, call.arguments)
            messages.append(tool_result(call.id, result))
    return escalate_to_human(messages)       # forced stop

Components worth naming explicitly:

  • Model - ideally tiered (strong model for planning, cheaper for routine steps).
  • Tools - the agent's only way to act on or perceive the environment; environment feedback via tool results is what makes it a loop rather than a monologue.
  • Context/memory - the message history is working memory; long tasks need compaction and external notes.
  • Stop conditions - natural: the model responds with text and no tool calls, or calls an explicit task_complete tool. Forced: max iterations, token/cost budget, wall-clock timeout, repeated-identical-call detection, or a human abort. Every production loop needs the forced ones; "it stops when it's done" is a red-flag answer.

Going further: follow-up territory

Also worth mentioning: verification before accepting "done" (run the tests, check the record exists) - models declare victory prematurely, and a checkable completion criterion is the cheapest reliability win in the whole design.

Worth sketching. Draw the forced-stop branch as prominently as the natural one, since that is the half most candidates leave out.

flowchart TD
    A["Context + tool defs"] --> B["Model call"]
    B --> C{"Tool calls emitted?"}
    C -->|"no"| D["Verify the claim,<br/>then return"]
    C -->|"yes"| E["Runtime executes tools"]
    E --> F["Append results to context"]
    F --> G{"Budget left?<br/>iterations, tokens, clock"}
    G -->|"yes"| B
    G -->|"no, or repeat detected"| H["Forced stop,<br/>escalate to human"]

What a good answer covers

  • An agent is a model, a set of tools, and context/memory, run in a loop with stop conditions
  • Per iteration: (1) call the model with the conversation so far plus tool definitions; (2) if the model…
  • Model - ideally tiered (strong model for planning, cheaper for routine steps)
  • Tools - the agent's only way to act on or perceive the environment; environment feedback via tool…
  • Context/memory - the message history is working memory; long tasks need compaction and external notes

Key terms: Model · Tools · Context/memory · Stop conditions

Interviewer follow-ups to expect

  1. Where would you put permission checks in that loop?

  2. How would you make this loop resumable after a process crash?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep