LESSON 7.1 · Intuition · 90 min

The minimal agent loop

A minimal agent loop receives a goal and current state; the model decides whether to answer, call a tool, or stop; the program validates tool name, arguments, and permissions befor

DIRECT ANSWER · VERIFIED SOURCES ·

What steps make up the smallest controllable AI-agent loop?

A minimal agent loop receives a goal and current state; the model decides whether to answer, call a tool, or stop; the program validates tool name, arguments, and permissions before execution; the result is written back as an observation; and the model chooses the next step until success, failure, a budget limit, or a need for human judgment. The essential feature is verifiable environmental feedback at every step, not the number of iterations.

Lecture alignment

Lecture alignment: label one task frame by frame as goal/state → model decision → validated action → tool result/observation → updated state → stop, distinguishing model choices from constraints enforced by code.

Key takeaways

  • The model handles uncertain decisions; code enforces permissions, schemas, timeouts, retries, budgets, and termination.
  • A predefined code path is a workflow; a system becomes more agent-like when the model dynamically chooses steps and tools.
  • A tool result is environmental evidence, not model memory, and must be recorded, parsed, and used in the next decision.

Boundary and caveat

An agent is not “an LLM in an infinite loop.” Open-ended tasks compound errors, cost, and risk; production systems need sandboxes, idempotent tools, audit logs, step limits, and human approval for high-impact actions such as payments, publishing, or deletion. Prefer a fixed workflow when it is sufficient.

Primary sources

Learning objectives

  1. Explain what problem “The minimal agent loop” solves without hiding behind terminology.
  2. Trace the variables and causal links across observe–reason–act, environments, and termination.
  3. Complete “Write a tool loop without a framework” and judge the result with evidence rather than intuition.

Core concepts

observe–reason–act

observe–reason–act is part of the lesson’s causal model. State its inputs, outputs, invariants, and failure mode; then verify it with a hand-check or a minimal experiment before moving to an optimized implementation.

environments

environments is part of the lesson’s causal model. State its inputs, outputs, invariants, and failure mode; then verify it with a hand-check or a minimal experiment.

and termination

and termination is part of the lesson’s causal model. State its inputs, outputs, invariants, and failure mode; then verify it with a hand-check or a minimal experiment.

Build and verify

Write a tool loop without a framework

  • Predict: write the expected output, trend, or failure before running code.
  • Build: implement only the minimum components needed to answer the question.
  • Verify: compare with a baseline or trusted implementation; save seeds, parameters, and raw outputs.
  • Transfer: change one shape, dataset, scale, or workload condition and explain whether the conclusion still holds.

Open the complete interactive lesson