Agents: the loop that does the work
An agent is a model that keeps going on its own: it picks a tool, looks at the result, decides what to do next, and repeats until the job is done. Every coding agent is one. Understanding the loop tells you when to trust it, when to stop it, and when you don't need an agent at all.
1. The idea
An agent is a model plus tools plus a loop (Module 06 showed one tool call; an agent makes many in a row):
- Act: the model chooses a tool and its arguments (read a file, run the tests, search).
- Look: the result comes back into its context.
- Decide: given everything so far, is the goal met? If not, what's the next best action?
- Repeat, until it reaches the definition of done, or a limit stops it: a turn or cost budget, a permission it doesn't have, or a question only you can answer.
Anthropic's widely used guide Building effective agents makes a key distinction. In a workflow, your code decides the steps and the model fills them in. In an agent, the model decides the steps itself. Agents handle open-ended problems you can't script, at the price of more tokens, more time and less predictability. Its advice: start with the simplest thing that works, and add autonomy only when it pays off.
2. How it works
Watch an agent fix a failing test: eight turns, one wrong guess, a recovery, and evidence at the end.
Five workflow patterns worth knowing
Before reaching for a fully autonomous agent, check whether one of these simpler, more predictable patterns does the job (from Building effective agents):
3. Try it yourself: workflow or agent?
For each job, pick the simplest design that would work well.
4. Why it matters at work
- Always give a definition of done. "Done when the new tests and the existing suite pass, and you've shown me the diff." Without it the agent decides, and it usually stops too early or wanders on.
- Let it check itself. Agents get dramatically better when they can verify their own work: tests, a type checker, running the app, a screenshot. Make sure those commands are allowed and fast.
- Watch the first few turns. If the first plan or the first file it opens is wrong, interrupt and redirect immediately. Steering early is cheap; untangling later is expensive.
- Keep a leash: permissions and budgets. Routine actions can run freely; consequential ones (push, deploy, delete, send) should ask. In automation, cap turns and cost.
- Long tasks: state in files, not in chat. For work that spans many context windows, have the agent keep a progress file and a test list, and commit as it goes. Anthropic's guidance for long-horizon agents recommends exactly this.
- Evidence, not "done". Ask for the test output, the diff and anything it couldn't verify. An agent's claim of success is a hypothesis.
5. In your five tools
Every coding agent lets you stop it, steer it, and choose how much it may do without asking. Checked October 2026.
| Tool | Interrupt | How much it may do alone |
|---|---|---|
| Claude Code | Esc stops the current turn; type to redirect | Permission modes, cycled with Shift+Tab: Manual, acceptEdits, plan, auto (a second model reviews each action instead of you; the default from v2.1.283) and bypassPermissions for isolated containers only |
| Antigravity CLI | Esc halts the stream | /permissions: request-review, always-proceed or strict; Ctrl+K fast-approves pending actions |
| GitHub Copilot (VS Code) | The stop button in chat | The agent picker (Agent, Ask, Plan) plus per-tool confirmations and auto-approve settings |
| Cursor | The stop button in chat | Agent mode with run modes and a command allowlist; Shift+Tab switches to Plan mode |
| Codex CLI | Esc interrupts | /permissions: read-only, auto (works inside the workspace, asks for anything outside) or full access |
Building your own agent? Each vendor offers an agent SDK that runs this loop for you: the Claude Agent SDK, the OpenAI Agents SDK and Google's Agent Development Kit (ADK). Module 16 builds one.
6. Remember it
How this hook works: what “Act, look, decide: a loop on a leash” means
What the slogan means, phrase by phrase
- “Act”
- One tool call: read, search, edit, run. The only way an agent touches the world.
- “look”
- The result lands in the context. Good agents look carefully, at test output rather than their own assumptions.
- “decide”
- Done? If not, what next? This is where reasoning (Module 04) earns its cost.
- “a loop”
- The three moves repeat, often dozens of times, which is why agents are powerful, slower and pricier than a single answer.
- “on a leash”
- Freedom with limits: a definition of done (when to stop), budgets (how much it may spend), permissions (what it may touch) and you (who it must ask).
Why this picture fits: a dog on a long leash explores freely but can't run into the road. That's the balance to aim for: enough freedom to be useful, limits where mistakes are expensive.
The story → the concept
| In the hook | In the agent |
|---|---|
| Act | A tool call |
| Look | The tool result, added to the context |
| Decide | The model's next turn: another call, or a final answer |
| The length of the leash | Permission mode, allowlists, sandbox |
| Where the walk ends | The definition of done |
| Pulling it back | Esc, the stop button, a turn or cost budget |
Watch it on an example
"Fix the failing test_invoice_total. Done when the full test suite passes."
- Act: run the test. Look: expected 120.00, got 119.99. Decide: a rounding problem?
- Act: open
invoice.py. Look: totals use floats. Decide: switch toDecimal. - Act: edit and re-run that test. Look: it passes. Decide: not done yet; the definition says the full suite.
- Act: run the full suite. Look: all green. Decide: done, and report the diff and the output.
- The leash: if it had tried to
git push, the permission rules would have asked you first.
The trap it saves you from
Either extreme. No leash means an agent that can push to production or run up a bill; a leash too short (approving every file read) means you'd be faster doing it yourself. Choose the length per task.
It still works when…
You use subagents (Module 12), which are agents launched by an agent, each with its own loop and leash, and when you automate agents in CI (Module 13), where the leash is written into the job's permissions and budgets.
7. Common mistakes
8. Hands-on lab (30 minutes)
- Watch the loop. Give an agent a small bug with a clear definition of done. Count the act-look-decide turns and note each tool it used.
- Interrupt and redirect. On a second task, stop it after its first plan and change one requirement. How well did it adapt?
- Leash settings. In two tools, find the mode closest to "edits allowed, commands ask first". Write down what each one calls it.
- Pattern spotting. List three AI tasks in your own work and label each: single prompt, workflow pattern, or agent.
9. Self-check quiz
What makes something an agent rather than a workflow?
What most improves an agent's chance of finishing correctly?
Support emails must go to billing, technical or sales prompts. Which pattern?
When is a "skip all permission checks" mode acceptable?
10. Go deeper
| Resource | Time | Why |
|---|---|---|
| Building effective agents (Anthropic) | 25 min | Workflows vs agents and the five patterns: the most-cited practical guide. |
| AI Agents Course (Hugging Face) | Self-paced | Free, vendor-neutral course from concepts to building agents. |
| 5-Day AI Agents Intensive (Google and Kaggle) | 5 days | Hands-on agent building with Google's ADK. |
| Permission modes (Claude Code) | 15 min | A detailed look at how one tool sets the leash, including auto mode's reviewer. |