“Hi, I got charged twice for order #4471. Can you sort it out?”
A field guide in five minutes
An AI agent is automation you already know how to write.
Read the transcript
Here’s a little secret about AI agents… they’re loops. Plain old automation reads a message, walks down an if-else tree you wrote by hand, and calls one of your functions. Then, around it goes again. But this ticket matches no rule. So it falls through to “else”… and waits for a human. So: keep the loop. Keep your functions. Snip out the tree, and paste in a model. The model reads everything so far, and suggests the next function. Your program checks it, runs it, and adds the result to the pile. Look. Choose. Do. Round and round, until the model says “done”, or your program says “enough.” That’s an agent: a loop, with a model where your if-else used to be.
Traditional automation is a loop that reads some input, walks an if / elif / else tree you wrote, and calls one of your functions. An agent is the same loop and the same functions. The tree is replaced by a model inference that picks the next function, and each function's result goes back in so the model can choose again.
- Look Read the input, plus every result so far
-
Choose
if / elif / elsemodel.infer() - Do Your program checks the choice, then runs your function
Repeat until done. An agent adds the result to its context before it goes round again.
- Rules you hand-wrote
- Model inference
- Your functions (tools)
The one-line swap
Take a support inbox. The automation reads each ticket, and a decision tree picks which function to call. Here is one real-looking ticket going through both versions.
1 · Input
text = ticket.body
context = [ticket.body]
2 · Decide
if "refund" in textnoelif "password" in textnoelsetaken
model.infer(context, tools)
Reads the whole message and everything in context, then returns the next function to call and its arguments. It returns data. It runs nothing.
3 · Do the same functions in both versions
lookup_order(id)1issue_refund(charge, amt)2reset_password(email)send_reply(text)3escalate_to_human()✓
Outer loop: next ticket. Nothing from this run is fed back.
Inner loop: each result goes into context, and the model is asked again until it says it's done.
Outcome: neither keyword matched, so it falls to else. A person has to read it and do the refund by hand.
Outcome: the model looks up the order, sees the duplicate charge, refunds $38, and tells Priya. That's four inference calls (three tool picks and one “done”).
Same program, side by side
- The functions don't change.
issue_refundis the same code that talks to the same payments API. In agent terms it's now called a tool, and it gets a short description so the model knows it exists. - The whole tree becomes one line. Instead of matching keywords,
model.inferreads the text and returns the name of a function plus its arguments. - The loop gains memory.
context.append(result)is the only truly new idea. Because the model sees what each step returned, it can take several steps on one ticket: look up the order, then refund, then reply.
What changed, and what didn't
Go through an automation piece by piece and most of it carries over unchanged. The differences all come from one change in the decision step.
| Part | Traditional automation | Agent |
|---|---|---|
| Trigger & loop | Cron job, queue poll, while True | Same loop, usually plus an inner loop per task |
| Reading input | Parse fields, regex, keyword match | Model reads the raw text |
| Deciding the next step | if / elif / else you wrote ahead of time | One inference call picks a function + arguments from a list |
| Actions | Functions | The same functions, now called tools (plus a name, description, and argument schema) |
| State between steps | Local variables | The context: a list of every message and result, re-sent on every call |
| Stopping | You reach the end of the tree | The model says “done”, or your step limit / budget / timeout cuts it off |
| Safety | Validation, permissions, limits | The same checks, and more important now, because the chooser can be wrong in new ways |
| How it fails | Input nobody planned for falls to else (or matches the wrong branch) | The model picks a bad move; your check blocks it or the result tells it so |
Watch one run, turn by turn
Read the transcript
Let’s watch a coding agent fix a bug. The task: “test_total is failing. Fix it.” Turn one: the model asks to run the tests. It can’t run anything itself; your program does, and adds the result to the context. Failed. Expected 108, got 100. Turn two: read cart.py. Turn three: an edit. Tax was never applied! Your program checks the path, then makes the change. Turn four: run the tests again. Nobody wrote “after an edit, re-run the tests.” The model chose that, from what was in its context. Turn five: “Done.” Five model calls. Four function runs. One loop. And its memory? Just that growing list.
Coding agents work the same way. Here a CI script would run the tests and email you “FAILED”. The agent runs the same run_tests function and then keeps going. Step through it and watch the context grow.
Task: “test_total is failing. Fix it.” Tools: run_tests() read_file(path) edit_file(path, old, new)
All 5 turns shown · context: 12 messages
- system You are a coding agent. Tools: run_tests, read_file, edit_file.
- user test_total is failing. Fix it.
- model
run_tests() - result FAILED test_total: expected 108.0, got 100.0
- model
read_file("cart.py") - result
TAX = 0.08 … def total(items): return subtotal(items) - model
edit_file("cart.py", "return subtotal(items)", "return round(subtotal(items) * (1 + TAX), 2)") - result ok: 1 line changed
- model
run_tests() - result 3 passed
- model done: “total() now applies TAX; all tests pass.”
- program
move.doneis true →break. Loop ends.
- Before the loop: the context holds only the instructions and the task. The model has no memory beyond this list.
- Turn 1. The model chooses
run_tests. It can't run anything itself; your program runs the function and appends the output. - Turn 2. The model sees the failure message in context, so the sensible next move is to read the file. Here, a hand-written tree would need a branch for every possible error message.
- Turn 3. It proposes an edit. This is where
check(move)earns its keep: only allowed paths, only in the repo, maybe a human approval. - Turn 4. It runs the tests again. Nobody wrote “after an edit, re-run tests”; the model chose it from what was in context.
- Turn 5. The model returns “done” instead of a tool call. That's the same
breakany loop has. Five inference calls, four function runs, one loop.
Loop Lab: be the chooser
Three short rounds, about four minutes. In each one you sit in the Choose step.
- Round 1: be the if/else. Follow a rule tree literally and see where it breaks.
- Round 2: be the model. Pick the next function each turn. The program checks it, runs it, and feeds you the result.
- Round 3: the whole inbox. Put the rules and the agent side by side on the same tickets.
A spectrum, not a leap
Read the transcript
“Agent” isn’t a new kind of program. It’s the far end of a dial you already use. All the way left: a script. Same steps, every time. Nobody chooses. One click: rules. An if-else tree you wrote picks the path. Perfect for clean forms. Another click: a router. A model reads the messy message once, picks a path, and fixed code takes it from there. All the way right: an agent. The model picks every step, based on what it has found so far. Each click hands a little more choosing to a model. More flexible. Less predictable. More expensive. So here’s the rule of thumb: use the leftmost setting that gets the job done.
“Agent” isn't a new kind of program. It's the far end of a range you probably already use. Each step to the right hands a bit more of the Choose step to a model: you gain flexibility and give up some predictability. Use the leftmost option that does the job.
-
Script
fetch(); transform(); save()Who chooses: nobody. Same steps every time.
Backups, ETL, report generation.
-
Rules automation
if x: a()elif y: b()else: c()Who chooses: the tree you wrote.
Clean fields, stable paths: forms, webhooks, Zapier-style flows.
-
Router (one inference)
route = model.infer(text, ["a","b","c"])ROUTES[route]()Who chooses: the model, once. Then fixed code runs.
Messy text, but a known set of paths: triage, classification.
-
Agent (inference in a loop)
while not done: move = model.infer(context) context += run(move)Who chooses: the model, every turn, based on results so far.
Open-ended tasks where the steps depend on what you find: debugging, research, multi-issue support.
What people get wrong
Read the transcript
Four things people get wrong about agents. One: “the model runs code.” It doesn’t. It writes a little note: call this function, with these arguments. Your program decides whether to run it… and runs it. Two: “the agent remembers.” Every call starts from zero. The memory is the list your loop re-sends each turn… which is why long runs get slower, and pricier. Three: “the agent decides when to stop.” It can suggest stopping. Your loop enforces the step limit, the budget, the timeout. Four: “agents replace automation.” They reuse it. Your functions become the tools. Your checks stay checks. Only the if-else tree goes away. The model suggests. Your program decides.
- “The model runs code.”
- It returns text, usually a small JSON object naming a function and its arguments. Your program decides whether to run it, and runs it.
- “The agent remembers.”
- Each inference call is stateless. The “memory” is the context list your loop re-sends every turn, which is why long runs get slower and pricier.
- “The agent decides when to stop.”
- It can propose stopping. Your loop enforces the step limit, budget, and timeout, the same way any automation has a kill switch.
- “Agents replace automation.”
- They reuse it. Your existing functions become the tools, and your existing validation becomes the checks. The tree is the only part that goes away.
An agent is a
whileloop around one inference call where your if/else tree used to be. The model picks the next function; your program checks it, runs it, feeds back the result, and decides when to stop.
The real API version (about 20 lines)
With a real model API, model.infer is one HTTP call. The response either asks for a tool (stop_reason == "tool_use") or finishes ("end_turn"). Here it is with the Anthropic Python SDK:
And a “tool” is just your function's name plus a description the model reads:
Under the hood: every byte of a real agent run →
Glossary
- Inference
- One call to a model: context in, text out. In an agent, the text names the next move.
- Tool
- A function your program exposes to the model by name, description, and argument schema. Your program runs it.
- Context
- The running list of instructions, messages, tool calls, and results that is sent with every inference.
- Harness
- The loop code around the model: calls it, checks moves, runs tools, appends results, enforces limits.
- Agent
- A harness plus a model that picks tools in a loop until the task is done or a limit is hit.
Primary sources
- Anthropic: Building effective agents (workflows vs agents; agents as models using tools on feedback in a loop)
- Anthropic: How tool use works (the tool_use / tool_result round trip)
- Yao et al.: ReAct, Synergizing Reasoning and Acting (reason → act → observe loop)
- Russell & Norvig: Intelligent agents (AIMA ch. 2) (the percept → action loop, decades before LLMs)