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:
- Think: What's the next sensible step toward this goal?
- Act: Call a tool (read a file, run code, hit an API)
- Check: Look at the result โ did it work? Any new information?
- 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.
QUICK QUIZ
Why do agents work in a loop instead of a single step?
SOURCES
- Anthropic: Building effective agents โ www.anthropic.com
- OpenAI docs: Agents โ platform.openai.com
- Wikipedia: Intelligent agent โ en.wikipedia.org