promptgarten 🌱
Concept●●○4 min Β· +40 XP

The Agent Loop: Think β†’ Act β†’ Check β†’ Repeat

The agent loop is the cycle an AI agent uses to work through a task step by step.

The four steps

An AI agent typically works in a loop:

  1. Think: What's the next sensible step toward this goal?
  2. Act: Call a tool (read a file, run code, hit an API)
  3. Check: Look at the result β€” did it work? Any new information?
  4. Repeat: Back to step 1, until the goal is reached or the loop is stopped

Why a loop instead of one step?

Because real tasks are rarely solved in one shot. A bug fix might need: read the file, understand the error, propose a change, run tests, check the result, adjust. Each round produces new information that shapes the next decision.

An example

Goal: "Fix the failing test." Round 1: the agent reads the error message. Round 2: it opens the affected file. Round 3: it changes a line. Round 4: it reruns the test. Round 5: test passes β€” done.

The danger: endless loops

Without limits, an agent can get stuck β€” retrying the same wrong fix forever, or racking up cost. That's why good agents need stop conditions: a maximum number of rounds, a budget cap, or a clear success condition.

EXAMPLE

Goal: 'Get all tests passing.' Loop: run tests β†’ read failures β†’ change code β†’ rerun tests β†’ repeat until green or limit reached.

🎬 AS A SHORT VIDEO

The Agent Loop: Think β†’ Act β†’ Check β†’ Repeat

QUICK QUIZ

Why do agents work in a loop instead of a single step?

Share:𝕏inπŸ’¬

SOURCES

RELATED TOPICS

What Is an AI Agent? (vs. a Chatbot) ●○○Loops for Agents: Letting AI Iterate Autonomously ●●●Context Window ●○○