InterviewKata
AI engineering · Module 07 of 21 · Level 2: Working with AI

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

A good contractor fixing a leak doesn't follow a script. They look, form a guess, open a panel, check, change their mind, test, and stop when the water stays off. You don't tell them each step, but you do agree what "fixed" means, a budget, and that they call you before knocking down a wall.

An agent is a model plus tools plus a loop (Module 06 showed one tool call; an agent makes many in a row):

  1. Act: the model chooses a tool and its arguments (read a file, run the tests, search).
  2. Look: the result comes back into its context.
  3. Decide: given everything so far, is the goal met? If not, what's the next best action?
  4. 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

The agent loop. The leash (definition of done, budgets, permissions, and you) is what makes it safe to let go.

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.

ToolInterruptHow much it may do alone
Claude CodeEsc stops the current turn; type to redirectPermission 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 CLIEsc halts the stream/permissions: request-review, always-proceed or strict; Ctrl+K fast-approves pending actions
GitHub Copilot (VS Code)The stop button in chatThe agent picker (Agent, Ask, Plan) plus per-tool confirmations and auto-approve settings
CursorThe stop button in chatAgent mode with run modes and a command allowlist; Shift+Tab switches to Plan mode
Codex CLIEsc 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

Memory hook: "Act, look, decide: a loop on a leash"An agent repeats three moves until the goal is met. The leash (a definition of done, budgets, permissions and you) decides how far it may run.
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 hookIn the agent
ActA tool call
LookThe tool result, added to the context
DecideThe model's next turn: another call, or a final answer
The length of the leashPermission mode, allowlists, sandbox
Where the walk endsThe definition of done
Pulling it backEsc, 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."

  1. Act: run the test. Look: expected 120.00, got 119.99. Decide: a rounding problem?
  2. Act: open invoice.py. Look: totals use floats. Decide: switch to Decimal.
  3. Act: edit and re-run that test. Look: it passes. Decide: not done yet; the definition says the full suite.
  4. Act: run the full suite. Look: all green. Decide: done, and report the diff and the output.
  5. 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

Full autonomy on your own machineModes that skip all permission checks belong in a disposable container or VM, never on a laptop holding your SSH keys and production credentials.
No definition of doneThe agent stops at "the test I touched passes" or keeps polishing forever. Say exactly what finished looks like.
Using an agent for a fixed processIf the steps never change (extract fields, classify, summarise), a scripted workflow is cheaper, faster and easier to test.
Not interrupting a bad startA wrong first plan compounds. Stop it, correct it, or start fresh with a better brief.
Taking "done" on trustAsk for the evidence: test output, the diff, screenshots, and what it couldn't check.

8. Hands-on lab (30 minutes)

  1. 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.
  2. Interrupt and redirect. On a second task, stop it after its first plan and change one requirement. How well did it adapt?
  3. Leash settings. In two tools, find the mode closest to "edits allowed, commands ask first". Write down what each one calls it.
  4. 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?

In a workflow your code fixes the steps; in an agent the model chooses them as it goes.

What most improves an agent's chance of finishing correctly?

A checkable finish line (tests, criteria) lets it verify itself and stop at the right moment.

Support emails must go to billing, technical or sales prompts. Which pattern?

Classify, then send to a specialised prompt: predictable, cheap and easy to test.

When is a "skip all permission checks" mode acceptable?

Without checks, a prompt injection or a mistake can reach anything the machine can. Contain it.

10. Go deeper

ResourceTimeWhy
Building effective agents (Anthropic)25 minWorkflows vs agents and the five patterns: the most-cited practical guide.
AI Agents Course (Hugging Face)Self-pacedFree, vendor-neutral course from concepts to building agents.
5-Day AI Agents Intensive (Google and Kaggle)5 daysHands-on agent building with Google's ADK.
Permission modes (Claude Code)15 minA detailed look at how one tool sets the leash, including auto mode's reviewer.