← Blog
Engineering

How the Master agent loop actually works

Tomáš Veselý·Jun 12, 2026·11 min read

Tool calls, planning, retries — a tour of the loop that writes your code.

Every request enters the same fixed loop: read the repository map, plan the change, apply edits, then validate. The loop is deliberately boring — the interesting work happens inside the tools, not in the control flow.

Reading comes first because blind writes are the single largest source of broken builds. The agent must open a file before it edits it, and edits carry an anchor of the original text so a stale plan fails loudly instead of silently overwriting good code.

Validation runs after every batch of writes. Import graphs are checked, missing components are created, and runtime errors from the preview are fed straight back into the loop with a hard cap of three repair rounds per file so the agent can never spin forever.